Menu

Home

Kevin Matthews

Artemis provides a lightweight framework leveraging DataStax's Cassandra driver's features to make writing an application that writes and reads data from Cassandra easy, while still allowing a user to customize at a granular level. Data is read from and written into any correctly annotated data model class you provide using DataStax's Mapping utility for ORM like functionality.

It also provides some hooks to make integration into a Jersey application easy. See the artemis-example project in the source code page for an example.

Artemis will read a simple configuration file and provide a Session, via a Data Access Object (DAO), to a Cassandra Cluster. Along with a few others things, the DAO can be used to read, insert and delete specific records or rows by using the partition or primary index keys, respectively, or conditionally delete and get records or rows via Clauses.

To give some idea, the following are examples of a few of the functions available for data retrieval:

getOne(String ... primaryKey)
getAll(String ... partitionKey)
getWhere(List<Clause> whereConditions)
get(T dataModel)

All DAO calls of this type return a Result object that contains both the mapped result (the data mapped to your model), and the raw result (the ResultSet). It will also contain any exception that may have occurred during the function call.

DAO calls to Cassandra are asynchronous. Blocking only occurs when you try to read from the Result object, thereby giving you control over when you block. It also allows for calls to Cassandra from the application to be executed in parallel.

Example of how Artemis may be used:

Model class:

@Table(keyspace = "artemis", name = "exampleservice")
public class ExampleData {
    @PartitionKey
    private String partitionKey;
    @ClusteringColumn
    private String clusterKey;
    private String data;
    ...
}

Read a record:

CassandraDAO exampleDAO = new CassandraDAO<ExampleData>();
ExampleData exampleData;

try {
    Result<ExampleData> mappedResult = exampleDAO.getOne(String ... primaryKey);
    exampleData = mappedResult.getMappedResult();
    // use exampleData

} catch (ResultAccessException e) {
    // handle error
}