Skip to content

Getting Started

Steve Forsyth edited this page Mar 24, 2016 · 6 revisions

Getting Started

Maven

<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 and Using the DAO Factory

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

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

    ...
}
Clone this wiki locally