Skip to content

Latest commit

 

History

History
 
 

sfm-datastax

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Maven Central JavaDoc

Datastax integration

What about the Datastax Mapper

  • SFM is at about 20% faster
  • More flexible
  • No configuration

Add dependency

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

Mapper

    final DatastaxMapper<DbObject> mapper =
        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 = mapper.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());