public class ReactiveCassandraTemplate extends Object implements ReactiveCassandraOperations
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.
| 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 |
|---|---|
reactor.core.publisher.Mono<Long> |
count(Class<?> entityClass)
Returns the number of rows for the given entity class.
|
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 the row
entityClass with the given id exists. |
CassandraConverter |
getConverter()
Returns the underlying
CassandraConverter. |
protected MappingContext<? extends CassandraPersistentEntity<?>,CassandraPersistentProperty> |
getMappingContext()
Returns the
CassandraMappingContext used by this template to access mapping meta-data used to store (map)
objects to Cassandra tables. |
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. |
reactor.core.publisher.Mono<WriteResult> |
insert(Object entity,
InsertOptions options)
Insert the given entity applying
WriteOptions and emit the entity if the insert was applied. |
<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.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. |
reactor.core.publisher.Mono<Void> |
truncate(Class<?> entityClass)
Execute a
TRUNCATE query to remove all entities of a given class. |
reactor.core.publisher.Mono<WriteResult> |
update(Object entity,
UpdateOptions options)
Update the given entity applying
WriteOptions and emit the entity if the update was applied. |
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.
|
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 CassandraConverter getConverter()
ReactiveCassandraOperationsCassandraConverter.getConverter in interface ReactiveCassandraOperationsCassandraConverter.protected MappingContext<? extends CassandraPersistentEntity<?>,CassandraPersistentProperty> getMappingContext()
CassandraMappingContext used by this template to access mapping meta-data used to store (map)
objects to Cassandra tables.CassandraMappingContext used by this template.CassandraMappingContextpublic ReactiveCqlOperations getReactiveCqlOperations()
ReactiveCassandraOperationsReactiveCqlOperations to allow CQL operations.getReactiveCqlOperations in interface ReactiveCassandraOperationsReactiveCqlOperations.ReactiveCqlOperationsprotected 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 <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<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<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 - must not be null.public reactor.core.publisher.Mono<Boolean> exists(Object id, Class<?> entityClass)
ReactiveCassandraOperationsentityClass with the given id exists.exists 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 - must not be null.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 reactor.core.publisher.Mono<WriteResult> insert(Object 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.WriteResult 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 reactor.core.publisher.Mono<WriteResult> update(Object 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.WriteResult 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.Copyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.