public class AsyncCassandraTemplate extends Object implements AsyncCassandraOperations, ApplicationEventPublisherAware
AsyncCassandraOperations. It simplifies the use of asynchronous 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 Session reference, or get
prepared in an application context and given to services as bean reference.
Note: The Session 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.
AsyncCassandraOperations| Constructor and Description |
|---|
AsyncCassandraTemplate(AsyncCqlTemplate asyncCqlTemplate,
CassandraConverter converter)
Creates an instance of
AsyncCassandraTemplate initialized with the given AsyncCqlTemplate and
CassandraConverter. |
AsyncCassandraTemplate(com.datastax.driver.core.Session session)
Creates an instance of
AsyncCassandraTemplate initialized with the given Session and a default
MappingCassandraConverter. |
AsyncCassandraTemplate(com.datastax.driver.core.Session session,
CassandraConverter converter)
Creates an instance of
AsyncCassandraTemplate initialized with the given Session and
CassandraConverter. |
AsyncCassandraTemplate(SessionFactory sessionFactory,
CassandraConverter converter)
Creates an instance of
AsyncCassandraTemplate initialized with the given SessionFactory and
CassandraConverter. |
| Modifier and Type | Method and Description |
|---|---|
ListenableFuture<Long> |
count(Class<?> entityClass)
Returns the number of rows for the given entity class.
|
ListenableFuture<Long> |
count(Query query,
Class<?> entityClass)
Returns the number of rows for the given entity class applying
Query. |
ListenableFuture<WriteResult> |
delete(Object entity,
QueryOptions options)
Delete the given entity applying
QueryOptions and return the entity if the delete was applied. |
ListenableFuture<Boolean> |
delete(Query query,
Class<?> entityClass)
Remove entities (rows)/columns from the table by
Query. |
<T> ListenableFuture<T> |
delete(T entity)
Delete the given entity and return the entity if the delete was applied.
|
ListenableFuture<Boolean> |
deleteById(Object id,
Class<?> entityClass)
Remove the given object from the table by id.
|
ListenableFuture<Boolean> |
exists(Object id,
Class<?> entityClass)
Determine whether a row of
entityClass with the given id exists. |
ListenableFuture<Boolean> |
exists(Query query,
Class<?> entityClass)
Determine whether the result for
entityClass Query yields at least one row. |
AsyncCqlOperations |
getAsyncCqlOperations()
Expose the underlying
AsyncCqlOperations to allow asynchronous CQL operations. |
CassandraConverter |
getConverter()
Returns the underlying
CassandraConverter. |
protected MappingContext<? extends CassandraPersistentEntity<?>,CassandraPersistentProperty> |
getMappingContext()
Returns the
CassandraMappingContext used by this template to access mapping meta-data in order to store
(map) object to Cassandra tables. |
protected SpelAwareProxyProjectionFactory |
getProjectionFactory()
Returns a reference to the configured
ProjectionFactory used by this template to process CQL query
projections. |
protected StatementFactory |
getStatementFactory()
Returns the
StatementFactory used by this template to construct and run Cassandra CQL statements. |
<T> ListenableFuture<T> |
insert(T entity)
Insert the given entity and return the entity if the insert was applied.
|
<T> ListenableFuture<EntityWriteResult<T>> |
insert(T entity,
InsertOptions options)
Insert the given entity applying
WriteOptions and return the entity if the insert was applied. |
<T> ListenableFuture<List<T>> |
select(Query query,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a List of entities. |
<T> ListenableFuture<Void> |
select(Query query,
Consumer<T> entityConsumer,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items notifying Consumer for each entity. |
<T> ListenableFuture<List<T>> |
select(com.datastax.driver.core.Statement statement,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a List of entities. |
<T> ListenableFuture<Void> |
select(com.datastax.driver.core.Statement statement,
Consumer<T> entityConsumer,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items notifying Consumer for each entity. |
<T> ListenableFuture<List<T>> |
select(String cql,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a List of entities. |
<T> ListenableFuture<Void> |
select(String cql,
Consumer<T> entityConsumer,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items notifying Consumer for each entity. |
<T> ListenableFuture<T> |
selectOne(Query query,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
<T> ListenableFuture<T> |
selectOne(com.datastax.driver.core.Statement statement,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
<T> ListenableFuture<T> |
selectOne(String cql,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
<T> ListenableFuture<T> |
selectOneById(Object id,
Class<T> entityClass)
Execute the Select by
id for the given entityClass. |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
<T> ListenableFuture<Slice<T>> |
slice(Query query,
Class<T> entityClass)
Execute a
SELECT query with paging and convert the result set to a Slice of entities. |
<T> ListenableFuture<Slice<T>> |
slice(com.datastax.driver.core.Statement statement,
Class<T> entityClass)
Execute a
SELECT query with paging and convert the result set to a Slice of entities. |
ListenableFuture<Void> |
truncate(Class<?> entityClass)
Execute a
TRUNCATE query to remove all entities of a given class. |
ListenableFuture<Boolean> |
update(Query query,
Update update,
Class<?> entityClass)
Update the queried entities and return true if the update was applied.
|
<T> ListenableFuture<T> |
update(T entity)
Update the given entity and return the entity if the update was applied.
|
<T> ListenableFuture<EntityWriteResult<T>> |
update(T entity,
UpdateOptions options)
Update the given entity applying
WriteOptions and return the entity if the update was applied. |
public AsyncCassandraTemplate(com.datastax.driver.core.Session session)
AsyncCassandraTemplate initialized with the given Session and a default
MappingCassandraConverter.session - Session used to interact with Cassandra; must not be null.CassandraConverter,
Sessionpublic AsyncCassandraTemplate(com.datastax.driver.core.Session session,
CassandraConverter converter)
AsyncCassandraTemplate initialized with the given Session and
CassandraConverter.session - Session used to interact with Cassandra; must not be null.converter - CassandraConverter used to convert between Java and Cassandra types; must not be
null.CassandraConverter,
Sessionpublic AsyncCassandraTemplate(SessionFactory sessionFactory, CassandraConverter converter)
AsyncCassandraTemplate initialized with the given SessionFactory and
CassandraConverter.sessionFactory - SessionFactory used to interact with Cassandra; must not be null.converter - CassandraConverter used to convert between Java and Cassandra types; must not be
null.CassandraConverter,
Sessionpublic AsyncCassandraTemplate(AsyncCqlTemplate asyncCqlTemplate, CassandraConverter converter)
AsyncCassandraTemplate initialized with the given AsyncCqlTemplate and
CassandraConverter.asyncCqlTemplate - AsyncCqlTemplate used to interact with Cassandra; must not be null.converter - CassandraConverter used to convert between Java and Cassandra types; must not be
null.CassandraConverter,
Sessionpublic AsyncCqlOperations getAsyncCqlOperations()
AsyncCassandraOperationsAsyncCqlOperations to allow asynchronous CQL operations.getAsyncCqlOperations in interface AsyncCassandraOperationsAsyncCqlOperations.AsyncCqlOperationspublic CassandraConverter getConverter()
AsyncCassandraOperationsCassandraConverter.getConverter in interface AsyncCassandraOperationsCassandraConverter.public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwarepublic <T> ListenableFuture<List<T>> select(String cql, Class<T> entityClass)
AsyncCassandraOperationsSELECT query and convert the resulting items to a List of entities.select in interface AsyncCassandraOperationscql - must not be null.entityClass - The entity type must not be null.public <T> ListenableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<T> entityClass) throws DataAccessException
AsyncCassandraOperationsSELECT query and convert the resulting items notifying Consumer for each entity.select in interface AsyncCassandraOperationscql - must not be null.entityConsumer - object that will be notified on each entity, one object at a time, must not be
null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public <T> ListenableFuture<T> selectOne(String cql, Class<T> entityClass)
AsyncCassandraOperationsSELECT query and convert the resulting item to an entity.selectOne in interface AsyncCassandraOperationscql - must not be null.entityClass - The entity type must not be null.public <T> ListenableFuture<List<T>> select(com.datastax.driver.core.Statement statement, Class<T> entityClass)
AsyncCassandraOperationsSELECT query and convert the resulting items to a List of entities.select in interface AsyncCassandraOperationsstatement - must not be null.entityClass - The entity type must not be null.public <T> ListenableFuture<Slice<T>> slice(com.datastax.driver.core.Statement statement, Class<T> entityClass)
AsyncCassandraOperationsSELECT query with paging and convert the result set to a Slice of entities.
A sliced query translates the effective fetch size to the page size.slice in interface AsyncCassandraOperationsstatement - the CQL statement, must not be null.entityClass - The entity type must not be null.CassandraPageRequestpublic <T> ListenableFuture<Void> select(com.datastax.driver.core.Statement statement, Consumer<T> entityConsumer, Class<T> entityClass) throws DataAccessException
AsyncCassandraOperationsSELECT query and convert the resulting items notifying Consumer for each entity.select in interface AsyncCassandraOperationsstatement - must not be null.entityConsumer - object that will be notified on each entity, one object at a time, must not be
null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public <T> ListenableFuture<T> selectOne(com.datastax.driver.core.Statement statement, Class<T> entityClass)
AsyncCassandraOperationsSELECT query and convert the resulting item to an entity.selectOne in interface AsyncCassandraOperationsstatement - must not be null.entityClass - The entity type must not be null.public <T> ListenableFuture<List<T>> select(Query query, Class<T> entityClass) throws DataAccessException
AsyncCassandraOperationsSELECT query and convert the resulting items to a List of entities.select in interface AsyncCassandraOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public <T> ListenableFuture<Slice<T>> slice(Query query, Class<T> entityClass) throws DataAccessException
AsyncCassandraOperationsSELECT query with paging and convert the result set to a Slice of entities.slice in interface AsyncCassandraOperationsquery - the query object used to create a CQL statement, must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.CassandraPageRequestpublic <T> ListenableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class<T> entityClass) throws DataAccessException
AsyncCassandraOperationsSELECT query and convert the resulting items notifying Consumer for each entity.select in interface AsyncCassandraOperationsquery - must not be null.entityConsumer - object that will be notified on each entity, one object at a time, must not be
null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public <T> ListenableFuture<T> selectOne(Query query, Class<T> entityClass) throws DataAccessException
AsyncCassandraOperationsSELECT query and convert the resulting item to an entity.selectOne in interface AsyncCassandraOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public ListenableFuture<Boolean> update(Query query, Update update, Class<?> entityClass) throws DataAccessException
AsyncCassandraOperationsupdate in interface AsyncCassandraOperationsquery - must not be null.update - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public ListenableFuture<Boolean> delete(Query query, Class<?> entityClass) throws DataAccessException
AsyncCassandraOperationsQuery.delete in interface AsyncCassandraOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem executing the query.public ListenableFuture<Long> count(Class<?> entityClass)
AsyncCassandraOperationscount in interface AsyncCassandraOperationsentityClass - type of the entity; must not be null.public ListenableFuture<Long> count(Query query, Class<?> entityClass) throws DataAccessException
AsyncCassandraOperationsQuery.
This overridden method allows users to further refine the selection criteria using a Query predicate
to determine how many entities of the given type match the criteria.count in interface AsyncCassandraOperationsquery - user-provided count Query to execute; must not be null.entityClass - type of the entity; must not be null.DataAccessException - if any problem occurs while executing the query.public ListenableFuture<Boolean> exists(Object id, Class<?> entityClass)
AsyncCassandraOperationsentityClass with the given id exists.exists in interface AsyncCassandraOperationsid - Id value. For single primary keys it's the plain value. For composite primary keys either, it's
an instance of either PrimaryKeyClass
or MapId. Must not be null.entityClass - type of the entity; must not be null.public ListenableFuture<Boolean> exists(Query query, Class<?> entityClass) throws DataAccessException
AsyncCassandraOperationsentityClass Query yields at least one row.exists in interface AsyncCassandraOperationsquery - user-provided exists Query to execute; must not be null.entityClass - type of the entity; must not be null.DataAccessException - if any problem occurs while executing the query.public <T> ListenableFuture<T> selectOneById(Object id, Class<T> entityClass)
AsyncCassandraOperationsid for the given entityClass.selectOneById in interface AsyncCassandraOperationsid - the Id value. For single primary keys it's the plain value. For composite primary keys either the
PrimaryKeyClass or
MapId. Must not be null.entityClass - The entity type must not be null.public <T> ListenableFuture<T> insert(T entity)
AsyncCassandraOperationsinsert in interface AsyncCassandraOperationsentity - The entity to insert, must not be null.public <T> ListenableFuture<EntityWriteResult<T>> insert(T entity, InsertOptions options)
AsyncCassandraOperationsWriteOptions and return the entity if the insert was applied.insert in interface AsyncCassandraOperationsentity - The entity to insert, must not be null.options - must not be null.EntityWriteResult for this operation.InsertOptions.empty()public <T> ListenableFuture<T> update(T entity)
AsyncCassandraOperationsupdate in interface AsyncCassandraOperationsentity - The entity to update, must not be null.public <T> ListenableFuture<EntityWriteResult<T>> update(T entity, UpdateOptions options)
AsyncCassandraOperationsWriteOptions and return the entity if the update was applied.update in interface AsyncCassandraOperationsentity - The entity to update, must not be null.options - must not be null.EntityWriteResult for this operation.UpdateOptions.empty()public <T> ListenableFuture<T> delete(T entity)
AsyncCassandraOperationsdelete in interface AsyncCassandraOperationsentity - must not be null.public ListenableFuture<WriteResult> delete(Object entity, QueryOptions options)
AsyncCassandraOperationsQueryOptions and return the entity if the delete was applied.delete in interface AsyncCassandraOperationsentity - must not be null.options - must not be null.WriteResult for this operation.QueryOptions.empty()public ListenableFuture<Boolean> deleteById(Object id, Class<?> entityClass)
AsyncCassandraOperationsdeleteById in interface AsyncCassandraOperationsid - the Id value. For single primary keys it's the plain value. For composite primary keys either the
PrimaryKeyClass or
MapId. Must not be null.entityClass - The entity type must not be null.public ListenableFuture<Void> truncate(Class<?> entityClass)
AsyncCassandraOperationsTRUNCATE query to remove all entities of a given class.truncate in interface AsyncCassandraOperationsentityClass - The entity type must not be null.protected MappingContext<? extends CassandraPersistentEntity<?>,CassandraPersistentProperty> getMappingContext()
CassandraMappingContext used by this template to access mapping meta-data in order to store
(map) object to Cassandra tables.CassandraMappingContext used by this template.CassandraMappingContextprotected SpelAwareProxyProjectionFactory getProjectionFactory()
ProjectionFactory used by this template to process CQL query
projections.ProjectionFactory used by this template to process CQL query
projections.SpelAwareProxyProjectionFactoryprotected StatementFactory getStatementFactory()
StatementFactory used by this template to construct and run Cassandra CQL statements.StatementFactory used by this template to construct and run Cassandra CQL statements.StatementFactoryCopyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.