Class BatchStatement
A statement that groups a number of BoundStatement and / or SimpleStatement so they get executed as a batch.
Implements
Inherited Members
Namespace: Cassandra
Assembly: Cassandra.dll
Syntax
public class BatchStatement : Statement, IStatement
Properties
BatchType
Gets the batch type
Declaration
public BatchType BatchType { get; }
Property Value
Type | Description |
---|---|
BatchType |
IsEmpty
Determines if the batch does not contain any query
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
Keyspace
Returns the keyspace this query operates on.
Note that not all Statement implementations specify on which keyspace they operate on so this method can return null. If null, it will operate on the default keyspace set during initialization (if it was set).
The keyspace returned is used as a hint for token-aware routing.
Declaration
public override string Keyspace { get; }
Property Value
Type | Description |
---|---|
string |
Overrides
Remarks
Consider using a ISession connected to single keyspace using Connect(string).
RoutingKey
Gets the routing key for the query.
Routing key can be provided using the SetRoutingValues(params object[]) method.
Declaration
public override RoutingKey RoutingKey { get; }
Property Value
Type | Description |
---|---|
RoutingKey |
Overrides
Statements
Gets the statements that were added to this batch.
Declaration
public IEnumerable<IStatement> Statements { get; }
Property Value
Type | Description |
---|---|
IEnumerable<IStatement> |
Methods
Add(Statement)
Adds a new statement to this batch.
Note that statement can be any Statement
. It is allowed to mix SimpleStatement and BoundStatement in the same BatchStatement
in particular.
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.
Declaration
public BatchStatement Add(Statement statement)
Parameters
Type | Name | Description |
---|---|---|
Statement | statement | Statement to add to the batch |
Returns
Type | Description |
---|---|
BatchStatement | The Batch statement |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException | Thrown when trying to add more than |
SetBatchType(BatchType)
Sets the BatchType
Declaration
public BatchStatement SetBatchType(BatchType batchType)
Parameters
Type | Name | Description |
---|---|---|
BatchType | batchType |
Returns
Type | Description |
---|---|
BatchStatement |
SetKeyspace(string)
Sets the keyspace this batch operates on. The keyspace should only be set when the statements in this batch apply to a different keyspace to the logged keyspace of the ISession.
Declaration
public BatchStatement SetKeyspace(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The keyspace name. |
Returns
Type | Description |
---|---|
BatchStatement |
SetRoutingKey(params RoutingKey[])
Set the routing key for this query.
This method allows to manually provide a routing key for this query. It is thus optional since the routing key is only an hint for token aware load balancing policy but is never mandatory.
If the partition key for the query is composite, use the
#setRoutingKey(ByteBuffer...) method instead to build the routing key.Declaration
public BatchStatement SetRoutingKey(params RoutingKey[] routingKeyComponents)
Parameters
Type | Name | Description |
---|---|---|
RoutingKey[] | routingKeyComponents | the raw (binary) values to compose to obtain the routing key. |
Returns
Type | Description |
---|---|
BatchStatement | this |
SetRoutingValues(params object[])
Sets the partition key values in order to route the query to the correct replicas.
For simple partition keys, set the partition key value.
For composite partition keys, set the multiple the partition key values in correct order.
Declaration
public BatchStatement SetRoutingValues(params object[] keys)
Parameters
Type | Name | Description |
---|---|---|
object[] | keys |
Returns
Type | Description |
---|---|
BatchStatement |