Class: RDF::Repository::Implementation::SerializedTransaction
- Inherits:
-
Transaction
- Object
- Transaction
- RDF::Repository::Implementation::SerializedTransaction
- Defined in:
- vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb
Overview
refactor me!
A transaction for the Hamster-based RDF::Repository::Implementation
with full serializability.
Instance Attribute Summary
Attributes inherited from Transaction
#changes, #graph_name, #options, #repository
Attributes included from Enumerable
Instance Method Summary collapse
-
#delete_statement(statement) ⇒ Object
Deletes the statement from the transaction's working snapshot.
-
#execute ⇒ Object
Replaces repository data with the transaction's snapshot in a safely serializable fashion.
-
#initialize(*args, **options, &block) ⇒ SerializedTransaction
constructor
A new instance of SerializedTransaction.
-
#insert_statement(statement) ⇒ Object
Inserts the statement to the transaction's working snapshot.
- #isolation_level ⇒ Object
- #mutated? ⇒ Boolean
Methods inherited from Transaction
begin, #each, #has_statement?, #inspect, #inspect!, #mutable?, #query_execute, #query_pattern, #readable?, #rollback, #writable?
Methods included from Queryable
#concise_bounded_description, #first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #lint, #query, #query_execute, #query_pattern, #query_without_sparql
Methods included from Enumerable
add_entailment, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #entail, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph_names, #has_graph?, #has_object?, #has_predicate?, #has_quad?, #has_statement?, #has_subject?, #has_term?, #has_triple?, #invalid?, #method_missing, #objects, #predicates, #project_graph, #quads, #respond_to_missing?, #statements, #subjects, #supports?, #terms, #to_a, #to_h, #to_set, #triples, #valid?, #validate!
Methods included from Util::Aliasing::LateBound
Methods included from Countable
Methods included from Isomorphic
#bijection_to, #isomorphic_with?
Methods included from Mutable
#<<, add_entailment, #apply_changeset, #clear, #delete, #delete_insert, #delete_statements, #entail, #entail!, #immutable?, #insert, #load, #method_missing, #mutable?, #respond_to_missing?, #snapshot, #update
Methods included from Util::Coercions
Methods included from Writable
#<<, #insert, #insert_graph, #insert_reader, #insert_statements, #writable?
Methods included from RDF::Readable
Constructor Details
#initialize(*args, **options, &block) ⇒ SerializedTransaction
Returns a new instance of SerializedTransaction.
529 530 531 532 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb', line 529 def initialize(*args, **, &block) super(*args, **, &block) @base_snapshot = @snapshot end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class RDF::Enumerable
Instance Method Details
#delete_statement(statement) ⇒ Object
Deletes the statement from the transaction's working snapshot.
549 550 551 552 553 554 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb', line 549 def delete_statement(statement) @snapshot = @snapshot.class .new(data: @snapshot.send(:delete_from, @snapshot.send(:data), process_statement(statement))) end |
#execute ⇒ Object
this transaction uses a pessimistic merge strategy which fails the transaction if any data has changed in the repository since transaction start time. However, the specific guarantee is softer: multiple concurrent conflicting transactions will not succeed. We may choose to implement a less pessimistic merge strategy as a non-breaking change.
Replaces repository data with the transaction's snapshot in a safely serializable fashion.
583 584 585 586 587 588 589 590 591 592 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb', line 583 def execute raise TransactionError, 'Cannot execute a rolled back transaction. ' \ 'Open a new one instead.' if @rolledback raise TransactionError, 'Error merging transaction. Repository' \ 'has changed during transaction time.' unless repository.send(:data).equal? @base_snapshot.send(:data) repository.send(:data=, @snapshot.send(:data)) end |
#insert_statement(statement) ⇒ Object
Inserts the statement to the transaction's working snapshot.
538 539 540 541 542 543 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb', line 538 def insert_statement(statement) @snapshot = @snapshot.class .new(data: @snapshot.send(:insert_to, @snapshot.send(:data), process_statement(statement))) end |
#isolation_level ⇒ Object
558 559 560 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb', line 558 def isolation_level :serializable end |
#mutated? ⇒ Boolean
this is a simple object equality check.
566 567 568 |
# File 'vendor/bundler/ruby/2.7.0/bundler/gems/rdf-0e84e3dd0307/lib/rdf/repository.rb', line 566 def mutated? !@snapshot.send(:data).equal?(repository.send(:data)) end |