Class: StrokeDB::Transaction
Instance Attribute Summary collapse
-
#uuid ⇒ Object
readonly
Returns the value of attribute uuid.
Instance Method Summary collapse
- #commit! ⇒ Object
- #execute ⇒ Object
- #find(uuid, version = nil, opts = {}) ⇒ Object
- #head_version(uuid) ⇒ Object
-
#initialize(options = {}) ⇒ Transaction
constructor
A new instance of Transaction.
- #inspect ⇒ Object
- #rollback! ⇒ Object
- #save!(doc) ⇒ Object
- #storage ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Transaction
Returns a new instance of Transaction.
7 8 9 10 11 |
# File 'lib/strokedb/transaction.rb', line 7 def initialize( = {}) @options = .stringify_keys @uuid = Util.random_uuid storage.add_chained_storage!(store.storage) end |
Instance Attribute Details
#uuid ⇒ Object (readonly)
Returns the value of attribute uuid.
5 6 7 |
# File 'lib/strokedb/transaction.rb', line 5 def uuid @uuid end |
Instance Method Details
#commit! ⇒ Object
58 59 60 61 |
# File 'lib/strokedb/transaction.rb', line 58 def commit! storage.sync_chained_storage!(store.storage) true end |
#execute ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/strokedb/transaction.rb', line 38 def execute raise ArgumentError, "no block provided" unless block_given? Thread.current[:strokedb_transactions] ||= [] Thread.current[:strokedb_transactions].push self @timestamp = LTS.new(store..counter,uuid) begin result = yield(self) rescue throw $! ensure Thread.current[:strokedb_transactions].pop end result end |
#find(uuid, version = nil, opts = {}) ⇒ Object
25 26 27 |
# File 'lib/strokedb/transaction.rb', line 25 def find(uuid, version=nil, opts = {}) storage.find(uuid,version,opts.merge(:store => self)) end |
#head_version(uuid) ⇒ Object
29 30 31 |
# File 'lib/strokedb/transaction.rb', line 29 def head_version(uuid) storage.head_version(uuid,{ :store => self }) end |
#inspect ⇒ Object
21 22 23 |
# File 'lib/strokedb/transaction.rb', line 21 def inspect "#<Transaction #{@uuid}>" end |
#rollback! ⇒ Object
63 64 65 66 |
# File 'lib/strokedb/transaction.rb', line 63 def rollback! @options['storage'] = setup_storage true end |
#save!(doc) ⇒ Object
33 34 35 36 |
# File 'lib/strokedb/transaction.rb', line 33 def save!(doc) @timestamp = @timestamp.next storage.save!(doc,@timestamp) end |
#storage ⇒ Object
13 14 15 |
# File 'lib/strokedb/transaction.rb', line 13 def storage @options['storage'] ||= setup_storage end |
#store ⇒ Object
17 18 19 |
# File 'lib/strokedb/transaction.rb', line 17 def store @options['store'] end |