Class: RDF::Repository::Implementation::SerializedTransaction

Inherits:
Transaction
  • Object
show all
Defined in:
lib/rdf/repository.rb

Overview

TODO:

refactor me!

A transaction for the Hamster-based ‘RDF::Repository::Implementation` with full serializability.

See Also:

Instance Attribute Summary

Attributes inherited from Transaction

#changes, #graph_name, #options, #repository

Instance Method Summary collapse

Methods inherited from Transaction

begin, #each, #has_statement?, #inspect, #inspect!, #mutable?, #readable?, #rollback, #writable?

Methods included from Queryable

#enum_for, #first, #first_literal, #first_object, #first_predicate, #first_subject, #first_value, #query

Methods included from Enumerable

#dump, #each_graph, #each_object, #each_predicate, #each_quad, #each_statement, #each_subject, #each_term, #each_triple, #enum_for, #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_hash, #to_set, #triples, #valid?, #validate!

Methods included from Util::Aliasing::LateBound

#alias_method

Methods included from Countable

#count, #empty?, #enum_for

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

#<<, #insert, #writable?

Methods included from RDF::Readable

#readable?

Constructor Details

#initializeSerializedTransaction

Returns a new instance of SerializedTransaction.



519
520
521
522
# File 'lib/rdf/repository.rb', line 519

def initialize(*)
  super
  @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.

See Also:

  • Transaction#insert_statement


539
540
541
542
543
544
# File 'lib/rdf/repository.rb', line 539

def delete_statement(statement)
  @snapshot = @snapshot.class
    .new(data: @snapshot.send(:delete_from, 
                              @snapshot.send(:data), 
                              process_statement(statement)))
end

#executeObject

Note:

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.

Raises:

See Also:



565
566
567
568
569
570
571
572
573
574
575
576
# File 'lib/rdf/repository.rb', line 565

def execute
  raise TransactionError, 'Cannot execute a rolled back transaction. ' \
                          'Open a new one instead.' if @rolledback

  # `Hamster::Hash#==` will use a cheap `#equal?` check first, but fall 
  # back on a full Ruby Hash comparison if required.
  raise TransactionError, 'Error merging transaction. Repository' \
                          'has changed during transaction time.' unless 
    repository.send(:data) == @base_snapshot.send(:data)

  repository.send(:data=, @snapshot.send(:data))
end

#insert_statement(statement) ⇒ Object

Inserts the statement to the transaction’s working snapshot.

See Also:

  • Transaction#insert_statement


528
529
530
531
532
533
# File 'lib/rdf/repository.rb', line 528

def insert_statement(statement)
  @snapshot = @snapshot.class
    .new(data: @snapshot.send(:insert_to, 
                              @snapshot.send(:data), 
                              process_statement(statement)))
end

#isolation_levelObject



548
549
550
# File 'lib/rdf/repository.rb', line 548

def isolation_level
  :serializable
end