Module: RDF::Transactable
- Included in:
- Graph, Repository
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/transactable.rb
Overview
A transaction application mixin.
Classes that include this module must provide a #begin_transaction
method
returning an Transaction.
Instance Method Summary collapse
-
#begin_transaction(mutable: false, graph_name: nil) ⇒ RDF::Transaction
protected
Begins a new transaction.
-
#commit_transaction(tx)
protected
Commits the given transaction.
-
#rollback_transaction(tx)
protected
Rolls back the given transaction.
-
#transaction(mutable: false, &block) ⇒ Object
(also: #transact)
Executes the given block in a transaction.
Instance Method Details
#begin_transaction(mutable: false, graph_name: nil) ⇒ RDF::Transaction (protected)
Begins a new transaction.
Subclasses implementing transaction-capable storage adapters may wish to override this method in order to begin a transaction against the underlying storage.
81 82 83 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/transactable.rb', line 81 def begin_transaction(mutable: false, graph_name: nil) raise NotImplementedError end |
#commit_transaction(tx) (protected)
This method returns an undefined value.
Commits the given transaction.
Subclasses implementing transaction-capable storage adapters may wish to override this method in order to commit the given transaction to the underlying storage.
105 106 107 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/transactable.rb', line 105 def commit_transaction(tx) tx.execute end |
#rollback_transaction(tx) (protected)
This method returns an undefined value.
Rolls back the given transaction.
91 92 93 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/transactable.rb', line 91 def rollback_transaction(tx) tx.rollback end |
#transaction(mutable: false) ⇒ RDF::Transaction #transaction(mutable: false) {|tx| ... } ⇒ self Also known as: transact
Executes the given block in a transaction.
Raising an error within the transaction block causes automatic rollback.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/mixin/transactable.rb', line 50 def transaction(mutable: false, &block) tx = begin_transaction(mutable: mutable) return tx unless block_given? begin case block.arity when 1 then block.call(tx) else tx.instance_eval(&block) end rescue => error rollback_transaction(tx) raise error end commit_transaction(tx) self end |