Interface BatchStatement
-
- All Superinterfaces:
Iterable<BatchableStatement<?>>,Request,Statement<BatchStatement>
public interface BatchStatement extends Statement<BatchStatement>, Iterable<BatchableStatement<?>>
A statement that groups a number of other statements, so that they can be executed as a batch (i.e. sent together as a single protocol frame).The default implementation returned by the driver is immutable and thread-safe. All mutating methods return a new instance. See also the static factory methods and builders in this interface.
-
-
Field Summary
-
Fields inherited from interface com.datastax.oss.driver.api.core.cql.Statement
ASYNC, NO_DEFAULT_TIMESTAMP, NO_NOW_IN_SECONDS, SYNC
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description BatchStatementadd(BatchableStatement<?> statement)Adds a new statement to the batch.default BatchStatementaddAll(BatchableStatement<?>... statements)BatchStatementaddAll(Iterable<? extends BatchableStatement<?>> statements)Adds new statements to the batch.static BatchStatementBuilderbuilder(BatchStatement template)Returns a builder to create an instance of the default implementation, copying the fields of the given statement.static BatchStatementBuilderbuilder(BatchType batchType)Returns a builder to create an instance of the default implementation.BatchStatementclear()Clears the batch, removing all the statements added so far.default intcomputeSizeInBytes(DriverContext context)Calculates the approximate size in bytes that the statement will have when encoded.BatchTypegetBatchType()static BatchStatementnewInstance(BatchType batchType)Creates an instance of the default implementation for the given batch type.static BatchStatementnewInstance(BatchType batchType, BatchableStatement<?>... statements)Creates an instance of the default implementation for the given batch type, containing the given statements.static BatchStatementnewInstance(BatchType batchType, Iterable<BatchableStatement<?>> statements)Creates an instance of the default implementation for the given batch type, containing the given statements.BatchStatementsetBatchType(BatchType newBatchType)Sets the batch type.BatchStatementsetKeyspace(CqlIdentifier newKeyspace)Sets the CQL keyspace to associate with this batch.default BatchStatementsetKeyspace(String newKeyspaceName)Shortcut forsetKeyspace(CqlIdentifier.fromCql(newKeyspaceName)).intsize()-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
Methods inherited from interface com.datastax.oss.driver.api.core.session.Request
getCustomPayload, getExecutionProfile, getExecutionProfileName, getKeyspace, getNode, getPartitioner, getRequestRoutingType, getRoutingKey, getRoutingKeyspace, getRoutingTable, getRoutingToken, getTimeout, isIdempotent
-
Methods inherited from interface com.datastax.oss.driver.api.core.cql.Statement
copy, disableTracing, enableTracing, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getNowInSeconds, getPageSize, getPagingState, getQueryTimestamp, getSerialConsistencyLevel, isLWT, isTracing, setConsistencyLevel, setCustomPayload, setDefaultTimestamp, setExecutionProfile, setExecutionProfileName, setFetchSize, setIdempotent, setNode, setNowInSeconds, setPageSize, setPagingState, setPagingState, setPagingState, setQueryTimestamp, setRequestRoutingType, setRoutingKey, setRoutingKey, setRoutingKeyspace, setRoutingKeyspace, setRoutingToken, setSerialConsistencyLevel, setTimeout, setTracing
-
-
-
-
Method Detail
-
newInstance
@NonNull static BatchStatement newInstance(@NonNull BatchType batchType)
Creates an instance of the default implementation for the given batch type.Note that the returned object is immutable.
-
newInstance
@NonNull static BatchStatement newInstance(@NonNull BatchType batchType, @NonNull Iterable<BatchableStatement<?>> statements)
Creates an instance of the default implementation for the given batch type, containing the given statements.Note that the returned object is immutable.
-
newInstance
@NonNull static BatchStatement newInstance(@NonNull BatchType batchType, @NonNull BatchableStatement<?>... statements)
Creates an instance of the default implementation for the given batch type, containing the given statements.Note that the returned object is immutable.
-
builder
@NonNull static BatchStatementBuilder builder(@NonNull BatchType batchType)
Returns a builder to create an instance of the default implementation.Note that this builder is mutable and not thread-safe.
-
builder
@NonNull static BatchStatementBuilder builder(@NonNull BatchStatement template)
Returns a builder to create an instance of the default implementation, copying the fields of the given statement.Note that this builder is mutable and not thread-safe.
-
getBatchType
@NonNull BatchType getBatchType()
-
setBatchType
@NonNull @CheckReturnValue BatchStatement setBatchType(@NonNull BatchType newBatchType)
Sets the batch type.The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
setKeyspace
@NonNull @CheckReturnValue BatchStatement setKeyspace(@Nullable CqlIdentifier newKeyspace)
Sets the CQL keyspace to associate with this batch.If the keyspace is not set explicitly with this method, it will be inferred from the first simple statement in the batch that has a keyspace set (or will be null if no such statement exists).
This feature is only available with
native protocol v5or higher. Specifying a per-request keyspace with lower protocol versions will cause a runtime error.- See Also:
Request.getKeyspace()
-
setKeyspace
@NonNull @CheckReturnValue default BatchStatement setKeyspace(@NonNull String newKeyspaceName)
Shortcut forsetKeyspace(CqlIdentifier.fromCql(newKeyspaceName)).
-
add
@NonNull @CheckReturnValue BatchStatement add(@NonNull BatchableStatement<?> statement)
Adds a new statement to the batch.Note that, due to protocol limitations, simple statements with named values are currently not supported.
The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
addAll
@NonNull @CheckReturnValue BatchStatement addAll(@NonNull Iterable<? extends BatchableStatement<?>> statements)
Adds new statements to the batch.Note that, due to protocol limitations, simple statements with named values are currently not supported.
The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
addAll
@NonNull @CheckReturnValue default BatchStatement addAll(@NonNull BatchableStatement<?>... statements)
- See Also:
addAll(Iterable)
-
size
int size()
- Returns:
- The number of child statements in this batch.
-
clear
@NonNull @CheckReturnValue BatchStatement clear()
Clears the batch, removing all the statements added so far.The driver's built-in implementation is immutable, and returns a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
computeSizeInBytes
default int computeSizeInBytes(@NonNull DriverContext context)Description copied from interface:StatementCalculates the approximate size in bytes that the statement will have when encoded.The size might be over-estimated by a few bytes due to global options that may be defined on a
Sessionbut not explicitly set on the statement itself.The result of this method is not cached, calling it will cause some encoding to be done in order to determine some of the statement's attributes sizes. Therefore, use this method sparingly in order to avoid unnecessary computation.
- Specified by:
computeSizeInBytesin interfaceStatement<BatchStatement>- Returns:
- the approximate number of bytes this statement will take when encoded.
-
-