Interface CassandraOperations
- All Superinterfaces:
ExecutableDeleteOperation,ExecutableInsertOperation,ExecutableSelectOperation,ExecutableUpdateOperation,FluentCassandraOperations
- All Known Subinterfaces:
CassandraAdminOperations
- All Known Implementing Classes:
CassandraAdminTemplate,CassandraTemplate
Interface specifying a basic set of Cassandra operations. Implemented by
CassandraTemplate. Not often used
directly, but a useful option to enhance testability, as it can easily be mocked or stubbed.- Author:
- Alex Shvid, David Webb, Matthew Adams, Mark Paluch, Sam Lightfoot
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.cassandra.core.ExecutableDeleteOperation
ExecutableDeleteOperation.DeleteWithQuery, ExecutableDeleteOperation.DeleteWithTable, ExecutableDeleteOperation.ExecutableDelete, ExecutableDeleteOperation.TerminatingDeleteNested classes/interfaces inherited from interface org.springframework.data.cassandra.core.ExecutableInsertOperation
ExecutableInsertOperation.ExecutableInsert<T>, ExecutableInsertOperation.InsertWithOptions<T>, ExecutableInsertOperation.InsertWithTable<T>, ExecutableInsertOperation.TerminatingInsert<T>Nested classes/interfaces inherited from interface org.springframework.data.cassandra.core.ExecutableSelectOperation
ExecutableSelectOperation.ExecutableSelect<T>, ExecutableSelectOperation.SelectWithProjection<T>, ExecutableSelectOperation.SelectWithQuery<T>, ExecutableSelectOperation.SelectWithTable<T>, ExecutableSelectOperation.TerminatingSelect<T>Nested classes/interfaces inherited from interface org.springframework.data.cassandra.core.ExecutableUpdateOperation
ExecutableUpdateOperation.ExecutableUpdate, ExecutableUpdateOperation.TerminatingUpdate, ExecutableUpdateOperation.UpdateWithQuery, ExecutableUpdateOperation.UpdateWithTable -
Method Summary
Modifier and TypeMethodDescriptiondefault CassandraBatchOperationsbatchOps()Returns a newCassandraBatchOperationsusingBatchType.LOGGED.batchOps(com.datastax.oss.driver.api.core.cql.BatchType batchType) Returns a newCassandraBatchOperations.longReturns the number of rows for the given entity class.longReturns the number of rows for the given entity class applyingQuery.voidDelete the given entity and return the entity if the delete statement was applied.delete(Object entity, QueryOptions options) Delete the given entity applyingQueryOptionsand return the entity if the delete statement was applied.default WriteResultdelete(Object entity, DeleteOptions options) Delete the given entity applyingDeleteOptionsand return the entity if the delete statement was applied.booleanRemove entities (rows)/columns from the table byQuery.booleandeleteById(Object id, Class<?> entityClass) Remove the given object from the table by id.com.datastax.oss.driver.api.core.cql.ResultSetexecute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) Execute the given CassandraStatement.booleanDetermine whether a row ofentityClasswith the givenidexists.booleanDetermine whether the result forentityClassQueryyields at least one row.Returns the underlyingCassandraConverter.Expose the underlyingCqlOperationsto allow CQL operations.com.datastax.oss.driver.api.core.CqlIdentifiergetTableName(Class<?> entityClass) The table name used for the specified class by this template.<T> Tinsert(T entity) Insert the given entity and return the entity if the insert was applied.<T> EntityWriteResult<T>insert(T entity, InsertOptions options) Insert the given entity applyingWriteOptionsand return the entity if the insert was applied.<T> List<T>Execute aSELECTquery and convert the resulting items to aListof entities.<T> List<T>Execute aSELECTquery and convert the resulting items to aListof entities.<T> List<T>Execute aSELECTquery and convert the resulting items to aListof entities.<T> TExecute aSELECTquery and convert the resulting item to an entity.<T> TExecute aSELECTquery and convert the resulting item to an entity.<T> TExecute aSELECTquery and convert the resulting item to an entity.<T> TselectOneById(Object id, Class<T> entityClass) Execute the Select byidfor the givenentityClass.<T> Slice<T>Execute aSELECTquery with paging and convert the result set to aSliceof entities.<T> Slice<T>Execute aSELECTquery with paging and convert the result set to aSliceof entities.<T> Stream<T>Execute aSELECTquery and convert the resulting items to aIteratorof entities.<T> Stream<T>Execute aSELECTquery and convert the resulting items to aIteratorof entities.<T> Stream<T>Execute aSELECTquery and convert the resulting items to aIteratorof entities.voidExecute aTRUNCATEquery to remove all entities of a given class.booleanUpdate the queried entities and return true if the update was applied.<T> Tupdate(T entity) Update the given entity and return the entity if the update was applied.<T> EntityWriteResult<T>update(T entity, UpdateOptions options) Update the given entity applyingWriteOptionsand return the entity if the update was applied.Methods inherited from interface org.springframework.data.cassandra.core.ExecutableDeleteOperation
deleteMethods inherited from interface org.springframework.data.cassandra.core.ExecutableInsertOperation
insertMethods inherited from interface org.springframework.data.cassandra.core.ExecutableSelectOperation
queryMethods inherited from interface org.springframework.data.cassandra.core.ExecutableUpdateOperation
update
-
Method Details
-
batchOps
Returns a newCassandraBatchOperationsusingBatchType.LOGGED. EachCassandraBatchOperationsinstance can be executed only once, so you need to obtain newCassandraBatchOperationsinstances for each batch.- Returns:
- a new
CassandraBatchOperationsassociated with the given entity class. - See Also:
-
batchOps
Returns a newCassandraBatchOperations. EachCassandraBatchOperationsinstance can be executed only once, so you need to obtain newCassandraBatchOperationsinstances for each batch.- Parameters:
batchType- must not be null.- Returns:
- a new
ReactiveCassandraBatchOperationsassociated with the given entity class. - Since:
- 3.2.6
-
getCqlOperations
CqlOperations getCqlOperations()Expose the underlyingCqlOperationsto allow CQL operations.- Returns:
- the underlying
CqlOperations. - See Also:
-
getConverter
CassandraConverter getConverter()Returns the underlyingCassandraConverter.- Returns:
- the underlying
CassandraConverter.
-
getTableName
The table name used for the specified class by this template.- Parameters:
entityClass- The entity type must not be null.- Returns:
- the
CqlIdentifier
-
select
Execute aSELECTquery and convert the resulting items to aListof entities.- Parameters:
cql- must not be null.entityClass- The entity type must not be null.- Returns:
- the converted results
- Throws:
DataAccessException- if there is any problem executing the query.
-
stream
Execute aSELECTquery and convert the resulting items to aIteratorof entities.Returns a
Iteratorthat wraps the CassandraResultSet.- Type Parameters:
T- element return type.- Parameters:
cql- query to execute. Must not be empty or null.entityClass- Class type of the elements in theIteratorstream. Must not be null.- Returns:
- an
Iterator(stream) over the elements in the query result set. - Throws:
DataAccessException- if there is any problem executing the query.- Since:
- 1.5
-
selectOne
Execute aSELECTquery 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:
DataAccessException- if there is any problem executing the query.
-
execute
com.datastax.oss.driver.api.core.cql.ResultSet execute(com.datastax.oss.driver.api.core.cql.Statement<?> statement) throws 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
ResultSet. - Throws:
DataAccessException- if there is any problem executing the query.- Since:
- 3.2
-
select
<T> List<T> select(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException Execute aSELECTquery and convert the resulting items to aListof entities.- Parameters:
statement- must not be null.entityClass- The entity type must not be null.- Returns:
- the converted results
- Throws:
DataAccessException- if there is any problem executing the query.
-
slice
<T> Slice<T> slice(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException Execute aSELECTquery with paging and convert the result set to aSliceof entities. A sliced query translates the effectivefetch sizeto 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:
DataAccessException- if there is any problem executing the query.- Since:
- 2.0
-
stream
<T> Stream<T> stream(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException Execute aSELECTquery and convert the resulting items to aIteratorof entities.Returns a
Iteratorthat wraps the CassandraResultSet.- Type Parameters:
T- element return type.- Parameters:
statement- query to execute. Must not be empty or null.entityClass- Class type of the elements in theIteratorstream. Must not be null.- Returns:
- an
Iterator(stream) over the elements in the query result set. - Throws:
DataAccessException- if there is any problem executing the query.- Since:
- 1.5
-
selectOne
@Nullable <T> T selectOne(com.datastax.oss.driver.api.core.cql.Statement<?> statement, Class<T> entityClass) throws DataAccessException Execute aSELECTquery 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:
DataAccessException- if there is any problem executing the query.
-
select
Execute aSELECTquery and convert the resulting items to aListof entities.- Parameters:
query- must not be null.entityClass- The entity type must not be null.- Returns:
- the converted results
- Throws:
DataAccessException- if there is any problem executing the query.- Since:
- 2.0
-
slice
Execute aSELECTquery with paging and convert the result set to aSliceof 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:
DataAccessException- if there is any problem executing the query.- Since:
- 2.0
- See Also:
-
stream
Execute aSELECTquery and convert the resulting items to aIteratorof entities.Returns a
Iteratorthat wraps the CassandraResultSet.- Type Parameters:
T- element return type.- Parameters:
query- query to execute. Must not be empty or null.entityClass- Class type of the elements in theIteratorstream. Must not be null.- Returns:
- an
Iterator(stream) over the elements in the query result set. - Throws:
DataAccessException- if there is any problem executing the query.- Since:
- 2.0
-
selectOne
Execute aSELECTquery 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:
DataAccessException- if there is any problem executing the query.- Since:
- 2.0
-
update
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:
DataAccessException- if there is any problem executing the query.
-
delete
Remove entities (rows)/columns from the table byQuery.- Parameters:
query- must not be null.entityClass- The entity type must not be null.- Throws:
DataAccessException- if there is any problem executing the query.
-
count
Returns the number of rows for the given entity class.- Parameters:
entityClass-typeof the entity; must not be null.- Returns:
- the number of existing entities.
- Throws:
DataAccessException- if any problem occurs while executing the query.
-
count
Returns the number of rows for the given entity class applyingQuery. This overridden method allows users to further refine the selection criteria using aQuerypredicate to determine how many entities of the giventypematch the criteria.- Parameters:
query- user-defined countQueryto execute; must not be null.entityClass-typeof the entity; must not be null.- Returns:
- the number of existing entities.
- Throws:
DataAccessException- if any problem occurs while executing the query.- Since:
- 2.1
-
exists
Determine whether a row ofentityClasswith the givenidexists.- Parameters:
id- Id value. For single primary keys it's the plain value. For composite primary keys either, it's an instance of eitherPrimaryKeyClassorMapId. Must not be null.entityClass-typeof the entity; must not be null.- Returns:
- true if the object exists.
- Throws:
DataAccessException- if any problem occurs while executing the query.
-
exists
Determine whether the result forentityClassQueryyields at least one row.- Parameters:
query- user-defined existsQueryto execute; must not be null.entityClass-typeof the entity; must not be null.- Returns:
- true if the object exists.
- Throws:
DataAccessException- if any problem occurs while executing the query.- Since:
- 2.1
-
selectOneById
Execute the Select byidfor the givenentityClass.- Parameters:
id- the Id value. For single primary keys it's the plain value. For composite primary keys either thePrimaryKeyClassorMapId. Must not be null.entityClass- The entity type must not be null.- Returns:
- the converted object or null.
- Throws:
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:
DataAccessException- if there is any problem executing the query.
-
insert
Insert the given entity applyingWriteOptionsand 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
EntityWriteResultfor this operation. - Throws:
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:
DataAccessException- if there is any problem executing the query.
-
update
Update the given entity applyingWriteOptionsand 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
EntityWriteResultfor this operation. - Throws:
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.- Throws:
DataAccessException- if there is any problem executing the query.
-
delete
Delete the given entity applyingQueryOptionsand return the entity if the delete statement was applied.- Parameters:
entity- must not be null.options- must not be null.- Returns:
- the
WriteResultfor this operation. - Throws:
DataAccessException- if there is any problem executing the query.- See Also:
-
delete
Delete the given entity applyingDeleteOptionsand return the entity if the delete statement was applied.- Parameters:
entity- must not be null.options- must not be null.- Returns:
- the
WriteResultfor this operation. - Throws:
DataAccessException- if there is any problem executing the query.- Since:
- 2.2
- See Also:
-
deleteById
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 thePrimaryKeyClassorMapId. Must not be null.entityClass- The entity type must not be null.- Throws:
DataAccessException- if there is any problem executing the query.
-
truncate
Execute aTRUNCATEquery to remove all entities of a given class.- Parameters:
entityClass- The entity type must not be null.- Throws:
DataAccessException- if there is any problem executing the query.
-