class RoadForest::SourceRigor::UpdateManager

Attributes

copied_contexts[RW]
deletes[RW]
inserts[RW]

Public Class Methods

new() click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 65
def initialize
  @copied_contexts = {}
  @inserts = Hash.new{|h,k| h[k] = []}
  @deletes = Hash.new{|h,k| h[k] = []}
end

Public Instance Methods

delete(statement) click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 123
def delete(statement)
  statement = statement_from(statement)
  record_delete(statement)
  super
end
dup() click to toggle source
Calls superclass method RoadForest::SourceRigor::Rigorous#dup
# File lib/roadforest/source-rigor/rigorous-access.rb, line 85
def dup
  other = super
  other.copied_contexts = self.copied_contexts
  other.inserts = self.inserts
  other.deletes = self.deletes
  other.target_graph = self.target_graph
  return other
end
each_payload() { |solution, solution, graph_for| ... } click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 129
def each_payload
  update_payload_query = ::RDF::Query.new do
    pattern [ :affordance, Af.target, :resource ]
    pattern [ :affordance, Af.payload, :pattern_root ]
    pattern [ :affordance, RDF.type, Af.Update ]
  end
  query(update_payload_query).each do |solution|
    yield(solution[:resource], solution[:pattern_root], parceller.graph_for(solution[:pattern_root]))
  end
end
each_target() { |root, graph| ... } click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 140
def each_target
  all_subjects = Hash[destination_graph.subjects.map{|s| [s,true]}]
  source_graph.subjects.each do |s|
    all_subjects[s] = true
  end
  check_inserts = inserts.dup
  check_deletes = deletes.dup
  marked_inserts = []
  marked_deletes = []

  each_payload do |root, pattern_root, graph_pattern|
    next unless all_subjects.has_key?(root)

    marked_inserts.clear
    marked_deletes.clear

    matcher = PathMatcher.new
    matcher.pattern = graph_pattern
    matcher.pattern_root = pattern_root

    source_match = matcher.match(root, source_graph)

    dest_match = matcher.match(root, destination_graph)

    if dest_match.successful?
      check_inserts.each_key do |stmt|
        if dest_match.graph.has_statement?(stmt)
          marked_inserts << stmt
        end
      end
    end

    if source_match.successful?
      check_deletes.each_key do |stmt|
        if source_match.graph.has_statement?(stmt)
          marked_deletes << stmt
        end
      end
    end

    if dest_match.successful?
      if !source_match.successful? || (source_match.graph != dest_match.graph)

        yield(root, dest_match.graph)

        marked_inserts.each do |stmt|
          check_inserts.delete(stmt)
        end
        marked_deletes.each do |stmt|
          check_deletes.delete(stmt)
        end
      end
    end
  end

  fallback_needed = {}
  check_inserts.each_value do|resources|
    resources.each {|resource| fallback_needed[resource] = true }
  end
  check_deletes.each_value do|resources|
    resources.each {|resource| fallback_needed[resource] = true }
  end

  fallback_needed.each_key do |key|
    yield(key, parceller.graph_for(key))
  end
end
insert(statement) click to toggle source
Calls superclass method RoadForest::Graph::WriteManager#insert
# File lib/roadforest/source-rigor/rigorous-access.rb, line 116
def insert(statement)
  statement = statement_from(statement)
  record_insert(statement)
  statement.context ||= ::RDF::URI.intern("urn:local-insert")
  super
end
parceller() click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 208
def parceller
  @parceller ||=
    begin
      parceller = Parcel.new
      parceller.graph = destination_graph
      parceller
    end
end
record_delete(statement) click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 108
def record_delete(statement)
  @deletes[statement] << resource
end
record_insert(statement) click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 104
def record_insert(statement)
  @inserts[statement] << resource
end
reset() click to toggle source
Calls superclass method RoadForest::Graph::SplitManager#reset
# File lib/roadforest/source-rigor/rigorous-access.rb, line 71
def reset
  super

  @copied_contexts.clear
  @inserts.clear
  @deletes.clear

  source_graph.each_statement do |stmt|
    target_graph << stmt
  end
end
statement_from(statement) click to toggle source
# File lib/roadforest/source-rigor/rigorous-access.rb, line 112
def statement_from(statement)
  ::RDF::Statement.from(statement)
end