Module spring.data.cassandra
Interface CassandraBatchOperations
public interface CassandraBatchOperations
Batch operations for insert/update/delete actions on a table.
CassandraBatchOperations use logged Cassandra
BATCHes for single entities, collections of entities, and statements. A
CassandraBatchOperations instance cannot be modified/used once it was executed.
Batches are atomic by default. In the context of a Cassandra batch operation, atomic means that if any of the batch
succeeds, all of it will. Statement order does not matter within a batch. CassandraBatchOperations applies
all rows using the same timestamp if supplied, otherwise Cassandra will generate a
timestamp.
Multi partition batches should only be used to achieve atomicity for a few writes on different tables. Apart from this they should be avoided because they’re too expensive. Single partition batches can be used to get atomicity and isolation, they're not much more expensive than normal writes.
- Since:
- 1.5
- Author:
- Mark Paluch, Anup Sabbi
-
Method Summary
Modifier and TypeMethodDescriptionaddStatement(com.datastax.oss.driver.api.core.cql.BatchableStatement<?> statement) Add astatementto the batch.addStatements(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>... statements) Addstatementsto the batch.addStatements(Iterable<? extends com.datastax.oss.driver.api.core.cql.BatchableStatement<?>> statements) Addstatementsto the batch.Add a collection of deletes to the batch.delete(Iterable<?> entities, WriteOptions options) Add a collection of deletes with givenWriteOptionsto the batch.Add an array of deletes to the batch.default CassandraBatchOperationsdelete(Object entity, WriteOptions options) Add delete to the batch.execute()Execute the batch.Add a collection of inserts to the batch.insert(Iterable<?> entities, WriteOptions options) Add a collection of inserts with givenWriteOptionsto the batch.Add an array of inserts to the batch.default CassandraBatchOperationsinsert(Object entity, WriteOptions options) Add an insert to the batch.Add a collection of updates to the batch.update(Iterable<?> entities, WriteOptions options) Add a collection of updates with givenWriteOptionsto the batch.Add an array of updates to the batch.default CassandraBatchOperationsupdate(Object entity, WriteOptions options) Add an update to the batch.withQueryOptions(QueryOptions options) Apply givenQueryOptionsto the whole batch statement.withTimestamp(long timestamp) Apply a giventimestampto the whole batch.
-
Method Details
-
execute
WriteResult execute()Execute the batch. The batch can be executed only once.- Returns:
- the
WriteResultfor the bulk operation. - Throws:
IllegalStateException- if the batch is executed after it was executed already.
-
withTimestamp
Apply a giventimestampto the whole batch.- Parameters:
timestamp- the timestamp to apply.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
withQueryOptions
Apply givenQueryOptionsto the whole batch statement.- Parameters:
options- the options to apply.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 4.4
-
addStatement
CassandraBatchOperations addStatement(com.datastax.oss.driver.api.core.cql.BatchableStatement<?> statement) Add astatementto the batch.- Parameters:
statement- the batchable statement such asINSERT,UPDATE,DELETE.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 4.4
-
addStatements
CassandraBatchOperations addStatements(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>... statements) Addstatementsto the batch.- Parameters:
statements- the batchable statements such asINSERT,UPDATE,DELETE.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 4.4
-
addStatements
CassandraBatchOperations addStatements(Iterable<? extends com.datastax.oss.driver.api.core.cql.BatchableStatement<?>> statements) Addstatementsto the batch.- Parameters:
statements- the batchable statements such asINSERT,UPDATE,DELETE.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 4.4
-
insert
Add an insert to the batch.- Parameters:
entity- the entity to insert; must not be null.options- the WriteOptions to apply; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 3.2.2
-
insert
Add an array of inserts to the batch.- Parameters:
entities- the entities to insert; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
insert
Add a collection of inserts to the batch.- Parameters:
entities- the entities to insert; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
insert
Add a collection of inserts with givenWriteOptionsto the batch.- Parameters:
entities- the entities to insert; must not be null.options- the WriteOptions to apply; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 2.0
- See Also:
-
update
Add an update to the batch.- Parameters:
entity- the entity to update; must not be null.options- the WriteOptions to apply; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 3.2.2
-
update
Add an array of updates to the batch.- Parameters:
entities- the entities to update; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
update
Add a collection of updates to the batch.- Parameters:
entities- the entities to update; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
update
Add a collection of updates with givenWriteOptionsto the batch.- Parameters:
entities- the entities to update; must not be null.options- the WriteOptions to apply; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 2.0
- See Also:
-
delete
Add delete to the batch.- Parameters:
entity- the entity to delete; must not be null.options- the WriteOptions to apply; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 3.2.2
-
delete
Add an array of deletes to the batch.- Parameters:
entities- the entities to delete; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
delete
Add a collection of deletes to the batch.- Parameters:
entities- the entities to delete; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.
-
delete
Add a collection of deletes with givenWriteOptionsto the batch.- Parameters:
entities- the entities to delete; must not be null.options- the WriteOptions to apply; must not be null.- Returns:
thisCassandraBatchOperations.- Throws:
IllegalStateException- if the batch was already executed.- Since:
- 2.2
- See Also:
-