Interface CassandraBatchOperations
public interface CassandraBatchOperations
Batch operations for insert/update/delete actions on a table.
CassandraBatchOperations
use logged Cassandra
BATCH
es 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 astatement
to the batch.addStatements
(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>... statements) Addstatements
to the batch.addStatements
(Iterable<? extends com.datastax.oss.driver.api.core.cql.BatchableStatement<?>> statements) Addstatements
to the batch.Add a collection of deletes to the batch.delete
(Iterable<?> entities, WriteOptions options) Add a collection of deletes with givenWriteOptions
to the batch.Add an array of deletes to the batch.default CassandraBatchOperations
delete
(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 givenWriteOptions
to the batch.Add an array of inserts to the batch.default CassandraBatchOperations
insert
(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 givenWriteOptions
to the batch.Add an array of updates to the batch.default CassandraBatchOperations
update
(Object entity, WriteOptions options) Add an update to the batch.withQueryOptions
(QueryOptions options) Apply givenQueryOptions
to the whole batch statement.withTimestamp
(long timestamp) Apply a giventimestamp
to the whole batch.
-
Method Details
-
execute
WriteResult execute()Execute the batch. The batch can be executed only once.- Returns:
- the
WriteResult
for the bulk operation. - Throws:
IllegalStateException
- if the batch is executed after it was executed already.
-
withTimestamp
Apply a giventimestamp
to the whole batch.- Parameters:
timestamp
- the timestamp to apply.- Returns:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.
-
withQueryOptions
Apply givenQueryOptions
to the whole batch statement.- Parameters:
options
- the options to apply.- Returns:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.- Since:
- 4.4
-
addStatement
CassandraBatchOperations addStatement(com.datastax.oss.driver.api.core.cql.BatchableStatement<?> statement) Add astatement
to the batch.- Parameters:
statement
- the batchable statement such asINSERT
,UPDATE
,DELETE
.- Returns:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.- Since:
- 4.4
-
addStatements
CassandraBatchOperations addStatements(com.datastax.oss.driver.api.core.cql.BatchableStatement<?>... statements) Addstatements
to the batch.- Parameters:
statements
- the batchable statements such asINSERT
,UPDATE
,DELETE
.- Returns:
this
CassandraBatchOperations
.- 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) Addstatements
to the batch.- Parameters:
statements
- the batchable statements such asINSERT
,UPDATE
,DELETE
.- Returns:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.
-
insert
Add a collection of inserts with givenWriteOptions
to the batch.- Parameters:
entities
- the entities to insert; must not be null.options
- the WriteOptions to apply; must not be null.- Returns:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.
-
update
Add a collection of updates with givenWriteOptions
to the batch.- Parameters:
entities
- the entities to update; must not be null.options
- the WriteOptions to apply; must not be null.- Returns:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- 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:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.
-
delete
Add a collection of deletes with givenWriteOptions
to the batch.- Parameters:
entities
- the entities to delete; must not be null.options
- the WriteOptions to apply; must not be null.- Returns:
this
CassandraBatchOperations
.- Throws:
IllegalStateException
- if the batch was already executed.- Since:
- 2.2
- See Also:
-