-
Notifications
You must be signed in to change notification settings - Fork 6
Getting Started
<dependency>
<groupId>com.savoirtech.hecate</groupId>
<artifactId>hecate-core</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.savoirtech.hecate</groupId>
<artifactId>hecate-pojo</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.savoirtech.hecate</groupId>
<artifactId>hecate-annotation</artifactId>
<version>2.0.10</version>
</dependency>
<dependency>
<groupId>com.savoirtech.hecate</groupId>
<artifactId>hecate-test</artifactId>
<version>2.0.10</version>
<scope>test</scope>
</dependency>
Setting Up the Factory
Just pass in your Cassandra session to the DefaultPojoDaoFactory for a default configuration or pass in a PojoMappingVerifier with the session to give you more options.
factory = new DefaultPojoDaoFactory(session, new CreateSchemaVerifier(session));
The CreateSchemaVerifier above will auto generate your schema if it does not already exist using your pojos and annotations if needed to generate your schema.
Creating your DAO
Simply ask the factory for your pojo dao using the following:
PojoDao<String, MyPojo> myPojoDao = factory.createPojoDao(MyPojo.class);
You now have instant CRUD operations available for the given class: save, findById, findByIds and delete
Pojo annotations make it dead simple to store data using your pojos. The default values allow you to quite often only annotate the Primary Key. While this simplicity is nice, annotations do offer overrides such as Column names, Table names, and Composite Keys with Partition Keys and Clustering Keys.
Simple Pojo using defaults:
Public class User {
@Id
String id;
String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
}
Simple Composite Key (2 partition keys):
Public class UserCompositeKey {
@PartitionKey(order = 0)
String userId;
@PartitionKey(order = 1)
String lastName;
...
}
Public class User {
@Id
UserCompositeKey key;
String data;
...
}
Composite Key with Clustering Keys (2 partition keys, 2 Clustering Keys):
Public class UserCompositeKey {
@PartitionKey(order = 0)
String userId;
@PartitionKey(order = 1)
String lastName;
@ClusteringColumn(order = 2)
String age;
@ClusteringColumn(order = 3)
String eyeColor;
...
}
Public class User {
@Id
UserCompositeKey key;
String data
...
}