Class: Cequel::Metal::Batch Private
- Inherits:
-
Object
- Object
- Cequel::Metal::Batch
- Defined in:
- lib/cequel/metal/batch.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Encapsulates a batch operation
Instance Method Summary collapse
-
#apply ⇒ Object
private
Send the batch to Cassandra.
-
#execute(cql, *bind_vars) ⇒ Object
private
Add a statement to the batch.
- #execute_with_consistency(cql, bind_vars, query_consistency) ⇒ Object private
-
#initialize(keyspace, options = {}) ⇒ Batch
constructor
private
A new instance of Batch.
-
#logged? ⇒ Boolean
private
Is this a logged batch?.
- #on_complete(&block) ⇒ Object private
-
#unlogged? ⇒ Boolean
private
Is this an unlogged batch?.
Constructor Details
#initialize(keyspace, options = {}) ⇒ Batch
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Batch.
27 28 29 30 31 32 33 34 35 |
# File 'lib/cequel/metal/batch.rb', line 27 def initialize(keyspace, = {}) .assert_valid_keys(:auto_apply, :unlogged, :consistency) @keyspace = keyspace @auto_apply = [:auto_apply] @unlogged = .fetch(:unlogged, false) @consistency = .fetch(:consistency, keyspace.default_consistency) reset end |
Instance Method Details
#apply ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Send the batch to Cassandra
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cequel/metal/batch.rb', line 54 def apply return if @statement_count.zero? if @statement_count > 1 @statement.prepend(begin_statement) @statement.append("APPLY BATCH\n") end @keyspace.execute_with_consistency( @statement.args.first, @statement.args.drop(1), @consistency) execute_on_complete_hooks end |
#execute(cql, *bind_vars) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add a statement to the batch.
42 43 44 45 46 47 48 49 |
# File 'lib/cequel/metal/batch.rb', line 42 def execute(cql, *bind_vars) @statement.append("#{cql}\n", *bind_vars) @statement_count += 1 if @auto_apply && @statement_count >= @auto_apply apply reset end end |
#execute_with_consistency(cql, bind_vars, query_consistency) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
87 88 89 90 91 92 93 94 95 |
# File 'lib/cequel/metal/batch.rb', line 87 def execute_with_consistency(cql, bind_vars, query_consistency) if query_consistency && query_consistency != @consistency raise ArgumentError, "Attempting to perform query with consistency " \ "#{query_consistency.to_s.upcase} in batch with consistency " \ "#{@consistency.upcase}" end execute(cql, *bind_vars) end |
#logged? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is this a logged batch?
82 83 84 |
# File 'lib/cequel/metal/batch.rb', line 82 def logged? !unlogged? end |
#on_complete(&block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
65 66 67 |
# File 'lib/cequel/metal/batch.rb', line 65 def on_complete(&block) on_complete_hooks << block end |
#unlogged? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is this an unlogged batch?
73 74 75 |
# File 'lib/cequel/metal/batch.rb', line 73 def unlogged? @unlogged end |