Skip to content

Commit c8bce71

Browse files
committed
Use new RDF.rb transaction support instead of iterating twice.
1 parent 26e36c5 commit c8bce71

3 files changed

Lines changed: 13 additions & 19 deletions

File tree

lib/ld/patch/algebra/patch.rb

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,25 @@ class Patch < SPARQL::Algebra::Operator
1010
NAME = :patch
1111

1212
##
13-
# Executes this upate on the given `writable` graph or repository.
13+
# Executes this upate on the given `repository`.
1414
#
15-
# @param [RDF::Queryable] queryable
16-
# the graph or repository to write
15+
# @param [RDF::Repository] repository
16+
# the repository to update.
1717
# @param [Hash{Symbol => Object}] options
1818
# any additional options
19-
# @return [RDF::Queryable]
20-
# Returns queryable.
19+
# @return [RDF::Repository]
20+
# Returns repository.
2121
# @raise [Error]
2222
# If any error is caught along the way, and rolls back the transaction
23-
def execute(queryable, options = {})
23+
def execute(repository, options = {})
2424
debug(options) {"Delete"}
2525

26-
# FIXME: due to insufficient transaction support, this is implemented by running through operands twice: the first using a clone of the graph, and the second acting on the graph directly
27-
graph = RDF::Graph.new << queryable
28-
loop do
26+
repository.transaction(mutable: true) do |tx|
2927
operands.inject(RDF::Query::Solutions.new([RDF::Query::Solution.new])) do |bindings, op|
3028
# Invoke operand using bindings from prvious operation
31-
op.execute(graph, options.merge(bindings: bindings))
29+
op.execute(tx, options.merge(bindings: bindings))
3230
end
33-
34-
break if graph.equal?(queryable)
35-
graph = queryable
3631
end
37-
queryable
3832
end
3933
end
4034
end

spec/algebra_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,9 @@
418418
},
419419
}.each do |name, props|
420420
it name do
421-
graph = RDF::Graph.new << RDF::NTriples::Reader.new(props[:data])
421+
graph = RDF::Repository.new << RDF::NTriples::Reader.new(props[:data])
422422
operator = LD::Patch::Parser.new(props[:patch]).parse
423-
result = RDF::Graph.new << RDF::NTriples::Reader.new(props[:result])
423+
result = RDF::Repository.new << RDF::NTriples::Reader.new(props[:result])
424424
operator.execute(graph)
425425
expect(graph).to be_equivalent_graph(result)
426426
end
@@ -469,7 +469,7 @@
469469
},
470470
}.each do |name, props|
471471
it name do
472-
graph = RDF::Graph.new << RDF::NTriples::Reader.new(props[:data])
472+
graph = RDF::Repository.new << RDF::NTriples::Reader.new(props[:data])
473473
operator = LD::Patch::Parser.new(props[:patch]).parse
474474
expect {operator.execute(graph)}.to raise_error(LD::Patch::Error)
475475
end

spec/suite_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,15 @@ def data
150150
end
151151

152152
def target_graph
153-
@graph ||= RDF::Graph.load(URI.decode(data), base_uri: base)
153+
@graph ||= RDF::Repository.load(URI.decode(data), base_uri: base)
154154
end
155155

156156
def expected
157157
@expected ||= RDF::Util::File.open_file(URI.decode(result)) {|f| f.read}
158158
end
159159

160160
def expected_graph
161-
@expected_graph ||= RDF::Graph.load(URI.decode(result), base_uri: base)
161+
@expected_graph ||= RDF::Repository.load(URI.decode(result), base_uri: base)
162162
end
163163

164164
def evaluate?

0 commit comments

Comments
 (0)