public interface BatchStatement extends Statement<BatchStatement>, Iterable<BatchableStatement<?>>
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.
ASYNC, NO_DEFAULT_TIMESTAMP, NO_NOW_IN_SECONDS, SYNC
Modifier and Type | Method and Description |
---|---|
BatchStatement |
add(BatchableStatement<?> statement)
Adds a new statement to the batch.
|
default BatchStatement |
addAll(BatchableStatement<?>... statements) |
BatchStatement |
addAll(Iterable<? extends BatchableStatement<?>> statements)
Adds new statements to the batch.
|
static BatchStatementBuilder |
builder(BatchStatement template)
Returns a builder to create an instance of the default implementation, copying the fields of
the given statement.
|
static BatchStatementBuilder |
builder(BatchType batchType)
Returns a builder to create an instance of the default implementation.
|
BatchStatement |
clear()
Clears the batch, removing all the statements added so far.
|
default int |
computeSizeInBytes(DriverContext context)
Calculates the approximate size in bytes that the statement will have when encoded.
|
BatchType |
getBatchType() |
static BatchStatement |
newInstance(BatchType batchType)
Creates an instance of the default implementation for the given batch type.
|
static BatchStatement |
newInstance(BatchType batchType,
BatchableStatement<?>... statements)
Creates an instance of the default implementation for the given batch type, containing the
given statements.
|
static BatchStatement |
newInstance(BatchType batchType,
Iterable<BatchableStatement<?>> statements)
Creates an instance of the default implementation for the given batch type, containing the
given statements.
|
BatchStatement |
setBatchType(BatchType newBatchType)
Sets the batch type.
|
BatchStatement |
setKeyspace(CqlIdentifier newKeyspace)
Sets the CQL keyspace to associate with this batch.
|
default BatchStatement |
setKeyspace(String newKeyspaceName)
Shortcut for
setKeyspace(CqlIdentifier.fromCql(newKeyspaceName)) . |
int |
size() |
copy, disableTracing, enableTracing, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getNowInSeconds, getPageSize, getPagingState, getQueryTimestamp, getSerialConsistencyLevel, isTracing, setConsistencyLevel, setCustomPayload, setDefaultTimestamp, setExecutionProfile, setExecutionProfileName, setFetchSize, setIdempotent, setNode, setNowInSeconds, setPageSize, setPagingState, setPagingState, setPagingState, setQueryTimestamp, setRoutingKey, setRoutingKey, setRoutingKeyspace, setRoutingKeyspace, setRoutingToken, setSerialConsistencyLevel, setTimeout, setTracing
getCustomPayload, getExecutionProfile, getExecutionProfileName, getKeyspace, getNode, getPartitioner, getRoutingKey, getRoutingKeyspace, getRoutingToken, getTimeout, isIdempotent
forEach, iterator, spliterator
@NonNull static BatchStatement newInstance(@NonNull BatchType batchType)
Note that the returned object is immutable.
@NonNull static BatchStatement newInstance(@NonNull BatchType batchType, @NonNull Iterable<BatchableStatement<?>> statements)
Note that the returned object is immutable.
@NonNull static BatchStatement newInstance(@NonNull BatchType batchType, @NonNull BatchableStatement<?>... statements)
Note that the returned object is immutable.
@NonNull static BatchStatementBuilder builder(@NonNull BatchType batchType)
Note that this builder is mutable and not thread-safe.
@NonNull static BatchStatementBuilder builder(@NonNull BatchStatement template)
Note that this builder is mutable and not thread-safe.
@NonNull BatchType getBatchType()
@NonNull BatchStatement setBatchType(@NonNull BatchType newBatchType)
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.
@NonNull BatchStatement setKeyspace(@Nullable CqlIdentifier newKeyspace)
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 v5
or
higher. Specifying a per-request keyspace with lower protocol versions will cause a runtime
error.
Request.getKeyspace()
@NonNull default BatchStatement setKeyspace(@NonNull String newKeyspaceName)
setKeyspace(CqlIdentifier.fromCql(newKeyspaceName))
.@NonNull BatchStatement add(@NonNull BatchableStatement<?> statement)
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.
@NonNull BatchStatement addAll(@NonNull Iterable<? extends BatchableStatement<?>> statements)
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.
@NonNull default BatchStatement addAll(@NonNull BatchableStatement<?>... statements)
addAll(Iterable)
int size()
@NonNull BatchStatement clear()
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.
default int computeSizeInBytes(@NonNull DriverContext context)
Statement
The size might be over-estimated by a few bytes due to global options that may be defined on
a Session
but 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.
computeSizeInBytes
in interface Statement<BatchStatement>
Copyright © 2017–2024. All rights reserved.