public class ReactiveCassandraTemplate extends Object implements ReactiveCassandraOperations, ApplicationEventPublisherAware, ApplicationContextAware
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.
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 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(com.datastax.oss.driver.api.core.cql.BatchType batchType)
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<ReactiveResultSet> |
execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement)
Execute the a Cassandra
Statement. |
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 org.springframework.data.cassandra.core.EntityOperations |
getEntityOperations()
Returns the
EntityOperations used to perform data access operations on an entity inside a Cassandra data
source. |
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. |
boolean |
isUsePreparedStatements()
Returns whether this instance is configured to use
prepared statements. |
protected <T> reactor.core.publisher.Mono<T> |
maybeCallBeforeConvert(T object,
com.datastax.oss.driver.api.core.CqlIdentifier tableName) |
protected <T> reactor.core.publisher.Mono<T> |
maybeCallBeforeSave(T object,
com.datastax.oss.driver.api.core.CqlIdentifier tableName,
com.datastax.oss.driver.api.core.cql.Statement<?> statement) |
protected <E extends CassandraMappingEvent<T>,T> |
maybeEmitEvent(E event) |
<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.oss.driver.api.core.cql.Statement<?> statement,
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.oss.driver.api.core.cql.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 |
setApplicationContext(ApplicationContext applicationContext) |
void |
setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) |
void |
setEntityCallbacks(ReactiveEntityCallbacks entityCallbacks)
Configure
EntityCallbacks to pre-/post-process entities during persistence operations. |
void |
setUsePreparedStatements(boolean usePreparedStatements)
Enable/disable
prepared statements usage. |
<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.oss.driver.api.core.cql.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. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbatchOps, deletepublic 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,
CqlSessionpublic 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,
CqlSessionpublic 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,
CqlSessionpublic ReactiveCassandraBatchOperations batchOps(com.datastax.oss.driver.api.core.cql.BatchType batchType)
ReactiveCassandraOperationsReactiveCassandraBatchOperations. Each ReactiveCassandraBatchOperations instance can
be executed only once, so you need to obtain new ReactiveCassandraBatchOperations instances for each batch.batchOps in interface ReactiveCassandraOperationsbatchType - must not be null.ReactiveCassandraBatchOperations associated with the given entity class.public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher in interface ApplicationEventPublisherAwarepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext in interface ApplicationContextAwareBeansExceptionpublic void setEntityCallbacks(@Nullable ReactiveEntityCallbacks entityCallbacks)
EntityCallbacks to pre-/post-process entities during persistence operations.entityCallbacks - public ReactiveCqlOperations getReactiveCqlOperations()
ReactiveCassandraOperationsReactiveCqlOperations to allow CQL operations.getReactiveCqlOperations in interface ReactiveCassandraOperationsReactiveCqlOperations.ReactiveCqlOperationspublic CassandraConverter getConverter()
ReactiveCassandraOperationsCassandraConverter.getConverter in interface ReactiveCassandraOperationsCassandraConverter.public boolean isUsePreparedStatements()
prepared statements. If enabled
(default), then all persistence methods (such as select(java.lang.String, java.lang.Class<T>), update(org.springframework.data.cassandra.core.query.Query, org.springframework.data.cassandra.core.query.Update, java.lang.Class<?>), and others) will make use of
prepared statements. Note that methods accepting a Statement must be called with SimpleStatement
instances to participate in statement preparation.public void setUsePreparedStatements(boolean usePreparedStatements)
prepared statements usage. If enabled (default), then all persistence
methods (such as select(java.lang.String, java.lang.Class<T>), update(org.springframework.data.cassandra.core.query.Query, org.springframework.data.cassandra.core.query.Update, java.lang.Class<?>), and others) will make use of prepared statements. Note that
methods accepting a Statement must be called with SimpleStatement instances to participate in
statement preparation.usePreparedStatements - whether to use prepared statements.protected org.springframework.data.cassandra.core.EntityOperations getEntityOperations()
EntityOperations used to perform data access operations on an entity inside a Cassandra data
source.EntityOperations for this template.EntityOperationsprotected 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.StatementFactorypublic <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 reactor.core.publisher.Mono<ReactiveResultSet> execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws DataAccessException
ReactiveCassandraOperationsStatement. Any errors that result from executing this command will be converted
into Spring's DAO exception hierarchy.execute in interface ReactiveCassandraOperationsstatement - a Cassandra Statement, must not be null.ReactiveResultSet.DataAccessException - if there is any problem issuing the execution.public <T> reactor.core.publisher.Flux<T> select(com.datastax.oss.driver.api.core.cql.Statement<?> statement,
Class<T> entityClass)
ReactiveCassandraOperationsSELECT query and convert the resulting items to a stream of entities.select in interface ReactiveCassandraOperationsstatement - must not be null.entityClass - The entity type must not be null.public <T> reactor.core.publisher.Mono<T> selectOne(com.datastax.oss.driver.api.core.cql.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.Mono<Slice<T>> slice(com.datastax.oss.driver.api.core.cql.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.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<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 <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 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 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.ReactiveDeletepublic <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 <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 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.ReactiveUpdateprotected <E extends CassandraMappingEvent<T>,T> void maybeEmitEvent(E event)
protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeConvert(T object,
com.datastax.oss.driver.api.core.CqlIdentifier tableName)
protected <T> reactor.core.publisher.Mono<T> maybeCallBeforeSave(T object,
com.datastax.oss.driver.api.core.CqlIdentifier tableName,
com.datastax.oss.driver.api.core.cql.Statement<?> statement)
Copyright © 2011–2021 Pivotal Software, Inc.. All rights reserved.