From 80ff975c9f3aee68ac0ee605326aaeaa75f8913e Mon Sep 17 00:00:00 2001 From: Tom Johnson Date: Tue, 16 Feb 2016 17:12:42 -0800 Subject: [PATCH] Only use tx on #delete_insert for :atomic_write Repositories that don't support :atomic_write shouldn't try to use a transaction for #delete_insert. Repositories answering `true` to `:atomic_write` promise to deliver an atomic `#apply_changeset`. --- lib/rdf/mixin/mutable.rb | 2 +- lib/rdf/repository.rb | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/rdf/mixin/mutable.rb b/lib/rdf/mixin/mutable.rb index 58478855..38d5c192 100644 --- a/lib/rdf/mixin/mutable.rb +++ b/lib/rdf/mixin/mutable.rb @@ -201,7 +201,7 @@ def delete_insert(deletes, inserts) ## # Applies the given changeset # - # If `#supports?(:transactions)` is `true`, this must apply the changeset + # If `#supports?(:atomic_write)` is `true`, this must apply the changeset # atomically. Otherwise, it should offer an efficient implementation of a # combined delete/insert of the changeset. # diff --git a/lib/rdf/repository.rb b/lib/rdf/repository.rb index ed1c4df6..50271c00 100644 --- a/lib/rdf/repository.rb +++ b/lib/rdf/repository.rb @@ -150,6 +150,8 @@ def supports?(feature) # # @see RDF::Mutable#delete_insert def delete_insert(deletes, inserts) + return super unless supports?(:atomic_write) + transaction(mutable: true) do deletes.respond_to?(:each_statement) ? delete(deletes) : delete(*deletes) inserts.respond_to?(:each_statement) ? insert(inserts) : insert(*inserts) @@ -291,7 +293,7 @@ def each_statement(&block) enum_statement end alias_method :each, :each_statement - + ## # @see Mutable#apply_changeset def apply_changeset(changeset)