class Cassandra::Statements::Batch
Batch
statement groups several {Cassandra::Statement}. There are several
types of Batch statements available:
@see Cassandra::Session#batch
@see Cassandra::Session#logged_batch
@see Cassandra::Session#unlogged_batch
@see Cassandra::Session#counter_batch
Attributes
@private
Public Class Methods
@private
# File lib/cassandra/statements/batch.rb 62 def initialize(options) 63 @options = options 64 @statements = [] 65 end
Public Instance Methods
@private
# File lib/cassandra/statements/batch.rb 117 def accept(client, options) 118 Util.assert_not_empty(statements) { 'batch cannot be empty' } 119 client.batch(self, options) 120 end
Adds a statement to this batch.
@param statement [String, Cassandra::Statements::Simple
,
Cassandra::Statements::Prepared, Cassandra::Statements::Bound] statement to add.
@param options [Hash] (nil) a customizable set of options @option options [Array, Hash] :arguments (nil) positional or named
arguments to bind, must contain the same number of parameters as the number of positional (`?`) or named (`:name`) markers in the CQL passed.
@option options [Array, Hash] :type_hints (nil) override Util.guess_type
to determine the CQL type for an argument; nil elements will fall-back to Util.guess_type.
@option options [Boolean] :idempotent (false) specify whether this
statement can be retried safely on timeout.
@note Positional arguments for simple statements are only supported
starting with Apache Cassandra 2.0 and above.
@note Named arguments for simple statements are only supported
starting with Apache Cassandra 2.1 and above.
@return [self]
# File lib/cassandra/statements/batch.rb 90 def add(statement, options = nil) 91 options = if options.is_a?(::Hash) 92 @options.override(options) 93 else 94 @options 95 end 96 97 case statement 98 when String 99 @statements << Simple.new(statement, 100 options.arguments, 101 options.type_hints, 102 options.idempotent?) 103 when Prepared 104 @statements << statement.bind(options.arguments) 105 when Bound, Simple 106 @statements << statement 107 else 108 raise ::ArgumentError, 109 'a batch can only consist of simple or prepared statements, ' \ 110 "#{statement.inspect} given" 111 end 112 113 self 114 end
A batch statement doesn't really have any cql of its own as it is composed of multiple different statements @return [nil] nothing
# File lib/cassandra/statements/batch.rb 132 def cql 133 nil 134 end
Determines whether or not the statement is safe to retry on timeout Batches are idempotent only when all statements in a batch are. @return [Boolean] whether the statement is safe to retry on timeout
# File lib/cassandra/statements/batch.rb 125 def idempotent? 126 @statements.all?(&:idempotent?) 127 end
@return [String] a CLI-friendly batch statement representation
# File lib/cassandra/statements/batch.rb 141 def inspect 142 "#<#{self.class.name}:0x#{object_id.to_s(16)} @type=#{type.inspect}>" 143 end
@return [Symbol] one of `:logged`, `:unlogged` or `:counter`
# File lib/cassandra/statements/batch.rb 137 def type 138 end