Getting Started Cassandra

Maven Central JavaDoc

Setting up the environment

Add the Dependency to your build.

for Maven:

Java 8, 9, 10 , 11 no module-info

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

Java 6, 7

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

Java 9, 10 , 11 with module-info

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

Works with datastax 2.1.x to 3.0.x, from 7.0.0 you will need explicitly include the datastax dependency in your pom.

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());