Class DefaultPreparedStatement
- java.lang.Object
-
- com.datastax.driver.core.DefaultPreparedStatement
-
- All Implemented Interfaces:
PreparedStatement
public class DefaultPreparedStatement extends Object implements PreparedStatement
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BoundStatementbind()Creates a new BoundStatement object for this prepared statement.BoundStatementbind(Object... values)Creates a new BoundStatement object and bind its variables to the provided values.PreparedStatementdisableTracing()Convenience method to disable tracing for all bound statements created from this prepared statement.PreparedStatementenableTracing()Convenience method to enables tracing for all bound statements created from this prepared statement.CodecRegistrygetCodecRegistry()Return theCodecRegistryinstance associated with this prepared statement.ConsistencyLevelgetConsistencyLevel()Returns the default consistency level set throughPreparedStatement.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel).Map<String,ByteBuffer>getIncomingPayload()Return the incoming payload, that is, the payload that the server sent back with itsPREPAREDresponse, if any, ornull, if the server did not include any custom payload.Map<String,ByteBuffer>getOutgoingPayload()Return the outgoing payload currently associated with this statement.com.datastax.driver.core.Token.FactorygetPartitioner()The partitioner for this prepared statement.PreparedIdgetPreparedId()Returns the prepared Id for this statement.StringgetQueryKeyspace()Returns the keyspace at the time that this prepared statement was prepared, (that is the one on which this statement applies unless it specified a keyspace explicitly).StringgetQueryString()Returns the string of the query that was prepared to yield thisPreparedStatement.RetryPolicygetRetryPolicy()Returns the retry policy sets for this prepared statement, if any.ByteBuffergetRoutingKey()Returns the routing key set for this query.ConsistencyLevelgetSerialConsistencyLevel()Returns the default serial consistency level set throughPreparedStatement.setSerialConsistencyLevel(com.datastax.driver.core.ConsistencyLevel).ColumnDefinitionsgetVariables()Returns metadata on the bounded variables of this prepared statement.BooleanisIdempotent()Whether this statement is idempotent, i.e. whether it can be applied multiple times without changing the result beyond the initial application.booleanisLWT()Whether a prepared statement is LWT statementbooleanisSkipMetadata()booleanisTracing()Returns whether tracing is enabled for this prepared statement, i.e. if BoundStatement created from it will use tracing by default.PreparedStatementsetConsistencyLevel(ConsistencyLevel consistency)Sets a default consistency level for all bound statements created from this prepared statement.PreparedStatementsetIdempotent(Boolean idempotent)Sets whether this statement is idempotent.PreparedStatementsetOutgoingPayload(Map<String,ByteBuffer> payload)Associate the given payload with this prepared statement.PreparedStatementsetRetryPolicy(RetryPolicy policy)Convenience method to set a default retry policy for theBoundStatementcreated from this prepared statement.PreparedStatementsetRoutingKey(ByteBuffer routingKey)Sets the routing key for this prepared statement.PreparedStatementsetRoutingKey(ByteBuffer... routingKeyComponents)Sets the routing key for this query.PreparedStatementsetSerialConsistencyLevel(ConsistencyLevel serialConsistency)Sets a default serial consistency level for all bound statements created from this prepared statement.
-
-
-
Method Detail
-
isSkipMetadata
public boolean isSkipMetadata()
-
getVariables
public ColumnDefinitions getVariables()
Description copied from interface:PreparedStatementReturns metadata on the bounded variables of this prepared statement.- Specified by:
getVariablesin interfacePreparedStatement- Returns:
- the variables bounded in this prepared statement.
-
bind
public BoundStatement bind(Object... values)
Description copied from interface:PreparedStatementCreates a new BoundStatement object and bind its variables to the provided values.While the number of
valuescannot be greater than the number of bound variables, the number ofvaluesmay be fewer than the number of bound variables. In that case, the remaining variables will have to be bound to values by another mean because the resultingBoundStatementbeing executable.This method is a convenience for
new BoundStatement(this).bind(...).- Specified by:
bindin interfacePreparedStatement- Parameters:
values- the values to bind to the variables of the newly created BoundStatement.- Returns:
- the newly created
BoundStatementwith its variables bound tovalues. - See Also:
BoundStatement.bind(java.lang.Object...)
-
bind
public BoundStatement bind()
Description copied from interface:PreparedStatementCreates a new BoundStatement object for this prepared statement.This method do not bind any values to any of the prepared variables. Said values need to be bound on the resulting statement using BoundStatement's setters methods (
BoundStatement.setInt(int, int),BoundStatement.setLong(int, long), ...).- Specified by:
bindin interfacePreparedStatement- Returns:
- the newly created
BoundStatement.
-
setRoutingKey
public PreparedStatement setRoutingKey(ByteBuffer routingKey)
Description copied from interface:PreparedStatementSets the routing key for this prepared statement.While you can provide a fixed routing key for all executions of this prepared statement with this method, it is not mandatory to provide one through this method. This method should only be used if the partition key of the prepared query is not part of the prepared variables (that is if the partition key is fixed).
Note that if the partition key is part of the prepared variables, the routing key will be automatically computed once those variables are bound.
If the partition key is neither fixed nor part of the prepared variables (e.g. a composite partition key where only some of the components are bound), the routing key can also be set on each bound statement.
- Specified by:
setRoutingKeyin interfacePreparedStatement- Parameters:
routingKey- the raw (binary) value to use as routing key.- Returns:
- this
PreparedStatementobject. - See Also:
Statement.getRoutingKey(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry),BoundStatement.getRoutingKey(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)
-
setRoutingKey
public PreparedStatement setRoutingKey(ByteBuffer... routingKeyComponents)
Description copied from interface:PreparedStatementSets the routing key for this query.See
PreparedStatement.setRoutingKey(ByteBuffer)for more information. This method is a variant for when the query partition key is composite and the routing key must be built from multiple values.- Specified by:
setRoutingKeyin interfacePreparedStatement- Parameters:
routingKeyComponents- the raw (binary) values to compose to obtain the routing key.- Returns:
- this
PreparedStatementobject. - See Also:
Statement.getRoutingKey(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)
-
getRoutingKey
public ByteBuffer getRoutingKey()
Description copied from interface:PreparedStatementReturns the routing key set for this query.- Specified by:
getRoutingKeyin interfacePreparedStatement- Returns:
- the routing key for this query or
nullif none has been explicitly set on this PreparedStatement.
-
setConsistencyLevel
public PreparedStatement setConsistencyLevel(ConsistencyLevel consistency)
Description copied from interface:PreparedStatementSets a default consistency level for all bound statements created from this prepared statement.If no consistency level is set through this method, the bound statement created from this object will use the default consistency level (LOCAL_ONE).
Changing the default consistency level is not retroactive, it only applies to BoundStatement created after the change.
- Specified by:
setConsistencyLevelin interfacePreparedStatement- Parameters:
consistency- the default consistency level to set.- Returns:
- this
PreparedStatementobject.
-
getConsistencyLevel
public ConsistencyLevel getConsistencyLevel()
Description copied from interface:PreparedStatementReturns the default consistency level set throughPreparedStatement.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel).- Specified by:
getConsistencyLevelin interfacePreparedStatement- Returns:
- the default consistency level. Returns
nullif no consistency level has been set through this objectsetConsistencyLevelmethod.
-
setSerialConsistencyLevel
public PreparedStatement setSerialConsistencyLevel(ConsistencyLevel serialConsistency)
Description copied from interface:PreparedStatementSets a default serial consistency level for all bound statements created from this prepared statement.If no serial consistency level is set through this method, the bound statement created from this object will use the default serial consistency level (SERIAL).
Changing the default serial consistency level is not retroactive, it only applies to BoundStatement created after the change.
- Specified by:
setSerialConsistencyLevelin interfacePreparedStatement- Parameters:
serialConsistency- the default serial consistency level to set.- Returns:
- this
PreparedStatementobject.
-
getSerialConsistencyLevel
public ConsistencyLevel getSerialConsistencyLevel()
Description copied from interface:PreparedStatementReturns the default serial consistency level set throughPreparedStatement.setSerialConsistencyLevel(com.datastax.driver.core.ConsistencyLevel).- Specified by:
getSerialConsistencyLevelin interfacePreparedStatement- Returns:
- the default serial consistency level. Returns
nullif no consistency level has been set through this objectsetSerialConsistencyLevelmethod.
-
getQueryString
public String getQueryString()
Description copied from interface:PreparedStatementReturns the string of the query that was prepared to yield thisPreparedStatement.Note that a CQL3 query may be implicitly applied to the current keyspace (that is, if the keyspace is not explicitly qualified in the query itself). For prepared queries, the current keyspace used is the one at the time of the preparation, not the one at execution time. The current keyspace at the time of the preparation can be retrieved through
PreparedStatement.getQueryKeyspace().- Specified by:
getQueryStringin interfacePreparedStatement- Returns:
- the query that was prepared to yield this
PreparedStatement.
-
getQueryKeyspace
public String getQueryKeyspace()
Description copied from interface:PreparedStatementReturns the keyspace at the time that this prepared statement was prepared, (that is the one on which this statement applies unless it specified a keyspace explicitly).- Specified by:
getQueryKeyspacein interfacePreparedStatement- Returns:
- the keyspace at the time that this statement was prepared or
nullif no keyspace was set when the query was prepared (which is possible since keyspaces can be explicitly qualified in queries and so may not require a current keyspace to be set).
-
enableTracing
public PreparedStatement enableTracing()
Description copied from interface:PreparedStatementConvenience method to enables tracing for all bound statements created from this prepared statement.- Specified by:
enableTracingin interfacePreparedStatement- Returns:
- this
Queryobject.
-
disableTracing
public PreparedStatement disableTracing()
Description copied from interface:PreparedStatementConvenience method to disable tracing for all bound statements created from this prepared statement.- Specified by:
disableTracingin interfacePreparedStatement- Returns:
- this
PreparedStatementobject.
-
isTracing
public boolean isTracing()
Description copied from interface:PreparedStatementReturns whether tracing is enabled for this prepared statement, i.e. if BoundStatement created from it will use tracing by default.- Specified by:
isTracingin interfacePreparedStatement- Returns:
trueif this prepared statement has tracing enabled,falseotherwise.
-
setRetryPolicy
public PreparedStatement setRetryPolicy(RetryPolicy policy)
Description copied from interface:PreparedStatementConvenience method to set a default retry policy for theBoundStatementcreated from this prepared statement.Note that this method is completely optional. By default, the retry policy used is the one returned
Policies.getRetryPolicy()in the cluster configuration. This method is only useful if you want to override this default policy for theBoundStatementcreated from thisPreparedStatement. to punctually override the default policy for this request.- Specified by:
setRetryPolicyin interfacePreparedStatement- Parameters:
policy- the retry policy to use for this prepared statement.- Returns:
- this
PreparedStatementobject.
-
getRetryPolicy
public RetryPolicy getRetryPolicy()
Description copied from interface:PreparedStatementReturns the retry policy sets for this prepared statement, if any.- Specified by:
getRetryPolicyin interfacePreparedStatement- Returns:
- the retry policy sets specifically for this prepared statement or
nullif none have been set.
-
getPartitioner
public com.datastax.driver.core.Token.Factory getPartitioner()
Description copied from interface:PreparedStatementThe partitioner for this prepared statement.- Specified by:
getPartitionerin interfacePreparedStatement- Returns:
- the partitioner for this query, or
nullif no partitioner has been specified. In the latter case, the cluster-wide partitioner will be used.
-
getPreparedId
public PreparedId getPreparedId()
Description copied from interface:PreparedStatementReturns the prepared Id for this statement.- Specified by:
getPreparedIdin interfacePreparedStatement- Returns:
- the PreparedId corresponding to this statement.
-
getIncomingPayload
public Map<String,ByteBuffer> getIncomingPayload()
Description copied from interface:PreparedStatementReturn the incoming payload, that is, the payload that the server sent back with itsPREPAREDresponse, if any, ornull, if the server did not include any custom payload.Note that if an incoming payload is present, and if no outgoing payload has been
explicitly set, then each time aBoundStatementis created (with eitherPreparedStatement.bind()orPreparedStatement.bind(Object...)), the resultingBoundStatementwill inherit from this value as its default outgoing payload.Implementors should return a read-only view of the original map, but even though, its values would remain inherently mutable. Callers should take care not to modify the returned map in any way.
This feature is only available with
ProtocolVersion.V4or above; with lower versions, this method will always returnnull.- Specified by:
getIncomingPayloadin interfacePreparedStatement- Returns:
- the custom payload that the server sent back with its response, if any, or
null, if the server did not include any custom payload.
-
getOutgoingPayload
public Map<String,ByteBuffer> getOutgoingPayload()
Description copied from interface:PreparedStatementReturn the outgoing payload currently associated with this statement.If this is set to a non-null value, each time a
BoundStatementis created (with eitherPreparedStatement.bind()orPreparedStatement.bind(Object...)), the resultingBoundStatementwill inherit from this value as its default outgoing payload.Implementors should return a read-only view of the original map, but even though, its values would remain inherently mutable. Callers should take care not to modify the returned map in any way.
This feature is only available with
ProtocolVersion.V4or above.- Specified by:
getOutgoingPayloadin interfacePreparedStatement- Returns:
- this statement's outgoing payload, if any, or
nullif no outgoing payload is set
-
setOutgoingPayload
public PreparedStatement setOutgoingPayload(Map<String,ByteBuffer> payload)
Description copied from interface:PreparedStatementAssociate the given payload with this prepared statement.If this is set to a non-null value, each time a
BoundStatementis created (with eitherPreparedStatement.bind()orPreparedStatement.bind(Object...)), the resultingBoundStatementwill inherit from this value as its default outgoing payload.Implementors should make a defensive, thread-safe copy of the given map, but even though, its values would remain inherently mutable. Callers should take care not to modify the original map once it is passed to this method.
This feature is only available with
ProtocolVersion.V4or above. Trying to include custom payloads in requests sent by the driver under lower protocol versions will result in anUnsupportedFeatureException(wrapped in aNoHostAvailableException).- Specified by:
setOutgoingPayloadin interfacePreparedStatement- Parameters:
payload- the outgoing payload to associate with this statement, ornullto clear any previously associated payload.- Returns:
- this
Statementobject.
-
getCodecRegistry
public CodecRegistry getCodecRegistry()
Description copied from interface:PreparedStatementReturn theCodecRegistryinstance associated with this prepared statement. Implementations should never returnnull; instead, they should always return theCodecRegistryinstance registered with theClusterinstance this prepared statement belongs to.- Specified by:
getCodecRegistryin interfacePreparedStatement- Returns:
- the
CodecRegistryinstance associated with this prepared statement.
-
setIdempotent
public PreparedStatement setIdempotent(Boolean idempotent)
Sets whether this statement is idempotent.See
Statement.isIdempotent()for more explanations about this property.- Specified by:
setIdempotentin interfacePreparedStatement- Parameters:
idempotent- the new value.- Returns:
- this
IdempotenceAwarePreparedStatementobject.
-
isIdempotent
public Boolean isIdempotent()
Whether this statement is idempotent, i.e. whether it can be applied multiple times without changing the result beyond the initial application.See
Statement.isIdempotent()for more explanations about this property.Please note that idempotence will be propagated to all
BoundStatements created from this prepared statement.- Specified by:
isIdempotentin interfacePreparedStatement- Returns:
- whether this statement is idempotent, or
nullto useQueryOptions.getDefaultIdempotence().
-
isLWT
public boolean isLWT()
Whether a prepared statement is LWT statement- Specified by:
isLWTin interfacePreparedStatement
-
-