Class: RDF::Transaction::SerializedTransaction
- Inherits:
-
RDF::Transaction
- Object
- RDF::Transaction
- RDF::Transaction::SerializedTransaction
- Defined in:
- lib/rdf/transaction.rb
Overview
refactor me!
A transaction with full serializability.
Instance Attribute Summary
Attributes inherited from RDF::Transaction
#changes, #graph_name, #options, #repository
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 RDF::Transaction
begin, #each, #inspect, #inspect!, #mutable?, #readable?, #rollback, #statement?, #writable?
Methods included from Queryable
#enum_for, #first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #query
Methods included from Enumerable
#canonicalize, #canonicalize!, #dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #enum_graph, #enum_object, #enum_predicate, #enum_quad, #enum_statement, #enum_subject, #enum_term, #enum_triple, #graph?, #graph_names, #invalid?, #object?, #objects, #predicate?, #predicates, #project_graph, #quad?, #quads, #statement?, #statements, #subject?, #subjects, #supports?, #term?, #terms, #to_a, #to_h, #to_set, #triple?, #triples, #valid?, #validate!
Methods included from Util::Aliasing::LateBound
Methods included from Countable
Methods included from Mutable
#<<, #apply_changeset, #clear, #delete, #delete_insert, #immutable?, #insert, #load, #method_missing, #mutable?, #respond_to_missing?, #snapshot, #update
Methods included from Writable
Methods included from Readable
Constructor Details
#initialize(*args, **options, &block) ⇒ SerializedTransaction
Returns a new instance of SerializedTransaction.
334 335 336 337 |
# File 'lib/rdf/transaction.rb', line 334 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.
354 355 356 357 358 359 |
# File 'lib/rdf/transaction.rb', line 354 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.
388 389 390 391 392 393 394 395 396 397 |
# File 'lib/rdf/transaction.rb', line 388 def execute raise TransactionError, 'Cannot execute a rolled back transaction. ' \ 'Open a new one instead.' if instance_variable_defined?(:@rolledback) && @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.
343 344 345 346 347 348 |
# File 'lib/rdf/transaction.rb', line 343 def insert_statement(statement) @snapshot = @snapshot.class .new(data: @snapshot.send(:insert_to, @snapshot.send(:data), process_statement(statement))) end |
#isolation_level ⇒ Object
363 364 365 |
# File 'lib/rdf/transaction.rb', line 363 def isolation_level :serializable end |
#mutated? ⇒ Boolean
this is a simple object equality check.
371 372 373 |
# File 'lib/rdf/transaction.rb', line 371 def mutated? !@snapshot.send(:data).equal?(repository.send(:data)) end |