com.datastax.driver.core
Class DefaultPreparedStatement

java.lang.Object
  extended by com.datastax.driver.core.DefaultPreparedStatement
All Implemented Interfaces:
PreparedStatement

public class DefaultPreparedStatement
extends Object
implements PreparedStatement


Method Summary
 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 PreparedStatement.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.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getVariables

public ColumnDefinitions getVariables()
Description copied from interface: PreparedStatement
Returns metadata on the bounded variables of this prepared statement.

Specified by:
getVariables in interface PreparedStatement
Returns:
the variables bounded in this prepared statement.

bind

public BoundStatement bind(Object... values)
Description copied from interface: PreparedStatement
Creates a new BoundStatement object and bind its variables to the provided values.

While the number of 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(...).

Specified by:
bind in interface PreparedStatement
Parameters:
values - the values to bind to the variables of the newly created BoundStatement.
Returns:
the newly created BoundStatement with its variables bound to values.
See Also:
BoundStatement.bind(java.lang.Object...)

bind

public BoundStatement bind()
Description copied from interface: PreparedStatement
Creates 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:
bind in interface PreparedStatement
Returns:
the newly created BoundStatement.

setRoutingKey

public PreparedStatement setRoutingKey(ByteBuffer routingKey)
Description copied from interface: PreparedStatement
Sets 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.

Specified by:
setRoutingKey in interface PreparedStatement
Parameters:
routingKey - the raw (binary) value to use as routing key.
Returns:
this PreparedStatement object.
See Also:
Statement.getRoutingKey()

setRoutingKey

public PreparedStatement setRoutingKey(ByteBuffer... routingKeyComponents)
Description copied from interface: PreparedStatement
Sets 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:
setRoutingKey in interface PreparedStatement
Parameters:
routingKeyComponents - the raw (binary) values to compose to obtain the routing key.
Returns:
this PreparedStatement object.
See Also:
Statement.getRoutingKey()

getRoutingKey

public ByteBuffer getRoutingKey()
Description copied from interface: PreparedStatement
Returns the routing key set for this query.

Specified by:
getRoutingKey in interface PreparedStatement
Returns:
the routing key for this query or null if none has been explicitely set on this PreparedStatement.

setConsistencyLevel

public PreparedStatement setConsistencyLevel(ConsistencyLevel consistency)
Description copied from interface: PreparedStatement
Sets 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 (ONE).

Changing the default consistency level is not retroactive, it only applies to BoundStatement created after the change.

Specified by:
setConsistencyLevel in interface PreparedStatement
Parameters:
consistency - the default consistency level to set.
Returns:
this PreparedStatement object.

getConsistencyLevel

public ConsistencyLevel getConsistencyLevel()
Description copied from interface: PreparedStatement
Returns the default consistency level set through PreparedStatement.setConsistencyLevel(com.datastax.driver.core.ConsistencyLevel).

Specified by:
getConsistencyLevel in interface PreparedStatement
Returns:
the default consistency level. Returns null if no consistency level has been set through this object setConsistencyLevel method.

getQueryString

public String getQueryString()
Description copied from interface: PreparedStatement
Returns the string of the query that was prepared to yield this 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 PreparedStatement.getQueryKeyspace().

Specified by:
getQueryString in interface PreparedStatement
Returns:
the query that was prepared to yield this PreparedStatement.

getQueryKeyspace

public String getQueryKeyspace()
Description copied from interface: PreparedStatement
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).

Specified by:
getQueryKeyspace in interface PreparedStatement
Returns:
the keyspace at the time that this statement was prepared or 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).

enableTracing

public PreparedStatement enableTracing()
Description copied from interface: PreparedStatement
Convenience method to enables tracing for all bound statements created from this prepared statement.

Specified by:
enableTracing in interface PreparedStatement
Returns:
this Query object.

disableTracing

public PreparedStatement disableTracing()
Description copied from interface: PreparedStatement
Convenience method to disable tracing for all bound statements created from this prepared statement.

Specified by:
disableTracing in interface PreparedStatement
Returns:
this PreparedStatement object.

isTracing

public boolean isTracing()
Description copied from interface: PreparedStatement
Returns whether tracing is enabled for this prepared statement, i.e. if BoundStatement created from it will use tracing by default.

Specified by:
isTracing in interface PreparedStatement
Returns:
true if this prepared statement has tracing enabled, false otherwise.

setRetryPolicy

public PreparedStatement setRetryPolicy(RetryPolicy policy)
Description copied from interface: PreparedStatement
Convenience method to set a default retry policy for the BoundStatement created from this prepared statement.

Note that this method is competely 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.

Specified by:
setRetryPolicy in interface PreparedStatement
Parameters:
policy - the retry policy to use for this prepared statement.
Returns:
this PreparedStatement object.

getRetryPolicy

public RetryPolicy getRetryPolicy()
Description copied from interface: PreparedStatement
Returns the retry policy sets for this prepared statement, if any.

Specified by:
getRetryPolicy in interface PreparedStatement
Returns:
the retry policy sets specifically for this prepared statement or null if none have been set.

getPreparedId

public PreparedId getPreparedId()
Description copied from interface: PreparedStatement
Returns the prepared Id for this statement.

Specified by:
getPreparedId in interface PreparedStatement
Returns:
the PreparedId corresponding to this statement.


Copyright © 2014. All rights reserved.