Class: Cequel::Metal::BatchManager Private
- Inherits:
-
Object
- Object
- Cequel::Metal::BatchManager
- Defined in:
- lib/cequel/metal/batch_manager.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.
Manage a current batch per thread. Used by Keyspace
Instance Method Summary collapse
-
#batch(options = {}) { ... } ⇒ Object
private
Execute write operations in a batch.
-
#initialize(keyspace) ⇒ BatchManager
constructor
private
A new instance of BatchManager.
Constructor Details
#initialize(keyspace) ⇒ BatchManager
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 BatchManager.
14 15 16 |
# File 'lib/cequel/metal/batch_manager.rb', line 14 def initialize(keyspace) @keyspace = keyspace end |
Instance Method Details
#batch(options = {}) { ... } ⇒ 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.
If this method is created while already in a batch of the same type (logged or unlogged), this method is a no-op.
Execute write operations in a batch. Any inserts, updates, and deletes inside this method’s block will be executed inside a CQL BATCH operation.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cequel/metal/batch_manager.rb', line 39 def batch( = {}) new_batch = Batch.new(keyspace, ) if current_batch if current_batch.unlogged? && new_batch.logged? fail ArgumentError, "Already in an unlogged batch; can't start a logged batch." end return yield(current_batch) end begin self.current_batch = new_batch yield(new_batch).tap { new_batch.apply } ensure self.current_batch = nil end end |