Swirrl / grafter

Linked Data & RDF Manufacturing Tools in Clojure
Eclipse Public License 1.0
190 stars 17 forks source link

Query string cannot be empty error when attempting to issue an update! in a transaction #175

Open RickMoynihan opened 3 years ago

RickMoynihan commented 3 years ago

Creating a transaction on a grafter/rdf4j sparql-repo and then calling update! yeilds an error:

user> (require 'grafter-2.rdf4j.repository)
;; => nil
user> (def repo (grafter-2.rdf4j.repository/sparql-repo "http://localhost:5820/test-db/query" "http://localhost:5820/test-db/update"))
;; => #'user/repo
user> (def conn (grafter-2.rdf4j.repository/->connection repo))
;; => #'user/conn
user> (grafter-2.rdf.protocols/begin conn)
;; => nil
user> (grafter-2.rdf.protocols/update! conn "INSERT DATA { <http://foo-4> <http://bar-1> <http://baz-1> . }")
;; => nil
user> (grafter-2.rdf.protocols/commit conn)
[nRepl-session-9a2d78ce-51e6-4c7d-86f9-771ddf06d921] WARN org.eclipse.rdf4j.http.client.SharedHttpClientSessionManager$2 - Server reports problem: {"message":"Query string cannot be empty"}

This is because RDF4j's SPARQLRepository class only considers direct add/delete operations on the connection to be part of the transaction, whilst the update! operation is sent immediately (outside of the transaction).

This means that when the transaction is commited it is empty and hence you have no "query string" (transaction data).

e.g. this does not error:

user> (def repo (grafter-2.rdf4j.repository/sparql-repo "http://localhost:5820/test-xsd/query" "http://localhost:5820/test-xsd/update"))
;; => #'user/repo
user> (def conn (grafter-2.rdf4j.repository/->connection repo))
;; => #'user/conn
user> (grafter-2.rdf.protocols/begin conn)
;; => nil
user> (grafter-2.rdf.protocols/add conn [(grafter-2.rdf.protocols/->Triple (java.net.URI. "http://foo") (java.net.URI. "http://foo") (java.net.URI. "http://foo"))])
;; => #object[org.eclipse.rdf4j.repository.sparql.SPARQLConnection 0x29c02d3b "http://localhost:5820/test-xsd/query"]
user> (grafter-2.rdf.protocols/update! conn "INSERT DATA { <http://foo-5> <http://bar-1> <http://baz-1> . }")
;; => nil
user> (grafter-2.rdf.protocols/commit conn)

However the update! call occured before the addition of the triple (outside the transaction).

These problems exist in the RDF4j implementation.