Q:

How can I examine the query string generated by Spring Data Cassandra Mapper

If I annotate a class with annotations from com.datastax.driver.mapping.annotations, I can write a test along the lines of:
MappingManager manager = new MappingManager(session);
Mapper<MyAnnotatedClass> mapper = manager.mapper(MyAnnotatedClass.class);

MyAnnotatedClass entity = ...;

RegularStatement saveQuery = (RegularStatement) mapper.saveQuery(entity);

assertEquals("...", saveQuery.getQueryString());

However I have entity classes annotated with org.springframework.data.cassandra.mapping annotations. I've been unable to find an Spring equivalent to Mapper's saveQuery(), getQuery() and deleteQuery().
How can I write (ideally lightweight at runtime) tests regarding the CQL generated from Spring Data Cassandra-annotated entity classes?

A:

With Spring Data for Apache Cassandra 1.5, you can write the following code to create Statements:
CassandraTemplate template = …

Person person = …

CqlIdentifier tableName = template.getTableName(Person.class);

Insert insert = CassandraTemplate.createInsertQuery(tableName.toCql(), person, 
                    new WriteOptions(), template.getConverter());

Delete delete = CassandraTemplate.createDeleteQuery(tableName.toCql(), person,
                    new WriteOptions(), template.getConverter());

Update update = CassandraTemplate.createUpdateQuery(tableName.toCql(), person, 
                    new WriteOptions(), template.getConverter());

Note: Spring Data for Apache Cassandra 1.5 uses BATCH statements for inserts, that's going to change with the release 2.0.
CassandraTemplate and CassandraConverter are the key classes involved in query creation for version 1.5. In Spring Data 2.0, things are going to change a bit as 2.0 is going to ship with additional Query and Update types for partial entity updates. So query creation moves from CassandraTemplate.create…Query(…)to QueryUtils.create…Query(…).

