Class CassandraTemplate

java.lang.Object
org.springframework.data.cassandra.core.CassandraTemplate
All Implemented Interfaces:
Aware, ApplicationContextAware, ApplicationEventPublisherAware, CassandraOperations, ExecutableDeleteOperation, ExecutableInsertOperation, ExecutableSelectOperation, ExecutableUpdateOperation, FluentCassandraOperations
Direct Known Subclasses:
CassandraAdminTemplate

public class CassandraTemplate extends Object implements CassandraOperations, ApplicationEventPublisherAware, ApplicationContextAware
Primary implementation of CassandraOperations. It simplifies the use of Cassandra usage and helps to avoid common errors. It executes core Cassandra workflow. This class executes CQL queries or updates, initiating iteration over ResultSet and catching Cassandra exceptions and translating them to the generic, more informative exception hierarchy defined in the org.springframework.dao package.

Can be used within a service implementation via direct instantiation with a CqlSession reference, or get prepared in an application context and given to services as bean reference.

This class supports the use of prepared statements when enabling setUsePreparedStatements(boolean). All statements created by methods of this class (such as select(Query, Class) or update(Query, org.springframework.data.cassandra.core.query.Update, Class) will be executed as prepared statements. Also, statements accepted by methods (such as select(String, Class) or and others) will be prepared prior to execution. Note that Statement objects passed to methods must be SimpleStatement so that these can be prepared.

Note: The CqlSession should always be configured as a bean in the application context, in the first case given to the service directly, in the second case to the prepared template.

Since:
2.0
Author:
Mark Paluch, John Blum, Lukasz Antoniak, Sam Lightfoot
See Also: