Getting Started Cassandra

Maven Central JavaDoc

Setting up the environment

Add the Dependency to your build.

for Maven:

Java 8

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-datastax</artifactId>
    <version>3.12.1</version>
</dependency>

Java 6, 7

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-datastax</artifactId>
    <version>3.12.1</version>
    <classifier>jdk16</classifier>
</dependency>

Java 9

<dependency>
    <groupId>org.simpleflatmapper</groupId>
    <artifactId>sfm-datastax</artifactId>
    <version>3.12.1</version>
    <classifier>jdk9ea</classifier>
</dependency>

Works with datastax 2.1.x to 3.0.x

What about the Datastax Mapper

Mapper

final DatastaxMapper<DbObject> parameterGetterMap =
    DatastaxMapperFactory.newInstance().mapTo(DbObject.class);

...

    ResultSet rs =
        session.execute(
            "select id, name, email, creation_time, type_ordinal, type_name"
            + " from dbobjects");
    final Iterator<DbObject> iterator = parameterGetterMap.iterator(rs);


final DatastaxBinder<DbObject> datastaxBinder =
    DatastaxMapperFactory.newInstance().mapFrom(DbObject.class);

...
    PreparedStatement preparedStatement = session.prepare(
       "insert into " +
       "dbobjects(id, name, email, creation_time, type_ordinal, type_name) " +
       "values(?, ?, ?, ?, ?, ?)"
    );

    session.execute(datastaxBinder.mapTo(dbObjects, preparedStatement));

Crud

DatastaxCrud<DbObject, Long> crud =
    DatastaxMapperFactory
        .newInstance()
        .crud(DbObject.class, Long.class)
        .to(session, "dbobjects");

crud.save(session, object);
DbObject object = crud.read(session, object.getId());
crud.delete(session, object.getId());