public interface PreparedStatement
Session.execute(java.lang.String)
).
A PreparedStatement
object allows you to define specific defaults
for the different properties of a Statement
(Consistency level, tracing, ...),
in which case those properties will be inherited as default by every
BoundedStatement created from the {PreparedStatement}. The default for those
PreparedStatement
properties is the same that in Statement
if the
PreparedStatement is created by Session.prepare(String)
but will inherit
of the properties of the RegularStatement
used for the preparation if
Session.prepare(RegularStatement)
is used.Modifier and Type | Method and Description |
---|---|
BoundStatement |
bind()
Creates a new BoundStatement object for this prepared statement.
|
BoundStatement |
bind(Object... values)
Creates a new BoundStatement object and bind its variables to the
provided values.
|
PreparedStatement |
disableTracing()
Convenience method to disable tracing for all bound statements created
from this prepared statement.
|
PreparedStatement |
enableTracing()
Convenience method to enables tracing for all bound statements created
from this prepared statement.
|
ConsistencyLevel |
getConsistencyLevel()
Returns the default consistency level set through
setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) . |
PreparedId |
getPreparedId()
Returns the prepared Id for this statement.
|
String |
getQueryKeyspace()
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).
|
String |
getQueryString()
Returns the string of the query that was prepared to yield this
PreparedStatement . |
RetryPolicy |
getRetryPolicy()
Returns the retry policy sets for this prepared statement, if any.
|
ByteBuffer |
getRoutingKey()
Returns the routing key set for this query.
|
ConsistencyLevel |
getSerialConsistencyLevel()
Returns the default serial consistency level set through
setSerialConsistencyLevel(com.datastax.driver.core.ConsistencyLevel) . |
ColumnDefinitions |
getVariables()
Returns metadata on the bounded variables of this prepared statement.
|
boolean |
isTracing()
Returns whether tracing is enabled for this prepared statement, i.e.
|
PreparedStatement |
setConsistencyLevel(ConsistencyLevel consistency)
Sets a default consistency level for all bound statements
created from this prepared statement.
|
PreparedStatement |
setRetryPolicy(RetryPolicy policy)
Convenience method to set a default retry policy for the
BoundStatement
created from this prepared statement. |
PreparedStatement |
setRoutingKey(ByteBuffer... routingKeyComponents)
Sets the routing key for this query.
|
PreparedStatement |
setRoutingKey(ByteBuffer routingKey)
Sets the routing key for this prepared statement.
|
PreparedStatement |
setSerialConsistencyLevel(ConsistencyLevel serialConsistency)
Sets a default serial consistency level for all bound statements
created from this prepared statement.
|
ColumnDefinitions getVariables()
BoundStatement bind(Object... values)
values
cannot be greater than the number of bound
variables, the number of values
may 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 resulting BoundStatement
being executable.
This method is a convenience for new BoundStatement(this).bind(...)
.values
- the values to bind to the variables of the newly created
BoundStatement.BoundStatement
with its variables
bound to values
.IllegalArgumentException
- if more values
are provided
than there is of bound variables in this statement.InvalidTypeException
- if any of the provided value is not of
correct type to be bound to the corresponding bind variable.NullPointerException
- if one of values
is a collection
(List, Set or Map) containing a null value. Nulls are not supported in
collections by CQL.BoundStatement.bind(java.lang.Object...)
BoundStatement bind()
BoundStatement.setInt(int, int)
, BoundStatement.setLong(int, long)
, ...).BoundStatement
.PreparedStatement setRoutingKey(ByteBuffer routingKey)
routingKey
- the raw (binary) value to use as routing key.PreparedStatement
object.Statement.getRoutingKey()
,
BoundStatement.getRoutingKey()
PreparedStatement setRoutingKey(ByteBuffer... routingKeyComponents)
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.routingKeyComponents
- the raw (binary) values to compose to obtain
the routing key.PreparedStatement
object.Statement.getRoutingKey()
ByteBuffer getRoutingKey()
null
if none has been
explicitly set on this PreparedStatement.PreparedStatement setConsistencyLevel(ConsistencyLevel consistency)
consistency
- the default consistency level to set.PreparedStatement
object.ConsistencyLevel getConsistencyLevel()
setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel)
.null
if no
consistency level has been set through this object setConsistencyLevel
method.PreparedStatement setSerialConsistencyLevel(ConsistencyLevel serialConsistency)
serialConsistency
- the default serial consistency level to set.PreparedStatement
object.IllegalArgumentException
- if serialConsistency
is not one of
ConsistencyLevel.SERIAL
or ConsistencyLevel.LOCAL_SERIAL
.ConsistencyLevel getSerialConsistencyLevel()
setSerialConsistencyLevel(com.datastax.driver.core.ConsistencyLevel)
.null
if no
consistency level has been set through this object setSerialConsistencyLevel
method.String getQueryString()
PreparedStatement
.
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
getQueryKeyspace()
.PreparedStatement
.String getQueryKeyspace()
null
if 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).PreparedStatement enableTracing()
Query
object.PreparedStatement disableTracing()
PreparedStatement
object.boolean isTracing()
true
if this prepared statement has tracing enabled,
false
otherwise.PreparedStatement setRetryPolicy(RetryPolicy policy)
BoundStatement
created 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 the BoundStatement
created from
this PreparedStatement
.
to punctually override the default policy for this request.policy
- the retry policy to use for this prepared statement.PreparedStatement
object.RetryPolicy getRetryPolicy()
null
if none have been set.PreparedId getPreparedId()