public class ReactiveCassandraTemplate extends Object implements ReactiveCassandraOperations, ApplicationEventPublisherAware
ReactiveCassandraOperations. It simplifies the use of Reactive Cassandra usage and
helps to avoid common errors. It executes core Cassandra workflow. This class executes CQL queries or updates,
initiating iteration over ReactiveResultSet 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 ReactiveSessionFactory reference,
or get prepared in an application context and given to services as bean reference.
Note: The ReactiveSessionFactory 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.
ReactiveSelectOperation.ReactiveSelect<T>, ReactiveSelectOperation.SelectWithProjection<T>, ReactiveSelectOperation.SelectWithQuery<T>, ReactiveSelectOperation.SelectWithTable<T>, ReactiveSelectOperation.TerminatingSelect<T>ReactiveInsertOperation.InsertWithOptions<T>, ReactiveInsertOperation.InsertWithTable<T>, ReactiveInsertOperation.ReactiveInsert<T>, ReactiveInsertOperation.TerminatingInsert<T>ReactiveUpdateOperation.ReactiveUpdate, ReactiveUpdateOperation.TerminatingUpdate, ReactiveUpdateOperation.UpdateWithQuery, ReactiveUpdateOperation.UpdateWithTableReactiveDeleteOperation.DeleteWithQuery, ReactiveDeleteOperation.DeleteWithTable, ReactiveDeleteOperation.ReactiveDelete, ReactiveDeleteOperation.TerminatingDelete| Constructor and Description |
|---|
ReactiveCassandraTemplate(ReactiveCqlOperations reactiveCqlOperations,
CassandraConverter converter)
Create an instance of
ReactiveCassandraTemplate initialized with the given ReactiveCqlOperations
and CassandraConverter. |
ReactiveCassandraTemplate(ReactiveSession session)
Creates an instance of
ReactiveCassandraTemplate initialized with the given ReactiveSession and a
default MappingCassandraConverter. |
ReactiveCassandraTemplate(ReactiveSession session,
CassandraConverter converter)
Create an instance of
CassandraTemplate initialized with the given ReactiveSession and
CassandraConverter. |
ReactiveCassandraTemplate(ReactiveSessionFactory sessionFactory,
CassandraConverter converter)
Create an instance of
ReactiveCassandraTemplate initialized with the given ReactiveSessionFactory
and CassandraConverter. |
| Modifier and Type | Method and Description |
|---|---|
ReactiveCassandraBatchOperations |
batchOps()
Returns a new
ReactiveCassandraBatchOperations. |
reactor.core.publisher.Mono<Long> |
count(Class<?> entityClass)
Returns the number of rows for the given entity class.
|
reactor.core.publisher.Mono<Long> |
count(Query query,
Class<?> entityClass)
Returns the number of rows for the given entity class applying
Query. |
ReactiveDeleteOperation.ReactiveDelete |
delete(Class<?> domainType)
Begin creating a
DELETE operation for the given domainType. |
reactor.core.publisher.Mono<WriteResult> |
delete(Object entity,
QueryOptions options)
Delete the given entity applying
QueryOptions and emit the entity if the delete was applied. |
reactor.core.publisher.Mono<Boolean> |
delete(Query query,
Class<?> entityClass)
Remove entities (rows)/columns from the table by
Query. |
<T> reactor.core.publisher.Mono<T> |
delete(T entity)
Delete the given entity and emit the entity if the delete was applied.
|
reactor.core.publisher.Mono<Boolean> |
deleteById(Object id,
Class<?> entityClass)
Remove the given object from the table by id.
|
reactor.core.publisher.Mono<Boolean> |
exists(Object id,
Class<?> entityClass)
Determine whether a row of
entityClass with the given id exists. |
reactor.core.publisher.Mono<Boolean> |
exists(Query query,
Class<?> entityClass)
Determine whether the result for
entityClass Query yields at least one row. |
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. |
ReactiveCqlOperations |
getReactiveCqlOperations()
Expose the underlying
ReactiveCqlOperations to allow CQL operations. |
protected StatementFactory |
getStatementFactory()
Returns the
StatementFactory used by this template to construct and run Cassandra CQL statements. |
<T> ReactiveInsertOperation.ReactiveInsert<T> |
insert(Class<T> domainType)
Begin creating an
INSERT operation for given domainType. |
<T> reactor.core.publisher.Mono<T> |
insert(T entity)
Insert the given entity and emit the entity if the insert was applied.
|
<T> reactor.core.publisher.Mono<EntityWriteResult<T>> |
insert(T entity,
InsertOptions options)
Insert the given entity applying
WriteOptions and emit the entity if the insert was applied. |
<T> ReactiveSelectOperation.ReactiveSelect<T> |
query(Class<T> domainType)
Begin creating a
SELECT operation for the given domainType. |
<T> reactor.core.publisher.Flux<T> |
select(Query query,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a stream of entities. |
<T> reactor.core.publisher.Flux<T> |
select(com.datastax.driver.core.Statement cql,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a stream of entities. |
<T> reactor.core.publisher.Flux<T> |
select(String cql,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting items to a stream of entities. |
<T> reactor.core.publisher.Mono<T> |
selectOne(Query query,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
<T> reactor.core.publisher.Mono<T> |
selectOne(com.datastax.driver.core.Statement statement,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
<T> reactor.core.publisher.Mono<T> |
selectOne(String cql,
Class<T> entityClass)
Execute a
SELECT query and convert the resulting item to an entity. |
<T> reactor.core.publisher.Mono<T> |
selectOneById(Object id,
Class<T> entityClass)
Execute the Select by
id for the given entityClass. |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
<T> reactor.core.publisher.Mono<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> reactor.core.publisher.Mono<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. |
reactor.core.publisher.Mono<Void> |
truncate(Class<?> entityClass)
Execute a
TRUNCATE query to remove all entities of a given class. |
ReactiveUpdateOperation.ReactiveUpdate |
update(Class<?> domainType)
Begin creating an
UPDATE operation for the given domainType. |
reactor.core.publisher.Mono<Boolean> |
update(Query query,
Update update,
Class<?> entityClass)
Update the queried entities and return true if the update was applied.
|
<T> reactor.core.publisher.Mono<T> |
update(T entity)
Update the given entity and emit the entity if the update was applied.
|
<T> reactor.core.publisher.Mono<EntityWriteResult<T>> |
update(T entity,
UpdateOptions options)
Update the given entity applying
WriteOptions and emit the entity if the update was applied. |
public ReactiveCassandraTemplate(ReactiveSession session)
ReactiveCassandraTemplate initialized with the given ReactiveSession and a
default MappingCassandraConverter.session - ReactiveSession used to interact with Cassandra; must not be null.CassandraConverter,
Sessionpublic ReactiveCassandraTemplate(ReactiveSession session, CassandraConverter converter)
CassandraTemplate initialized with the given ReactiveSession and
CassandraConverter.session - ReactiveSession 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 ReactiveCassandraTemplate(ReactiveSessionFactory sessionFactory, CassandraConverter converter)
ReactiveCassandraTemplate initialized with the given ReactiveSessionFactory
and CassandraConverter.sessionFactory - ReactiveSessionFactory 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 ReactiveCassandraTemplate(ReactiveCqlOperations reactiveCqlOperations, CassandraConverter converter)
ReactiveCassandraTemplate initialized with the given ReactiveCqlOperations
and CassandraConverter.reactiveCqlOperations - ReactiveCqlOperations 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 ReactiveCassandraBatchOperations batchOps()
ReactiveCassandraOperationsReactiveCassandraBatchOperations. Each ReactiveCassandraBatchOperations instance can
be executed only once so you might want to obtain new ReactiveCassandraBatchOperations instances for each
batch.batchOps in interface ReactiveCassandraOperationsReactiveCassandraBatchOperations associated with the given entity class.public CassandraConverter getConverter()
ReactiveCassandraOperationsCassandraConverter.getConverter in interface ReactiveCassandraOperationsCassandraConverter.public ReactiveCqlOperations getReactiveCqlOperations()
ReactiveCassandraOperationsReactiveCqlOperations to allow CQL operations.getReactiveCqlOperations in interface ReactiveCassandraOperationsReactiveCqlOperations.ReactiveCqlOperationspublic void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwarepublic <T> reactor.core.publisher.Flux<T> select(String cql, Class<T> entityClass)
ReactiveCassandraOperationsSELECT query and convert the resulting items to a stream of entities.select in interface ReactiveCassandraOperationscql - must not be null.entityClass - The entity type must not be null.public <T> reactor.core.publisher.Mono<T> selectOne(String cql, Class<T> entityClass)
ReactiveCassandraOperationsSELECT query and convert the resulting item to an entity.selectOne in interface ReactiveCassandraOperationscql - must not be null.entityClass - The entity type must not be null.Mono.empty()public <T> reactor.core.publisher.Flux<T> select(com.datastax.driver.core.Statement cql,
Class<T> entityClass)
ReactiveCassandraOperationsSELECT query and convert the resulting items to a stream of entities.select in interface ReactiveCassandraOperationscql - must not be null.entityClass - The entity type must not be null.public <T> reactor.core.publisher.Mono<Slice<T>> slice(com.datastax.driver.core.Statement statement, Class<T> entityClass)
ReactiveCassandraOperationsSELECT 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 ReactiveCassandraOperationsstatement - the CQL statement, must not be null.entityClass - The entity type must not be null.Mono.just(Object) of an empty Slice.public <T> reactor.core.publisher.Mono<T> selectOne(com.datastax.driver.core.Statement statement,
Class<T> entityClass)
ReactiveCassandraOperationsSELECT query and convert the resulting item to an entity.selectOne in interface ReactiveCassandraOperationsstatement - must not be null.entityClass - The entity type must not be null.Mono.empty()public <T> reactor.core.publisher.Flux<T> select(Query query, Class<T> entityClass) throws DataAccessException
ReactiveCassandraOperationsSELECT query and convert the resulting items to a stream of entities.select in interface ReactiveCassandraOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem issuing the execution.public <T> reactor.core.publisher.Mono<Slice<T>> slice(Query query, Class<T> entityClass) throws DataAccessException
ReactiveCassandraOperationsSELECT query with paging and convert the result set to a Slice of entities.slice in interface ReactiveCassandraOperationsquery - the query object used to create a CQL statement, must not be null.entityClass - The entity type must not be null.Mono.just(Object) of an empty Slice.DataAccessException - if there is any problem executing the query.CassandraPageRequestpublic <T> reactor.core.publisher.Mono<T> selectOne(Query query, Class<T> entityClass) throws DataAccessException
ReactiveCassandraOperationsSELECT query and convert the resulting item to an entity.selectOne in interface ReactiveCassandraOperationsquery - must not be null.entityClass - The entity type must not be null.Mono.empty().DataAccessException - if there is any problem issuing the execution.public reactor.core.publisher.Mono<Boolean> update(Query query, Update update, Class<?> entityClass) throws DataAccessException
ReactiveCassandraOperationsupdate in interface ReactiveCassandraOperationsquery - 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 reactor.core.publisher.Mono<Boolean> delete(Query query, Class<?> entityClass) throws DataAccessException
ReactiveCassandraOperationsQuery.delete in interface ReactiveCassandraOperationsquery - must not be null.entityClass - The entity type must not be null.DataAccessException - if there is any problem issuing the execution.public reactor.core.publisher.Mono<Long> count(Class<?> entityClass)
ReactiveCassandraOperationscount in interface ReactiveCassandraOperationsentityClass - type of the entity; must not be null.public reactor.core.publisher.Mono<Long> count(Query query, Class<?> entityClass) throws DataAccessException
ReactiveCassandraOperationsQuery.
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 ReactiveCassandraOperationsquery - user-defined 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 reactor.core.publisher.Mono<Boolean> exists(Object id, Class<?> entityClass)
ReactiveCassandraOperationsentityClass with the given id exists.exists in interface ReactiveCassandraOperationsid - 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 reactor.core.publisher.Mono<Boolean> exists(Query query, Class<?> entityClass) throws DataAccessException
ReactiveCassandraOperationsentityClass Query yields at least one row.exists in interface ReactiveCassandraOperationsquery - user-defined 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> reactor.core.publisher.Mono<T> selectOneById(Object id, Class<T> entityClass)
ReactiveCassandraOperationsid for the given entityClass.selectOneById in interface ReactiveCassandraOperationsid - 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.Mono.empty()public <T> reactor.core.publisher.Mono<T> insert(T entity)
ReactiveCassandraOperationsinsert in interface ReactiveCassandraOperationsentity - The entity to insert, must not be null.public <T> reactor.core.publisher.Mono<EntityWriteResult<T>> insert(T entity, InsertOptions options)
ReactiveCassandraOperationsWriteOptions and emit the entity if the insert was applied.insert in interface ReactiveCassandraOperationsentity - The entity to insert, must not be null.options - must not be null.EntityWriteResult for this operation.InsertOptions.empty()public <T> reactor.core.publisher.Mono<T> update(T entity)
ReactiveCassandraOperationsupdate in interface ReactiveCassandraOperationsentity - The entity to update, must not be null.public <T> reactor.core.publisher.Mono<EntityWriteResult<T>> update(T entity, UpdateOptions options)
ReactiveCassandraOperationsWriteOptions and emit the entity if the update was applied.update in interface ReactiveCassandraOperationsentity - The entity to update, must not be null.options - must not be null.EntityWriteResult for this operation.UpdateOptions.empty()public <T> reactor.core.publisher.Mono<T> delete(T entity)
ReactiveCassandraOperationsdelete in interface ReactiveCassandraOperationsentity - must not be null.public reactor.core.publisher.Mono<WriteResult> delete(Object entity, QueryOptions options)
ReactiveCassandraOperationsQueryOptions and emit the entity if the delete was applied.delete in interface ReactiveCassandraOperationsentity - must not be null.options - must not be null.WriteResult for this operation.QueryOptions.empty()public reactor.core.publisher.Mono<Boolean> deleteById(Object id, Class<?> entityClass)
ReactiveCassandraOperationsdeleteById in interface ReactiveCassandraOperationsid - 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 reactor.core.publisher.Mono<Void> truncate(Class<?> entityClass)
ReactiveCassandraOperationsTRUNCATE query to remove all entities of a given class.truncate in interface ReactiveCassandraOperationsentityClass - The entity type must not be null.public <T> ReactiveSelectOperation.ReactiveSelect<T> query(Class<T> domainType)
ReactiveSelectOperationSELECT operation for the given domainType.query in interface ReactiveSelectOperationT - type of the application domain object.domainType - type of the domain object to query; must not be null.ReactiveSelectOperation.ReactiveSelect.ReactiveSelectOperation.ReactiveSelectpublic <T> ReactiveInsertOperation.ReactiveInsert<T> insert(Class<T> domainType)
ReactiveInsertOperationINSERT operation for given domainType.insert in interface ReactiveInsertOperationT - type of the application domain object.domainType - type of the domain object to insert; must not be null.ReactiveInsertOperation.ReactiveInsert.ReactiveInsertOperation.ReactiveInsertpublic ReactiveUpdateOperation.ReactiveUpdate update(Class<?> domainType)
ReactiveUpdateOperationUPDATE operation for the given domainType.update in interface ReactiveUpdateOperationdomainType - type of domain object to update; must not be null.ReactiveUpdateOperation.ReactiveUpdate.ReactiveUpdateOperation.ReactiveUpdatepublic ReactiveDeleteOperation.ReactiveDelete delete(Class<?> domainType)
ReactiveDeleteOperationDELETE operation for the given domainType.delete in interface ReactiveDeleteOperationdomainType - type of domain object to delete; must not be null.ReactiveDeleteOperation.ReactiveDelete.ReactiveDeleteOperation.ReactiveDeleteprotected 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.