Class: ActiveTriples::BufferedTransaction
- Inherits:
-
RDF::Repository::Implementation::SerializedTransaction
- Object
- RDF::Repository::Implementation::SerializedTransaction
- ActiveTriples::BufferedTransaction
- Defined in:
- lib/active_triples/util/buffered_transaction.rb
Overview
A buffered trasaction for use with ‘ActiveTriples::ParentStrategy`.
If an ‘ActiveTriples::RDFSource` instance is passed as the underlying repository, this transaction will try to find an existing `BufferedTransaction` to use as the basis for a snapshot. When the transaction is executed, the inserts and deletes are replayed against the `RDFSource`.
If a ‘RDF::Transaction::TransactionError` is raised on commit, this transaction optimistically attempts to replay the changes.
Reads are projected onto a specialized “Extended Bounded Description” subgraph.
Instance Attribute Summary collapse
-
#ancestors ⇒ Object
readonly
Returns the value of attribute ancestors.
-
#snapshot ⇒ Object
readonly
RDF::Dataset.
-
#subject ⇒ Object
readonly
RDF::Term.
Instance Method Summary collapse
-
#data ⇒ BufferedTransaction
Self.
-
#delete_statement(statement) ⇒ Object
Adds statement to the ‘deletes` collection of the buffered changeset and updates the snapshot.
-
#execute ⇒ Object
Executes optimistically.
-
#initialize(repository, ancestors: [], subject: nil, graph_name: nil, mutable: false, **options, &block) ⇒ BufferedTransaction
constructor
A new instance of BufferedTransaction.
-
#insert_statement(statement) ⇒ Object
Adds statement to the ‘inserts` collection of the buffered changeset and updates the snapshot.
-
#isolation_level ⇒ Object
Provides :repeatable_read isolation (???).
- #supports?(feature) ⇒ Boolean
Constructor Details
#initialize(repository, ancestors: [], subject: nil, graph_name: nil, mutable: false, **options, &block) ⇒ BufferedTransaction
Returns a new instance of BufferedTransaction.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 30 def initialize(repository, ancestors: [], subject: nil, graph_name: nil, mutable: false, **, &block) @subject = subject @ancestors = ancestors if repository.is_a?(RDFSource) if repository.persistence_strategy.graph.is_a?(BufferedTransaction) super @snapshot = repository.persistence_strategy.graph.snapshot return else repository = repository.persistence_strategy.graph.data end end return super end |
Instance Attribute Details
#ancestors ⇒ Object (readonly)
Returns the value of attribute ancestors.
28 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 28 attr_reader :snapshot, :subject, :ancestors |
#snapshot ⇒ Object (readonly)
Returns RDF::Dataset.
28 29 30 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 28 def snapshot @snapshot end |
#subject ⇒ Object (readonly)
Returns RDF::Term.
28 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 28 attr_reader :snapshot, :subject, :ancestors |
Instance Method Details
#data ⇒ BufferedTransaction
Returns self.
63 64 65 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 63 def data self end |
#delete_statement(statement) ⇒ Object
Adds statement to the ‘deletes` collection of the buffered changeset and updates the snapshot.
89 90 91 92 93 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 89 def delete_statement(statement) @changes.delete(statement) @changes.inserts.delete(statement) super end |
#execute ⇒ Object
Executes optimistically. If errors are encountered, we replay the buffer on the latest version.
If the ‘repository` is a transaction, we immediately replay the buffer onto it.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 103 def execute raise TransactionError, 'Cannot execute a rolled back transaction. ' \ 'Open a new one instead.' if @rolledback return if changes.empty? return super unless repository.is_a?(ActiveTriples::RDFSource) repository.insert(changes.inserts) repository.delete(changes.deletes) rescue RDF::Transaction::TransactionError => err raise err if @rolledback # replay changest on the current version of the repository repository.delete(*changes.deletes) repository.insert(*changes.inserts) end |
#insert_statement(statement) ⇒ Object
Adds statement to the ‘inserts` collection of the buffered changeset and updates the snapshot.
78 79 80 81 82 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 78 def insert_statement(statement) @changes.insert(statement) @changes.deletes.delete(statement) super end |
#isolation_level ⇒ Object
Provides :repeatable_read isolation (???)
57 58 59 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 57 def isolation_level :repeatable_read end |
#supports?(feature) ⇒ Boolean
69 70 71 |
# File 'lib/active_triples/util/buffered_transaction.rb', line 69 def supports?(feature) return true if feature.to_sym == :snapshots end |