class ActiveTriples::BufferedTransaction

A buffered trasaction for use with ‘ActiveTriples::ParentStrategy`.

If an ‘ActiveTriples::RDFSource` instance is passed as the underlying repository, this transaction will try to find an existing `BufferedTransaction` to use as the basis for a snapshot. When the transaction is executed, the inserts and deletes are replayed against the `RDFSource`.

If a ‘RDF::Transaction::TransactionError` is raised on commit, this transaction optimistically attempts to replay the changes.

Reads are projected onto a specialized “Extended Bounded Description” subgraph.

@see ActiveTriples::Util::ExtendedBoundedDescription

Attributes

ancestors[R]

@!attribute snapshot [r]

@return RDF::Dataset

@!attribute subject [r]

@return RDF::Term

@!attribute ancestors [r]

@return Array<RDF::Term>
snapshot[R]

@!attribute snapshot [r]

@return RDF::Dataset

@!attribute subject [r]

@return RDF::Term

@!attribute ancestors [r]

@return Array<RDF::Term>
subject[R]

@!attribute snapshot [r]

@return RDF::Dataset

@!attribute subject [r]

@return RDF::Term

@!attribute ancestors [r]

@return Array<RDF::Term>

Public Class Methods

new(repository, ancestors: [], subject: nil, graph_name: nil, mutable: false, **options, &block) click to toggle source
Calls superclass method
# File lib/active_triples/util/buffered_transaction.rb, line 30
def initialize(repository,
               ancestors:  [],
               subject:    nil, 
               graph_name: nil, 
               mutable:    false, 
               **options,
               &block)
  @subject   = subject
  @ancestors = ancestors

  if repository.is_a?(RDFSource)
    if repository.persistence_strategy.graph.is_a?(BufferedTransaction)
      super
      @snapshot = repository.persistence_strategy.graph.snapshot
      return
    else
      repository = repository.persistence_strategy.graph.data
    end
  end

  return super
end

Public Instance Methods

data() click to toggle source

@return [BufferedTransaction] self

# File lib/active_triples/util/buffered_transaction.rb, line 63
def data
  self
end
delete_statement(statement) click to toggle source

Adds statement to the ‘deletes` collection of the buffered changeset and updates the snapshot.

@see RDF::Transaction#delete_statement

Calls superclass method
# File lib/active_triples/util/buffered_transaction.rb, line 89
def delete_statement(statement)
  @changes.delete(statement)
  @changes.inserts.delete(statement)
  super
end
execute() click to toggle source

Executes optimistically. If errors are encountered, we replay the buffer on the latest version.

If the ‘repository` is a transaction, we immediately replay the buffer onto it.

@see RDF::Transaction#execute

Calls superclass method
# File lib/active_triples/util/buffered_transaction.rb, line 103
def execute
  raise TransactionError, 'Cannot execute a rolled back transaction. ' \
                          'Open a new one instead.' if @rolledback
  return if changes.empty?
  return super unless repository.is_a?(ActiveTriples::RDFSource)

  repository.insert(changes.inserts)
  repository.delete(changes.deletes)
rescue RDF::Transaction::TransactionError => err
  raise err if @rolledback

  # replay changest on the current version of the repository
  repository.delete(*changes.deletes)
  repository.insert(*changes.inserts)
end
insert_statement(statement) click to toggle source

Adds statement to the ‘inserts` collection of the buffered changeset and updates the snapshot.

@see RDF::Mutable#insert_statement

Calls superclass method
# File lib/active_triples/util/buffered_transaction.rb, line 78
def insert_statement(statement)
  @changes.insert(statement)
  @changes.deletes.delete(statement)
  super
end
isolation_level() click to toggle source

Provides :repeatable_read isolation (???)

@see RDF::Transaction#isolation_level

# File lib/active_triples/util/buffered_transaction.rb, line 57
def isolation_level
  :repeatable_read
end
supports?(feature) click to toggle source

@see RDF::Mutable#supports

# File lib/active_triples/util/buffered_transaction.rb, line 69
def supports?(feature)
  return true if feature.to_sym == :snapshots
end

Private Instance Methods

read_target() click to toggle source
Calls superclass method
# File lib/active_triples/util/buffered_transaction.rb, line 121
def read_target
  return super unless subject
  ExtendedBoundedDescription.new(super, subject, ancestors)
end