class RDF::Repository::Implementation::SerializedTransaction
A transaction for the Hamster-based `RDF::Repository::Implementation` with full serializability.
@todo refactor me! @see RDF::Transaction
Public Class Methods
new(*)
click to toggle source
@see Transaction#initialize
Calls superclass method
# File lib/rdf/repository.rb, line 519 def initialize(*) super @base_snapshot = @snapshot end
Public Instance Methods
delete_statement(statement)
click to toggle source
Deletes the statement from the transaction's working snapshot.
@see RDF::Transaction#insert_statement
# 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
execute()
click to toggle source
Replaces repository data with the transaction's snapshot in a safely serializable fashion.
@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.
@raise [TransactionError] when the transaction can't be merged. @see RDF::Transaction#execute
# 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)
click to toggle source
Inserts the statement to the transaction's working snapshot.
@see RDF::Transaction#insert_statement
# 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_level()
click to toggle source
@see RDF::Dataset#isolation_level
# File lib/rdf/repository.rb, line 548 def isolation_level :serializable end