com.datastax.driver.core
Class BatchStatement

java.lang.Object
  extended by com.datastax.driver.core.Statement
      extended by com.datastax.driver.core.BatchStatement

public class BatchStatement
extends Statement

A statement that group a number of Statement so they get executed as a batch.


Nested Class Summary
static class BatchStatement.Type
          The type of batch to use.
 
Constructor Summary
BatchStatement()
          Creates a new LOGGED batch statement.
BatchStatement(BatchStatement.Type batchType)
          Creates a new batch statement of the provided type.
 
Method Summary
 BatchStatement add(Statement statement)
          Adds a new statement to this batch.
 BatchStatement addAll(Iterable<? extends Statement> statements)
          Adds multiple statements to this batch.
 String getKeyspace()
          Returns the keyspace this query operates on.
 ByteBuffer getRoutingKey()
          Returns the routing key (in binary raw form) to use for token aware routing of this query.
 
Methods inherited from class com.datastax.driver.core.Statement
disableTracing, enableTracing, getConsistencyLevel, getFetchSize, getRetryPolicy, getSerialConsistencyLevel, isTracing, setConsistencyLevel, setFetchSize, setRetryPolicy, setSerialConsistencyLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BatchStatement

public BatchStatement()
Creates a new LOGGED batch statement.


BatchStatement

public BatchStatement(BatchStatement.Type batchType)
Creates a new batch statement of the provided type.

Parameters:
batchType - the type of batch.
Method Detail

add

public BatchStatement add(Statement statement)
Adds a new statement to this batch.

Note that statement can be any Statement. It is allowed to mix RegularStatement and BoundStatement in the same BatchStatement in particular. Adding another BatchStatement is also allowed for convenient and is equivalent to adding all the Statement contained in that other BatchStatement.

Please note that the options of the added Statement (all those defined directly by the Statement class: consistency level, fetch size, tracing, ...) will be ignored for the purpose of the execution of the Batch. Instead, the options used are the one of this BatchStatement object.

Parameters:
statement - the new statement to add.
Returns:
this batch statement.

addAll

public BatchStatement addAll(Iterable<? extends Statement> statements)
Adds multiple statements to this batch.

This is a shortcut method that calls add(com.datastax.driver.core.Statement) on all the statements from statements.

Parameters:
statements - the statements to add.
Returns:
this batch statement.

getRoutingKey

public ByteBuffer getRoutingKey()
Description copied from class: Statement
Returns the routing key (in binary raw form) to use for token aware routing of this query.

The routing key is optional in that implementers are free to return null. The routing key is an hint used for token-aware routing (see TokenAwarePolicy), and if provided should correspond to the binary value for the query partition key. However, not providing a routing key never causes a query to fail and if the load balancing policy used is not token aware, then the routing key can be safely ignored.

Specified by:
getRoutingKey in class Statement
Returns:
the routing key for this query or null.

getKeyspace

public String getKeyspace()
Description copied from class: Statement
Returns the keyspace this query operates on.

Note that not all query specify on which keyspace they operate on, and so this method can always reutrn null. Firstly, some queries do not operate inside a keyspace: keyspace creation, USE queries, user creation, etc. Secondly, even query that operate within a keyspace do not have to specify said keyspace directly, in which case the currently logged in keyspace (the one set through a USE query (or through the use of Cluster.connect(String))). Lastly, as for the routing key, this keyspace information is only a hint for token-aware routing (since replica placement depend on the replication strategy in use which is a per-keyspace property) and having this method return null (or even a bogus keyspace name) will never cause the query to fail.

Specified by:
getKeyspace in class Statement
Returns:
the keyspace this query operate on if relevant or null.


Copyright © 2013. All rights reserved.