class RDF::Transaction::SerializedTransaction

A transaction with full serializability.

@todo refactor me! @see RDF::Transaction

Public Class Methods

new(*args, **options, &block) click to toggle source

@see Transaction#initialize

Calls superclass method RDF::Transaction::new
# File lib/rdf/transaction.rb, line 334
def initialize(*args, **options, &block)
  super(*args, **options, &block)
  @base_snapshot = @snapshot
end

Public Instance Methods

delete_statement(statement) click to toggle source

Deletes the statement from the transaction’s working snapshot.

@see Transaction#insert_statement

# 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() 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 Transaction#execute

# 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) click to toggle source

Inserts the statement to the transaction’s working snapshot.

@see Transaction#insert_statement

# 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() click to toggle source

@see RDF::Dataset#isolation_level

# File lib/rdf/transaction.rb, line 363
def isolation_level
  :serializable
end
mutated?() click to toggle source

@note this is a simple object equality check.

@see RDF::Transaction#mutated?

# File lib/rdf/transaction.rb, line 371
def mutated?
  !@snapshot.send(:data).equal?(repository.send(:data))
end