Class Batch
- java.lang.Object
-
- com.datastax.driver.core.Statement
-
- com.datastax.driver.core.RegularStatement
-
- com.datastax.driver.core.querybuilder.BuiltStatement
-
- com.datastax.driver.core.querybuilder.Batch
-
public class Batch extends BuiltStatement
A built BATCH statement.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBatch.OptionsThe options of a BATCH statement.
-
Field Summary
-
Fields inherited from class com.datastax.driver.core.Statement
idempotent, NULL_PAYLOAD_VALUE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Batchadd(RegularStatement statement)Adds a new statement to this batch.StringgetKeyspace()Returns the keyspace of the first statement in this batch.ByteBuffergetRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)Returns the first non-null routing key of the statements in this batch or null otherwise.ByteBuffer[]getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)The positional values to use for this statement.BooleanisIdempotent()Whether this statement is idempotent, i.e. whether it can be applied multiple times without changing the result beyond the initial application.Batch.Optionsusing(Using using)Adds a new options for this BATCH statement.-
Methods inherited from class com.datastax.driver.core.querybuilder.BuiltStatement
escapeId, getNamedValues, getObject, getObject, getQueryString, hasValues, setForceNoValues, toString, usesNamedValues
-
Methods inherited from class com.datastax.driver.core.RegularStatement
getQueryString, hasValues, requestSizeInBytes
-
Methods inherited from class com.datastax.driver.core.Statement
disableTracing, enableTracing, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getHost, getLastHost, getNowInSeconds, getOutgoingPayload, getPartitioner, getReadTimeoutMillis, getRetryPolicy, getSerialConsistencyLevel, isBatchIdempotent, isLWT, isTracing, setConsistencyLevel, setDefaultTimestamp, setFetchSize, setHost, setIdempotent, setLastHost, setNowInSeconds, setOutgoingPayload, setPagingState, setPagingState, setPagingStateUnsafe, setReadTimeoutMillis, setRetryPolicy, setSerialConsistencyLevel
-
-
-
-
Method Detail
-
add
public Batch add(RegularStatement statement)
Adds a new statement to this batch.- Parameters:
statement- the new statement to add.- Returns:
- this batch.
- Throws:
IllegalArgumentException- if counter and non-counter operations are mixed.
-
getValues
public ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
Description copied from class:RegularStatementThe positional values to use for this statement.A statement can use either positional or named values, but not both. So if this method returns a non-null result,
RegularStatement.getNamedValues(ProtocolVersion, CodecRegistry)will returnnull.Values for a RegularStatement (i.e. if either method does not return
null) are not supported with the native protocol version 1: you will get anUnsupportedProtocolVersionExceptionwhen submitting one if version 1 of the protocol is in use (i.e. if you've forced version 1 throughCluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)or you use Cassandra 1.2).- Overrides:
getValuesin classBuiltStatement- Parameters:
protocolVersion- the protocol version that will be used to serialize the values.codecRegistry- the codec registry that will be used to serialize the values.- See Also:
SimpleStatement(String, Object...)
-
using
public Batch.Options using(Using using)
Adds a new options for this BATCH statement.- Parameters:
using- the option to add.- Returns:
- the options of this BATCH statement.
-
getRoutingKey
public ByteBuffer getRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
Returns the first non-null routing key of the statements in this batch or null otherwise.- Overrides:
getRoutingKeyin classBuiltStatement- Parameters:
protocolVersion- the protocol version that will be used if the actual implementation needs to serialize something to compute the key.codecRegistry- the codec registry that will be used if the actual implementation needs to serialize something to compute this key.- Returns:
- the routing key for this batch statement.
-
getKeyspace
public String getKeyspace()
Returns the keyspace of the first statement in this batch.- Overrides:
getKeyspacein classBuiltStatement- Returns:
- the keyspace of the first statement in this batch.
-
isIdempotent
public Boolean isIdempotent()
Description copied from class:StatementWhether this statement is idempotent, i.e. whether it can be applied multiple times without changing the result beyond the initial application.If a statement is not idempotent, the driver will ensure that it never gets executed more than once, which means:
- avoiding
retrieson write timeouts or request errors; - never scheduling
speculative executions.
Note that this method can return
null, in which case the driver will default toQueryOptions.getDefaultIdempotence().By default, this method returns
nullfor all statements, except forBuiltStatement- value will be inferred from the query: if it updates counters, prepends/appends to a list, or uses a function call orQueryBuilder.raw(String)anywhere in an inserted value, the result will befalse; otherwise it will betrue.BatchandBatchStatement:- If any statement in batch has isIdempotent() false - return false
- If no statements with isIdempotent() false, but some have isIdempotent() null - return null
- Otherwise - return true
Statement.setIdempotent(boolean)forces a value that overrides calculated value.Note that when a statement is prepared (
Session.prepare(String)), its idempotence flag will be propagated to allPreparedStatements created from it.- Overrides:
isIdempotentin classBuiltStatement- Returns:
- whether this statement is idempotent, or
nullto useQueryOptions.getDefaultIdempotence().
- avoiding
-
-