Interface Statement<SelfT extends Statement<SelfT>>
-
- Type Parameters:
SelfT- the "self type" used for covariant returns in subtypes.
- All Superinterfaces:
Request
- All Known Subinterfaces:
BatchableStatement<SelfT>,BatchStatement,BoundStatement,SimpleStatement
public interface Statement<SelfT extends Statement<SelfT>> extends Request
A request to execute a CQL query.
-
-
Field Summary
Fields Modifier and Type Field Description static GenericType<CompletionStage<AsyncResultSet>>ASYNCThe type returned when a CQL statement is executed asynchronously.static longNO_DEFAULT_TIMESTAMPA special value forgetQueryTimestamp()that means "no value".static intNO_NOW_IN_SECONDSA special value forgetNowInSeconds()that means "no value".static GenericType<ResultSet>SYNCThe type returned when a CQL statement is executed synchronously.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description intcomputeSizeInBytes(DriverContext context)Calculates the approximate size in bytes that the statement will have when encoded.default SelfTcopy(ByteBuffer newPagingState)Creates a new instance with a different paging state.default SelfTdisableTracing()Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetTracing(false).default SelfTenableTracing()Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetTracing(true).ConsistencyLevelgetConsistencyLevel()Returns theConsistencyLevelto use for the statement.default longgetDefaultTimestamp()Deprecated.this method only exists to ease the transition from driver 3, it is an alias forgetQueryTimestamp().default intgetFetchSize()Deprecated.this method only exists to ease the transition from driver 3, it is an alias forgetPageSize().default intgetNowInSeconds()A custom "now in seconds" to use when applying the request (for testing purposes).intgetPageSize()Returns the page size to use for the statement.ByteBuffergetPagingState()Returns the paging state to send with the statement, ornullif this statement has no paging state.longgetQueryTimestamp()Returns the query timestamp, in microseconds, to send with the statement.ConsistencyLevelgetSerialConsistencyLevel()Returns the serialConsistencyLevelto use for the statement.default booleanisLWT()Informs if this is a prepared LWT query.booleanisTracing()Whether tracing information should be recorded for this statement.SelfTsetConsistencyLevel(ConsistencyLevel newConsistencyLevel)Sets theConsistencyLevelto use for this statement.SelfTsetCustomPayload(Map<String,ByteBuffer> newCustomPayload)Sets the custom payload to use for execution.default SelfTsetDefaultTimestamp(long newTimestamp)Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetQueryTimestamp(long).SelfTsetExecutionProfile(DriverExecutionProfile newProfile)Sets the execution profile to use for this statement.SelfTsetExecutionProfileName(String newConfigProfileName)Sets the name of the execution profile that will be used for this statement.default SelfTsetFetchSize(int newPageSize)Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetPageSize(int).SelfTsetIdempotent(Boolean newIdempotence)Sets the idempotence to use for execution.SelfTsetNode(Node node)Sets theNodethat should handle this query.default SelfTsetNowInSeconds(int nowInSeconds)Sets the "now in seconds" to use when applying the request (for testing purposes).SelfTsetPageSize(int newPageSize)Configures how many rows will be retrieved simultaneously in a single network roundtrip (the goal being to avoid loading too many results in memory at the same time).default SelfTsetPagingState(PagingState newPagingState)Sets the paging state to send with the statement, ornullif this statement has no paging state.default SelfTsetPagingState(PagingState newPagingState, Session session)Alternative tosetPagingState(PagingState)that specifies the session the statement will be executed with.SelfTsetPagingState(ByteBuffer newPagingState)Sets the paging state to send with the statement, ornullif this statement has no paging state.SelfTsetQueryTimestamp(long newTimestamp)Sets the query timestamp, in microseconds, to send with the statement.default SelfTsetRequestRoutingType(RequestRoutingType requestRoutingType)Sets the request routing type to use when applying the request (for testing purposes).SelfTsetRoutingKey(ByteBuffer newRoutingKey)Sets the key to use for token-aware routing.default SelfTsetRoutingKey(ByteBuffer... newRoutingKeyComponents)Sets the key to use for token-aware routing, when the partition key has multiple components.SelfTsetRoutingKeyspace(CqlIdentifier newRoutingKeyspace)Sets the keyspace to use for token-aware routing.default SelfTsetRoutingKeyspace(String newRoutingKeyspaceName)SelfTsetRoutingToken(Token newRoutingToken)Sets the token to use for token-aware routing.SelfTsetSerialConsistencyLevel(ConsistencyLevel newSerialConsistencyLevel)Sets the serialConsistencyLevelto use for this statement.SelfTsetTimeout(Duration newTimeout)Sets how long to wait for this request to complete.SelfTsetTracing(boolean newTracing)Sets tracing for execution.-
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
-
-
-
-
Field Detail
-
SYNC
static final GenericType<ResultSet> SYNC
The type returned when a CQL statement is executed synchronously.Most users won't use this explicitly. It is needed for the generic execute method (
Session.execute(Request, GenericType)), but CQL statements will generally be run with one of the driver's built-in helper methods (such asSyncCqlSession.execute(Statement)).
-
ASYNC
static final GenericType<CompletionStage<AsyncResultSet>> ASYNC
The type returned when a CQL statement is executed asynchronously.Most users won't use this explicitly. It is needed for the generic execute method (
Session.execute(Request, GenericType)), but CQL statements will generally be run with one of the driver's built-in helper methods (such asAsyncCqlSession.executeAsync(Statement)).
-
NO_DEFAULT_TIMESTAMP
static final long NO_DEFAULT_TIMESTAMP
A special value forgetQueryTimestamp()that means "no value".It is equal to
Long.MIN_VALUE.- See Also:
- Constant Field Values
-
NO_NOW_IN_SECONDS
static final int NO_NOW_IN_SECONDS
A special value forgetNowInSeconds()that means "no value".It is equal to
Integer.MIN_VALUE.- See Also:
- Constant Field Values
-
-
Method Detail
-
setExecutionProfileName
@NonNull @CheckReturnValue SelfT setExecutionProfileName(@Nullable String newConfigProfileName)
Sets the name of the execution profile that will be used for this statement.For all the driver's built-in implementations, calling this method with a non-null argument automatically resets
Request.getExecutionProfile()to null.All the driver's built-in implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
setExecutionProfile
@NonNull @CheckReturnValue SelfT setExecutionProfile(@Nullable DriverExecutionProfile newProfile)
Sets the execution profile to use for this statement.For all the driver's built-in implementations, calling this method with a non-null argument automatically resets
Request.getExecutionProfileName()to null.All the driver's built-in implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
setRoutingKeyspace
@NonNull @CheckReturnValue SelfT setRoutingKeyspace(@Nullable CqlIdentifier newRoutingKeyspace)
Sets the keyspace to use for token-aware routing.See
Request.getRoutingKey()for a description of the token-aware routing algorithm.- Parameters:
newRoutingKeyspace- The keyspace to use, ornullto disable token-aware routing.
-
setNode
@NonNull @CheckReturnValue SelfT setNode(@Nullable Node node)
Sets theNodethat should handle this query.In the general case, use of this method is heavily discouraged and should only be used in the following cases:
- Querying node-local tables, such as tables in the
systemandsystem_viewskeyspaces. - Applying a series of schema changes, where it may be advantageous to execute schema changes in sequence on the same node.
Configuring a specific node causes the configured
LoadBalancingPolicyto be completely bypassed. However, if the load balancing policy dictates that the node is at distanceNodeDistance.IGNOREDor there is no active connectivity to the node, the request will fail with aNoNodeAvailableException.- Parameters:
node- The node that should be used to handle executions of this statement or null to delegate to the configured load balancing policy.
- Querying node-local tables, such as tables in the
-
setRoutingKeyspace
@NonNull @CheckReturnValue default SelfT setRoutingKeyspace(@Nullable String newRoutingKeyspaceName)
- Parameters:
newRoutingKeyspaceName- The keyspace to use, ornullto disable token-aware routing.
-
setRoutingKey
@NonNull @CheckReturnValue SelfT setRoutingKey(@Nullable ByteBuffer newRoutingKey)
Sets the key to use for token-aware routing.See
Request.getRoutingKey()for a description of the token-aware routing algorithm.- Parameters:
newRoutingKey- The routing key to use, ornullto disable token-aware routing.
-
setRoutingKey
@NonNull @CheckReturnValue default SelfT setRoutingKey(@NonNull ByteBuffer... newRoutingKeyComponents)
Sets the key to use for token-aware routing, when the partition key has multiple components.This method assembles the components into a single byte buffer and passes it to
setRoutingKey(ByteBuffer). Neither the individual components, nor the vararg array itself, can benull.
-
setRoutingToken
@NonNull @CheckReturnValue SelfT setRoutingToken(@Nullable Token newRoutingToken)
Sets the token to use for token-aware routing.See
Request.getRoutingKey()for a description of the token-aware routing algorithm.- Parameters:
newRoutingToken- The routing token to use, ornullto disable token-aware routing.
-
setCustomPayload
@NonNull @CheckReturnValue SelfT setCustomPayload(@NonNull Map<String,ByteBuffer> newCustomPayload)
Sets the custom payload to use for execution.All the driver's built-in statement implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
Note that it's your responsibility to provide a thread-safe map. This can be achieved with a concurrent or immutable implementation, or by making it effectively immutable (meaning that it's never modified after being set on the statement).
-
setIdempotent
@NonNull @CheckReturnValue SelfT setIdempotent(@Nullable Boolean newIdempotence)
Sets the idempotence to use for execution.All the driver's built-in implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
- Parameters:
newIdempotence- a boolean instance to set a statement-specific value, ornullto use the default idempotence defined in the configuration.
-
setTracing
@NonNull @CheckReturnValue SelfT setTracing(boolean newTracing)
Sets tracing for execution.All the driver's built-in implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
-
enableTracing
@Deprecated @NonNull @CheckReturnValue default SelfT enableTracing()
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetTracing(true).
-
disableTracing
@Deprecated @NonNull @CheckReturnValue default SelfT disableTracing()
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetTracing(false).
-
getQueryTimestamp
long getQueryTimestamp()
Returns the query timestamp, in microseconds, to send with the statement. SeesetQueryTimestamp(long)for details.If this is equal to
NO_DEFAULT_TIMESTAMP, theTimestampGeneratorconfigured for this driver instance will be used to generate a timestamp.- See Also:
NO_DEFAULT_TIMESTAMP,TimestampGenerator
-
getDefaultTimestamp
@Deprecated default long getDefaultTimestamp()
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forgetQueryTimestamp().
-
setQueryTimestamp
@NonNull @CheckReturnValue SelfT setQueryTimestamp(long newTimestamp)
Sets the query timestamp, in microseconds, to send with the statement.This is an alternative to appending a
USING TIMESTAMPclause in the statement's query string, and has the advantage of sending the timestamp separately from the query string itself, which doesn't have to be modified when executing the same statement with different timestamps. Note that, if both aUSING TIMESTAMPclause and a query timestamp are set for a given statement, the timestamp from theUSING TIMESTAMPclause wins.This method can be used on any instance of
SimpleStatement,BoundStatementorBatchStatement. For aBatchStatement, the timestamp will apply to all its child statements; it is not possible to define per-child timestamps using this method, and consequently, if this method is called on a batch child statement, the provided timestamp will be silently ignored. If different timestamps are required for individual child statements, this can only be achieved with a customUSING TIMESTAMPclause in each child query.If this is equal to
NO_DEFAULT_TIMESTAMP, theTimestampGeneratorconfigured for this driver instance will be used to generate a timestamp.All the driver's built-in implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance.
- See Also:
NO_DEFAULT_TIMESTAMP,TimestampGenerator
-
setDefaultTimestamp
@Deprecated @NonNull @CheckReturnValue default SelfT setDefaultTimestamp(long newTimestamp)
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetQueryTimestamp(long).
-
setTimeout
@NonNull @CheckReturnValue SelfT setTimeout(@Nullable Duration newTimeout)
Sets how long to wait for this request to complete. This is a global limit on the duration of a session.execute() call, including any retries the driver might do.- Parameters:
newTimeout- the timeout to use, ornullto use the default value defined in the configuration.- See Also:
DefaultDriverOption.REQUEST_TIMEOUT
-
getPagingState
@Nullable ByteBuffer getPagingState()
Returns the paging state to send with the statement, ornullif this statement has no paging state.Paging states are used in scenarios where a paged result is interrupted then resumed later. The paging state can only be reused with the exact same statement (same query string, same parameters). It is an opaque value that is only meant to be collected, stored and re-used. If you try to modify its contents or reuse it with a different statement, the results are unpredictable.
-
setPagingState
@NonNull @CheckReturnValue SelfT setPagingState(@Nullable ByteBuffer newPagingState)
Sets the paging state to send with the statement, ornullif this statement has no paging state.Paging states are used in scenarios where a paged result is interrupted then resumed later. The paging state can only be reused with the exact same statement (same query string, same parameters). It is an opaque value that is only meant to be collected, stored and re-used. If you try to modify its contents or reuse it with a different statement, the results are unpredictable.
All the driver's built-in implementations are immutable, and return a new instance from this method. However custom implementations may choose to be mutable and return the same instance; if you do so, you must override
copy(ByteBuffer).
-
setPagingState
@NonNull @CheckReturnValue default SelfT setPagingState(@Nullable PagingState newPagingState)
Sets the paging state to send with the statement, ornullif this statement has no paging state.This variant uses the "safe" paging state wrapper, it will throw immediately if the statement doesn't match the one that the state was initially extracted from (same query string, same parameters). The advantage is that it fails fast, instead of waiting for an error response from the server.
Note that, if this statement is a
SimpleStatementwith bound values, those values must be encoded in order to perform the check. This method uses the default codec registry and default protocol version. This might fail if you use custom codecs; in that case, usesetPagingState(PagingState, Session)instead.- Throws:
IllegalArgumentException- if the given state does not match this statement.- See Also:
setPagingState(ByteBuffer),ExecutionInfo.getSafePagingState()
-
setPagingState
@NonNull @CheckReturnValue default SelfT setPagingState(@Nullable PagingState newPagingState, @Nullable Session session)
Alternative tosetPagingState(PagingState)that specifies the session the statement will be executed with. You only need this for simple statements, and if you use custom codecs. Bound statements already know which session they are attached to.
-
getPageSize
int getPageSize()
Returns the page size to use for the statement.- Returns:
- the set page size, otherwise 0 or a negative value to use the default value defined in the configuration.
- See Also:
DefaultDriverOption.REQUEST_PAGE_SIZE
-
getFetchSize
@Deprecated default int getFetchSize()
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forgetPageSize().
-
setPageSize
@NonNull @CheckReturnValue SelfT setPageSize(int newPageSize)
Configures how many rows will be retrieved simultaneously in a single network roundtrip (the goal being to avoid loading too many results in memory at the same time).- Parameters:
newPageSize- the page size to use, set to 0 or a negative value to use the default value defined in the configuration.- See Also:
DefaultDriverOption.REQUEST_PAGE_SIZE
-
setFetchSize
@Deprecated @NonNull @CheckReturnValue default SelfT setFetchSize(int newPageSize)
Deprecated.this method only exists to ease the transition from driver 3, it is an alias forsetPageSize(int).
-
getConsistencyLevel
@Nullable ConsistencyLevel getConsistencyLevel()
Returns theConsistencyLevelto use for the statement.- Returns:
- the set consistency, or
nullto use the default value defined in the configuration. - See Also:
DefaultDriverOption.REQUEST_CONSISTENCY
-
setConsistencyLevel
@NonNull @CheckReturnValue SelfT setConsistencyLevel(@Nullable ConsistencyLevel newConsistencyLevel)
Sets theConsistencyLevelto use for this statement.- Parameters:
newConsistencyLevel- the consistency level to use, or null to use the default value defined in the configuration.- See Also:
DefaultDriverOption.REQUEST_CONSISTENCY
-
getSerialConsistencyLevel
@Nullable ConsistencyLevel getSerialConsistencyLevel()
Returns the serialConsistencyLevelto use for the statement.- Returns:
- the set serial consistency, or
nullto use the default value defined in the configuration. - See Also:
DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY
-
setSerialConsistencyLevel
@NonNull @CheckReturnValue SelfT setSerialConsistencyLevel(@Nullable ConsistencyLevel newSerialConsistencyLevel)
Sets the serialConsistencyLevelto use for this statement.- Parameters:
newSerialConsistencyLevel- the serial consistency level to use, or null to use the default value defined in the configuration.- See Also:
DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY
-
isTracing
boolean isTracing()
Whether tracing information should be recorded for this statement.
-
getNowInSeconds
default int getNowInSeconds()
A custom "now in seconds" to use when applying the request (for testing purposes).This method's default implementation returns
NO_NOW_IN_SECONDS. The only reason it exists is to preserve binary compatibility. Internally, the driver overrides it to return the value that was set programmatically (if any).- See Also:
NO_NOW_IN_SECONDS
-
setNowInSeconds
@NonNull @CheckReturnValue default SelfT setNowInSeconds(int nowInSeconds)
Sets the "now in seconds" to use when applying the request (for testing purposes).This method's default implementation returns the statement unchanged. The only reason it exists is to preserve binary compatibility. Internally, the driver overrides it to record the new value.
- See Also:
NO_NOW_IN_SECONDS
-
setRequestRoutingType
@NonNull @CheckReturnValue default SelfT setRequestRoutingType(@Nullable RequestRoutingType requestRoutingType)
Sets the request routing type to use when applying the request (for testing purposes).This method's default implementation returns the statement unchanged. The only reason it exists is to preserve binary compatibility. Internally, the driver overrides it to record the new value.
-
isLWT
default boolean isLWT()
Informs if this is a prepared LWT query.Not guaranteed to return true for prepared LWT queries (but guaranteed to return false for non-LWT ones). It can happen for several reasons, for example: using Cassandra instead of Scylla, using too old Scylla version, future changes in driver allowing channels to be created without sending OPTIONS request.
Provided implementations of BatchStatements will be considered by driver as LWT if any of the statements in a batch is LWT on its own.
More information about LWT:
- See Also:
- Docs about LWT
-
computeSizeInBytes
int computeSizeInBytes(@NonNull DriverContext context)Calculates 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.
- Returns:
- the approximate number of bytes this statement will take when encoded.
-
copy
@NonNull @CheckReturnValue default SelfT copy(@Nullable ByteBuffer newPagingState)
Creates a new instance with a different paging state.Since all the built-in statement implementations in the driver are immutable, this method's default implementation delegates to
setPagingState(ByteBuffer). However, if you write your own mutable implementation, make sure it returns a different instance.
-
-