Interface AsyncCassandraOperations
- All Known Implementing Classes:
AsyncCassandraTemplate
public interface AsyncCassandraOperations
Interface specifying a basic set of asynchronous Cassandra operations. Implemented by
AsyncCassandraTemplate
.
Not often used directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.- Since:
- 2.0
- Author:
- Mark Paluch, John Blum
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionReturns the number of rows for the given entity class.Returns the number of rows for the given entity class applyingQuery
.delete
(Object entity, QueryOptions options) Delete the given entity applyingQueryOptions
and return the entity if the delete statement was applied.default CompletableFuture<WriteResult>
delete
(Object entity, DeleteOptions options) Delete the given entity applyingDeleteOptions
and return the entity if the delete statement was applied.Remove entities (rows)/columns from the table byQuery
.<T> CompletableFuture<T>
delete
(T entity) Delete the given entity and return the entity if the delete statement was applied.deleteById
(Object id, Class<?> entityClass) Remove the given object from the table by id.CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet>
execute
(com.datastax.oss.driver.api.core.cql.Statement<?> statement) Execute the given CassandraStatement
.Determine whether a row ofentityClass
with the givenid
exists.Determine whether the result forentityClass
Query
yields at least one row.Expose the underlyingAsyncCqlOperations
to allow asynchronous CQL operations.Returns the underlyingCassandraConverter
.<T> CompletableFuture<T>
insert
(T entity) Insert the given entity and return the entity if the insert was applied.<T> CompletableFuture<EntityWriteResult<T>>
insert
(T entity, InsertOptions options) Insert the given entity applyingWriteOptions
and return the entity if the insert was applied.<T> CompletableFuture<List<T>>
Execute aSELECT
query and convert the resulting items to aList
of entities.<T> CompletableFuture<Void>
select
(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Consumer<T> entityConsumer, Class<T> entityClass) Execute aSELECT
query and convert the resulting items notifyingConsumer
for each entity.<T> CompletableFuture<List<T>>
Execute aSELECT
query and convert the resulting items to aList
of entities.<T> CompletableFuture<Void>
Execute aSELECT
query and convert the resulting items notifyingConsumer
for each entity.<T> CompletableFuture<List<T>>
Execute aSELECT
query and convert the resulting items to aList
of entities.<T> CompletableFuture<Void>
Execute aSELECT
query and convert the resulting items notifyingConsumer
for each entity.<T> CompletableFuture<T>
Execute aSELECT
query and convert the resulting item to an entity.<T> CompletableFuture<T>
Execute aSELECT
query and convert the resulting item to an entity.<T> CompletableFuture<T>
Execute aSELECT
query and convert the resulting item to an entity.<T> CompletableFuture<T>
selectOneById
(Object id, Class<T> entityClass) Execute the Select byid
for the givenentityClass
.<T> CompletableFuture<org.springframework.data.domain.Slice<T>>
Execute aSELECT
query with paging and convert the result set to aSlice
of entities.<T> CompletableFuture<org.springframework.data.domain.Slice<T>>
Execute aSELECT
query with paging and convert the result set to aSlice
of entities.Execute aTRUNCATE
query to remove all entities of a given class.Update the queried entities and return true if the update was applied.<T> CompletableFuture<T>
update
(T entity) Update the given entity and return the entity if the update was applied.<T> CompletableFuture<EntityWriteResult<T>>
update
(T entity, UpdateOptions options) Update the given entity applyingWriteOptions
and return the entity if the update was applied.
-
Method Details
-
getAsyncCqlOperations
AsyncCqlOperations getAsyncCqlOperations()Expose the underlyingAsyncCqlOperations
to allow asynchronous CQL operations.- Returns:
- the underlying
AsyncCqlOperations
. - See Also:
-
getConverter
CassandraConverter getConverter()Returns the underlyingCassandraConverter
.- Returns:
- the underlying
CassandraConverter
.
-
select
<T> CompletableFuture<List<T>> select(String cql, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting items to aList
of entities.- Parameters:
cql
- must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted results
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
select
<T> CompletableFuture<Void> select(String cql, Consumer<T> entityConsumer, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting items notifyingConsumer
for each entity.- Parameters:
cql
- 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.- Returns:
- the completion handle
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
selectOne
<T> CompletableFuture<T> selectOne(String cql, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting item to an entity.- Parameters:
cql
- must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted object or null.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
execute
CompletableFuture<com.datastax.oss.driver.api.core.cql.AsyncResultSet> execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws org.springframework.dao.DataAccessException Execute the given CassandraStatement
. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.- Parameters:
statement
- a CassandraStatement
, must not be null.- Returns:
- the
AsyncResultSet
. - Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- Since:
- 3.2
-
select
<T> CompletableFuture<List<T>> select(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting items to aList
of entities.- Parameters:
statement
- must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted results
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
slice
<T> CompletableFuture<org.springframework.data.domain.Slice<T>> slice(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query with paging and convert the result set to aSlice
of entities. A sliced query translates the effectivefetch size
to the page size.- Parameters:
statement
- the CQL statement, must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted results
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- See Also:
-
select
<T> CompletableFuture<Void> select(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Consumer<T> entityConsumer, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting items notifyingConsumer
for each entity.- Parameters:
statement
- 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.- Returns:
- the completion handle
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
selectOne
<T> CompletableFuture<T> selectOne(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting item to an entity.- Parameters:
statement
- must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted object or null.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
select
<T> CompletableFuture<List<T>> select(Query query, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting items to aList
of entities.- Parameters:
query
- must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted results
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
slice
<T> CompletableFuture<org.springframework.data.domain.Slice<T>> slice(Query query, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query with paging and convert the result set to aSlice
of entities.- Parameters:
query
- the query object used to create a CQL statement, must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted results
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- See Also:
-
select
<T> CompletableFuture<Void> select(Query query, Consumer<T> entityConsumer, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting items notifyingConsumer
for each entity.- Parameters:
query
- 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.- Returns:
- the completion handle
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
selectOne
<T> CompletableFuture<T> selectOne(Query query, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute aSELECT
query and convert the resulting item to an entity.- Parameters:
query
- must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted object or null.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
update
CompletableFuture<Boolean> update(Query query, Update update, Class<?> entityClass) throws org.springframework.dao.DataAccessException Update the queried entities and return true if the update was applied.- Parameters:
query
- must not be null.update
- must not be null.entityClass
- The entity type must not be null.- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
delete
CompletableFuture<Boolean> delete(Query query, Class<?> entityClass) throws org.springframework.dao.DataAccessException Remove entities (rows)/columns from the table byQuery
.- Parameters:
query
- must not be null.entityClass
- The entity type must not be null.- Returns:
- true if the deletion was applied.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
count
CompletableFuture<Long> count(Class<?> entityClass) throws org.springframework.dao.DataAccessException Returns the number of rows for the given entity class.- Parameters:
entityClass
-type
of the entity; must not be null.- Returns:
- the number of existing entities.
- Throws:
org.springframework.dao.DataAccessException
- if any problem occurs while executing the query.
-
count
CompletableFuture<Long> count(Query query, Class<?> entityClass) throws org.springframework.dao.DataAccessException -
exists
CompletableFuture<Boolean> exists(Object id, Class<?> entityClass) throws org.springframework.dao.DataAccessException Determine whether a row ofentityClass
with the givenid
exists.- Parameters:
id
- Id value. For single primary keys it's the plain value. For composite primary keys either, it's an instance of eitherPrimaryKeyClass
orMapId
. Must not be null.entityClass
-type
of the entity; must not be null.- Returns:
- true if the object exists.
- Throws:
org.springframework.dao.DataAccessException
- if any problem occurs while executing the query.
-
exists
CompletableFuture<Boolean> exists(Query query, Class<?> entityClass) throws org.springframework.dao.DataAccessException Determine whether the result forentityClass
Query
yields at least one row. -
selectOneById
<T> CompletableFuture<T> selectOneById(Object id, Class<T> entityClass) throws org.springframework.dao.DataAccessException Execute the Select byid
for the givenentityClass
.- Parameters:
id
- the Id value. For single primary keys it's the plain value. For composite primary keys either thePrimaryKeyClass
orMapId
. Must not be null.entityClass
- The entity type must not be null.- Returns:
- the converted object or null.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
insert
Insert the given entity and return the entity if the insert was applied.- Parameters:
entity
- The entity to insert, must not be null.- Returns:
- the inserted entity.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
insert
<T> CompletableFuture<EntityWriteResult<T>> insert(T entity, InsertOptions options) throws org.springframework.dao.DataAccessException Insert the given entity applyingWriteOptions
and return the entity if the insert was applied.- Parameters:
entity
- The entity to insert, must not be null.options
- must not be null.- Returns:
- the
EntityWriteResult
for this operation. - Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- See Also:
-
update
Update the given entity and return the entity if the update was applied.- Parameters:
entity
- The entity to update, must not be null.- Returns:
- the updated entity.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
update
<T> CompletableFuture<EntityWriteResult<T>> update(T entity, UpdateOptions options) throws org.springframework.dao.DataAccessException Update the given entity applyingWriteOptions
and return the entity if the update was applied.- Parameters:
entity
- The entity to update, must not be null.options
- must not be null.- Returns:
- the
EntityWriteResult
for this operation. - Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- See Also:
-
delete
Delete the given entity and return the entity if the delete statement was applied.- Parameters:
entity
- must not be null.- Returns:
- the deleted entity.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
delete
CompletableFuture<WriteResult> delete(Object entity, QueryOptions options) throws org.springframework.dao.DataAccessException Delete the given entity applyingQueryOptions
and return the entity if the delete statement was applied.- Parameters:
entity
- must not be null.options
- must not be null.- Returns:
- the
WriteResult
for this operation. - Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- See Also:
-
delete
default CompletableFuture<WriteResult> delete(Object entity, DeleteOptions options) throws org.springframework.dao.DataAccessException Delete the given entity applyingDeleteOptions
and return the entity if the delete statement was applied.- Parameters:
entity
- must not be null.options
- must not be null.- Returns:
- the
WriteResult
for this operation. - Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.- Since:
- 2.2
- See Also:
-
deleteById
CompletableFuture<Boolean> deleteById(Object id, Class<?> entityClass) throws org.springframework.dao.DataAccessException Remove the given object from the table by id.- Parameters:
id
- the Id value. For single primary keys it's the plain value. For composite primary keys either thePrimaryKeyClass
orMapId
. Must not be null.entityClass
- The entity type must not be null.- Returns:
- true if the deletion was applied.
- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-
truncate
CompletableFuture<Void> truncate(Class<?> entityClass) throws org.springframework.dao.DataAccessException Execute aTRUNCATE
query to remove all entities of a given class.- Parameters:
entityClass
- The entity type must not be null.- Throws:
org.springframework.dao.DataAccessException
- if there is any problem executing the query.
-