diff --git a/env/dev/clj/drafter/routes/dump.clj b/env/dev/clj/drafter/routes/dump.clj
index 9512e1fcc..4574cdc4c 100644
--- a/env/dev/clj/drafter/routes/dump.clj
+++ b/env/dev/clj/drafter/routes/dump.clj
@@ -5,7 +5,8 @@
[drafter.rdf.drafter-ontology :refer :all]
[grafter.rdf :refer [add statements]]
[grafter.rdf.formats :refer [rdf-trig]]
- [grafter.rdf.io :refer [rdf-serializer default-prefixes]]
+ [grafter.rdf.io :refer [default-prefixes]]
+ [grafter.rdf4j.io :refer [rdf-writer]]
[ring.util.io :as rio]
[ring.util.response :refer [not-found]]
[grafter.url :as url]))
@@ -20,7 +21,7 @@
the RAW database as a Trig String for debugging. Don't use on large
databases as it will be loaded into memory."
[db ostream]
- (add (rdf-serializer ostream :format rdf-trig :prefixes drafter-prefixes)
+ (add (rdf-writer ostream :format rdf-trig :prefixes drafter-prefixes)
(statements db)))
(defn build-dump-route [backend]
diff --git a/project.clj b/project.clj
index 166632a61..d236187d0 100644
--- a/project.clj
+++ b/project.clj
@@ -1,4 +1,4 @@
-(defproject drafter "2.1.6-SNAPSHOT"
+(defproject drafter "2.1.7-SNAPSHOT"
:description "Backend PMD service"
:url "http://github.com/Swirrl/drafter"
:license {:name "Proprietary & Commercially Licensed Only"
@@ -23,10 +23,6 @@
[org.clojure/clojure "1.9.0-beta2"]
[org.clojure/math.combinatorics "0.1.4"]
- [org.openrdf.sesame/sesame-queryrender "2.8.11"]
- [org.openrdf.sesame/sesame-runtime "2.8.11"]
- [org.openrdf.sesame/sesame-queryresultio-sparqlxml "2.8.11"]
-
[cognician/dogstatsd-clj "0.1.2"]
[clj-yaml "0.4.0"] ;; for loading our Swagger schemas
@@ -49,7 +45,7 @@
[com.sun.mail/javax.mail "1.6.0"]
;;[com.taoensso/tower "2.0.2"]
- [grafter "0.9.0"]
+ [grafter "0.10.0"]
[grafter/url "0.2.5"]
;[grafter/vocabularies "0.1.3"]
[lib-noir "0.9.9" :exclusions [compojure org.clojure/java.classpath org.clojure/tools.reader org.clojure/java.classpath]]
@@ -66,9 +62,7 @@
[org.apache.jena/jena-iri "3.4.0" :exclusions [org.slf4j/slf4j-api]]
[org.mindrot/jbcrypt "0.4"]
- [org.openrdf.sesame/sesame-queryrender "2.8.11"]
- [org.openrdf.sesame/sesame-queryresultio-sparqlxml "2.8.11"]
- [org.openrdf.sesame/sesame-runtime "2.8.11"]
+
[org.slf4j/slf4j-log4j12 "1.7.25" :exclusions [log4j org.slf4j/slf4j-api]]
[prismatic/schema "1.1.7"]
diff --git a/src-java/drafter_sparql_repository/drafter-sparql-repository.iml b/src-java/drafter_sparql_repository/drafter-sparql-repository.iml
index 05aff616d..e7c3d3f91 100644
--- a/src-java/drafter_sparql_repository/drafter-sparql-repository.iml
+++ b/src-java/drafter_sparql_repository/drafter-sparql-repository.iml
@@ -1,6 +1,6 @@
-
+
@@ -11,78 +11,86 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src-java/drafter_sparql_repository/pom.xml b/src-java/drafter_sparql_repository/pom.xml
index cf4c1873d..1bd7144e4 100644
--- a/src-java/drafter_sparql_repository/pom.xml
+++ b/src-java/drafter_sparql_repository/pom.xml
@@ -40,9 +40,9 @@
NOTE: this version of sesame should be kept in sync with the version in the parent
leiningen project.clj.
-->
- org.openrdf.sesame
- sesame-runtime
- 2.8.11
+ org.eclipse.rdf4j
+ rdf4j-runtime
+ 2.2.2
diff --git a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLConnection.java b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLConnection.java
index ee1e0d342..9d1e9fde2 100644
--- a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLConnection.java
+++ b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLConnection.java
@@ -1,14 +1,16 @@
package drafter.rdf;
-import org.openrdf.query.*;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sparql.SPARQLConnection;
-import org.openrdf.repository.sparql.SPARQLRepository;
-import org.openrdf.http.client.SparqlSession;
+import org.eclipse.rdf4j.http.client.SPARQLProtocolSession;
+import org.eclipse.rdf4j.query.*;
+import org.eclipse.rdf4j.repository.RepositoryException;
+import org.eclipse.rdf4j.repository.sparql.SPARQLConnection;
+import org.eclipse.rdf4j.repository.sparql.SPARQLRepository;
+import org.eclipse.rdf4j.http.client.SPARQLProtocolSession;
+
public class DrafterSPARQLConnection extends SPARQLConnection {
- public DrafterSPARQLConnection(SPARQLRepository repository, SparqlSession sparqlSession) {
+ public DrafterSPARQLConnection(SPARQLRepository repository, SPARQLProtocolSession sparqlSession) {
super(repository, sparqlSession);
}
diff --git a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLRepository.java b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLRepository.java
index 743a89028..0c38b3986 100644
--- a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLRepository.java
+++ b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSPARQLRepository.java
@@ -2,15 +2,15 @@
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClients;
-import org.openrdf.http.client.SesameClient;
-import org.openrdf.model.vocabulary.SESAME;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.repository.sparql.SPARQLRepository;
+import org.eclipse.rdf4j.http.client.HttpClientSessionManager;
+import org.eclipse.rdf4j.http.client.SesameClient;
+import org.eclipse.rdf4j.repository.RepositoryConnection;
+import org.eclipse.rdf4j.repository.RepositoryException;
+import org.eclipse.rdf4j.repository.sparql.SPARQLRepository;
public class DrafterSPARQLRepository extends SPARQLRepository {
- private SesameClient sesameClient;
+ private HttpClientSessionManager httpClientManager;
private Integer maxConcurrentHttpConnections;
public DrafterSPARQLRepository(String queryEndpoint) { super(queryEndpoint); }
@@ -18,26 +18,41 @@ public DrafterSPARQLRepository(String queryEndpoint, String updateEndpoint) {
super(queryEndpoint, updateEndpoint);
}
- @Override public RepositoryConnection getConnection() throws RepositoryException {
- if(!this.isInitialized()) {
- throw new RepositoryException("SPARQLRepository not initialized.");
- } else {
- return new DrafterSPARQLConnection(this, createHTTPClient());
- }
- }
+ @Override public RepositoryConnection getConnection() throws RepositoryException {
+ if(!this.isInitialized()) {
+ throw new RepositoryException("SPARQLRepository not initialized.");
+ } else {
+ return new DrafterSPARQLConnection(this, createHTTPClient());
+ }
+ }
- @Override public synchronized SesameClient getSesameClient() {
- if (this.sesameClient == null) {
- HttpClient httpClient = newHttpClient();
- this.sesameClient = new DrafterSesameClientImpl(httpClient);
- }
- return this.sesameClient;
- }
+ public synchronized HttpClientSessionManager getHttpClientSessionManager() {
+ if (this.httpClientManager == null) {
+ HttpClient httpClient = newHttpClient();
+ this.httpClientManager = new DrafterSesameClientImpl(httpClient);
+ }
+ return this.httpClientManager;
+ }
- @Override public synchronized void setSesameClient(SesameClient client) {
- this.sesameClient = client;
+// @Override public synchronized SesameClient getSesameClient() {
+// if (this.httpClientManager == null) {
+// HttpClient httpClient = newHttpClient();
+// this.httpClientManager = new DrafterSesameClientImpl(httpClient);
+// }
+// return this.httpClientManager;
+// }
+
+
+ @Override public synchronized void setHttpClientSessionManager(HttpClientSessionManager httpMan) {
+ this.httpClientManager = httpMan;
}
+
+//
+// @Override public synchronized void setSesameClient(SesameClient client) {
+// this.httpClientManager = client;
+// }
+
/**
* Gets the maximum number of concurrent TCP connections created per route
* in the HTTP client used by this repository.
@@ -60,6 +75,7 @@ public synchronized void setMaxConcurrentHttpConnections(Integer maxConcurrentHt
this.setSesameClient(null);
}
+ // Fix for: https://github.com/eclipse/rdf4j/issues/367
private synchronized HttpClient newHttpClient() {
//the 'system' HTTP client uses the http.maxConnections
//system property to define the size of its connection pool (5 is the default
diff --git a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSesameClientImpl.java b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSesameClientImpl.java
index 8daa22df0..d345b35b4 100644
--- a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSesameClientImpl.java
+++ b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSesameClientImpl.java
@@ -1,14 +1,15 @@
package drafter.rdf;
import org.apache.http.client.HttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.openrdf.http.client.SesameClientImpl;
-import org.openrdf.http.client.SparqlSession;
+import org.eclipse.rdf4j.http.client.SPARQLProtocolSession;
+import org.eclipse.rdf4j.http.client.SharedHttpClientSessionManager;
+import org.eclipse.rdf4j.http.client.SparqlSession;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
-public class DrafterSesameClientImpl extends SesameClientImpl {
+//public class DrafterSesameClientImpl extends SesameClientImpl {
+public class DrafterSesameClientImpl extends SharedHttpClientSessionManager {
private static final ExecutorService QUERY_EXECUTOR = Executors.newCachedThreadPool();
@@ -16,12 +17,20 @@ public DrafterSesameClientImpl(HttpClient httpClient) {
this.setHttpClient(httpClient);
}
- @Override public synchronized SparqlSession createSparqlSession(String queryEndpointUrl, String updateEndpointUrl) {
- //NOTE: The two-argument constructor (HttpClient, ExecutorService) of SesameClientImpl does not seem to be
- //used and the executor is created by the initialize() method called from the default constructor. initialize()
- //sets the executor to Executors.newCachedThreadPool()
- //ExecutorService executor = Executors.newCachedThreadPool();
+ @Override public SPARQLProtocolSession createSPARQLProtocolSession(String queryEndpointUrl, String updateEndpointUrl) {
+ DrafterSparqlSession session = new DrafterSparqlSession(queryEndpointUrl, updateEndpointUrl, this.getHttpClient(), QUERY_EXECUTOR);
- return new DrafterSparqlSession(queryEndpointUrl, updateEndpointUrl, this.getHttpClient(), QUERY_EXECUTOR);
+ //session.setQueryURL(queryEndpointUrl);
+ //session.setUpdateURL(updateEndpointUrl);
+ return session;
}
+
+// @Override public synchronized SparqlSession createSparqlSession(String queryEndpointUrl, String updateEndpointUrl) {
+// //NOTE: The two-argument constructor (HttpClient, ExecutorService) of SesameClientImpl does not seem to be
+// //used and the executor is created by the initialize() method called from the default constructor. initialize()
+// //sets the executor to Executors.newCachedThreadPool()
+// //ExecutorService executor = Executors.newCachedThreadPool();
+//
+// return new DrafterSparqlSession(queryEndpointUrl, updateEndpointUrl, this.getHttpClient(), QUERY_EXECUTOR);
+// }
}
diff --git a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSparqlSession.java b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSparqlSession.java
index 48405c375..6a113897d 100644
--- a/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSparqlSession.java
+++ b/src-java/drafter_sparql_repository/src/main/java/drafter/rdf/DrafterSparqlSession.java
@@ -13,15 +13,16 @@
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
-import org.openrdf.OpenRDFException;
-import org.openrdf.http.client.SparqlSession;
-import org.openrdf.http.protocol.UnauthorizedException;
-import org.openrdf.http.protocol.error.ErrorInfo;
-import org.openrdf.http.protocol.error.ErrorType;
-import org.openrdf.query.*;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.rio.RDFParseException;
-import org.openrdf.rio.UnsupportedRDFormatException;
+import org.eclipse.rdf4j.OpenRDFException;
+import org.eclipse.rdf4j.http.client.SPARQLProtocolSession;
+import org.eclipse.rdf4j.http.client.SparqlSession;
+import org.eclipse.rdf4j.http.protocol.UnauthorizedException;
+import org.eclipse.rdf4j.http.protocol.error.ErrorInfo;
+import org.eclipse.rdf4j.http.protocol.error.ErrorType;
+import org.eclipse.rdf4j.query.*;
+import org.eclipse.rdf4j.repository.RepositoryException;
+import org.eclipse.rdf4j.rio.RDFParseException;
+import org.eclipse.rdf4j.rio.UnsupportedRDFormatException;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -30,12 +31,12 @@
import java.util.List;
import java.util.concurrent.ExecutorService;
-public class DrafterSparqlSession extends SparqlSession {
+public class DrafterSparqlSession extends SPARQLProtocolSession /*SparqlSession*/ {
/**
* The longest URL length accepted by stardog. SPARQL queries which result in a URL longer than this length
* should be sent as POST requests instead.
*/
- public static final int STARDOG_MAXIMUM_URL_LENGTH = 4083;
+ //public static final int STARDOG_MAXIMUM_URL_LENGTH = 4083;
public DrafterSparqlSession(String queryEndpointUrl, String updateEndpointUrl, HttpClient client, ExecutorService executor) {
super(client, executor);
@@ -79,7 +80,7 @@ private HttpParams getHttpParams() {
}
private HttpClientContext getHttpContext() {
- return readField(SparqlSession.class, this, "httpContext");
+ return readField(SPARQLProtocolSession.class, this, "httpContext");
}
/**
@@ -144,9 +145,9 @@ private static void removeTimeoutQueryParams(List queryPairs) {
* @param query The SPARQL query
* @return Whether to use a POST request to submit the query
*/
- @Override protected boolean shouldUsePost(String query) {
- return query.length() > STARDOG_MAXIMUM_URL_LENGTH;
- }
+ // @Override protected boolean shouldUsePost(String query) {
+ // return query.length() > STARDOG_MAXIMUM_URL_LENGTH;
+ // }
@SuppressWarnings("deprecation")
@Override protected HttpResponse execute(HttpUriRequest method) throws IOException, OpenRDFException {
diff --git a/src/drafter/backend/endpoints.clj b/src/drafter/backend/endpoints.clj
index c42b251fb..6c66bbc04 100644
--- a/src/drafter/backend/endpoints.clj
+++ b/src/drafter/backend/endpoints.clj
@@ -10,7 +10,7 @@
[protocols :as proto]
[repository :as repo]]
[schema.core :as s])
- (:import org.openrdf.model.URI))
+ (:import org.eclipse.rdf4j.model.URI))
(require 'drafter.backend.repository)
diff --git a/src/drafter/backend/repository.clj b/src/drafter/backend/repository.clj
index 40f8470b2..a699b7417 100644
--- a/src/drafter/backend/repository.clj
+++ b/src/drafter/backend/repository.clj
@@ -3,7 +3,7 @@
type."
(:require [drafter.backend.protocols :refer :all]
[drafter.rdf.sesame :as ses])
- (:import org.openrdf.repository.Repository))
+ (:import org.eclipse.rdf4j.repository.Repository))
(extend-type Repository
SparqlExecutor
diff --git a/src/drafter/backend/sesame/remote.clj b/src/drafter/backend/sesame/remote.clj
index f51996b8c..e0109a782 100644
--- a/src/drafter/backend/sesame/remote.clj
+++ b/src/drafter/backend/sesame/remote.clj
@@ -3,11 +3,11 @@
[clojure.tools.logging :as log]
[grafter.rdf.repository.registry :as reg])
(:import drafter.rdf.DrafterSPARQLRepository
- [org.openrdf.query.resultio.sparqljson SPARQLBooleanJSONParserFactory SPARQLResultsJSONParserFactory]
- [org.openrdf.query.resultio.sparqlxml SPARQLBooleanXMLParserFactory SPARQLResultsXMLParserFactory]
- org.openrdf.query.resultio.text.BooleanTextParserFactory
- org.openrdf.rio.nquads.NQuadsParserFactory
- org.openrdf.rio.ntriples.NTriplesParserFactory))
+ [org.eclipse.rdf4j.query.resultio.sparqljson SPARQLBooleanJSONParserFactory SPARQLResultsJSONParserFactory]
+ [org.eclipse.rdf4j.query.resultio.sparqlxml SPARQLBooleanXMLParserFactory SPARQLResultsXMLParserFactory]
+ org.eclipse.rdf4j.query.resultio.text.BooleanTextParserFactory
+ org.eclipse.rdf4j.rio.nquads.NQuadsParserFactory
+ org.eclipse.rdf4j.rio.ntriples.NTriplesParserFactory))
(defn get-required-configuration-setting [var-key config]
(if-let [ev (var-key config)]
diff --git a/src/drafter/errors.clj b/src/drafter/errors.clj
index e8be942d2..e1183dfdd 100644
--- a/src/drafter/errors.clj
+++ b/src/drafter/errors.clj
@@ -13,7 +13,7 @@ overly-specific in your interpretation of the error."
[errors :refer [encode-error]]
[responses :as r]]))
-(defmethod encode-error org.openrdf.query.QueryEvaluationException [ex]
+(defmethod encode-error org.eclipse.rdf4j.query.QueryEvaluationException [ex]
;; This exception should also be caught in specific routes concerned with
;; SPARQL endpoints, here we use this to unpack our ConnectionPoolTimeoutException.
diff --git a/src/drafter/middleware.clj b/src/drafter/middleware.clj
index 9b1a17c3f..3a3fdc2f7 100644
--- a/src/drafter/middleware.clj
+++ b/src/drafter/middleware.clj
@@ -10,7 +10,7 @@
[drafter.user :as user]
[drafter.user.repository :as user-repo]
[drafter.rdf.sesame :refer [read-statements] :as ses]
- [grafter.rdf.io :refer [mimetype->rdf-format]]
+ [grafter.rdf.formats :refer [mimetype->rdf-format]]
[buddy.auth :as auth]
[buddy.auth.protocols :as authproto]
[buddy.auth.backends.httpbasic :refer [http-basic-backend]]
diff --git a/src/drafter/rdf/content_negotiation.clj b/src/drafter/rdf/content_negotiation.clj
index bebd1d30c..1e92e04e9 100644
--- a/src/drafter/rdf/content_negotiation.clj
+++ b/src/drafter/rdf/content_negotiation.clj
@@ -1,8 +1,8 @@
(ns drafter.rdf.content-negotiation
(:require [ring.middleware.accept :refer [wrap-accept]]
[drafter.rdf.formats :refer [csv-rdf-format tsv-rdf-format]])
- (:import [org.openrdf.query.resultio BooleanQueryResultFormat TupleQueryResultFormat]
- [org.openrdf.rio RDFFormat]))
+ (:import [org.eclipse.rdf4j.query.resultio BooleanQueryResultFormat TupleQueryResultFormat]
+ [org.eclipse.rdf4j.rio RDFFormat]))
(defn- format-preferences->mime-spec [format-prefs]
(into {} (mapcat (fn [[f q]] (map (fn [m] [m [f q]]) (.getMIMETypes f))) format-prefs)))
diff --git a/src/drafter/rdf/draft_management.clj b/src/drafter/rdf/draft_management.clj
index ca6b8671e..e07d4bebd 100644
--- a/src/drafter/rdf/draft_management.clj
+++ b/src/drafter/rdf/draft_management.clj
@@ -1,13 +1,15 @@
(ns drafter.rdf.draft-management
(:require [clojure
- [set :as set]]
+ [set :as set]
+ [string :as str]]
[clojure.tools.logging :as log]
[drafter.backend.protocols :refer [->repo-connection ->sesame-repo]]
+ [drafter.rdf.sparql :as sparql]
[drafter.rdf
[drafter-ontology :refer :all]
[sparql :refer [update!]]]
[drafter.util :as util]
- [grafter.rdf :refer [add]]
+ [grafter.rdf :as rdf]
[grafter.rdf
[repository :as repo]
[templater :refer [add-properties graph]]]
@@ -40,14 +42,14 @@
" }")))
(defn is-graph-managed? [db graph-uri]
- (repo/query db
+ (sparql/eager-query db
(str "ASK WHERE {"
(with-state-graph
"<" graph-uri "> a <" drafter:ManagedGraph "> ."
"}"))))
(defn is-graph-live? [db graph-uri]
- (repo/query db
+ (sparql/eager-query db
(str "ASK WHERE {"
(with-state-graph
" <" graph-uri "> a <" drafter:ManagedGraph "> ."
@@ -67,12 +69,12 @@
" }"
" HAVING (?numberOfRefs > 1)"
"}")]
- (repo/query db qry)))
+ (sparql/eager-query db qry)))
(defn graph-exists?
"Checks that a graph exists"
[db graph-uri]
- (repo/query db
+ (sparql/eager-query db
(str "ASK WHERE {"
" SELECT ?s ?p ?o WHERE {"
" GRAPH <" graph-uri "> { ?s ?p ?o }"
@@ -97,7 +99,7 @@
;; the managed graph(?). Ideally, we'd do this as a single INSERT/WHERE statement.
(if (not (is-graph-managed? db graph-uri))
(let [managed-graph-quads (to-quads (create-managed-graph graph-uri))]
- (add db managed-graph-quads)))
+ (sparql/add db managed-graph-quads)))
graph-uri)
(defn create-draft-graph
@@ -131,7 +133,7 @@
draftset-uri (some-> draftset-ref (url/->java-uri))
triple-templates (create-draft-graph live-graph-uri draft-graph-uri now draftset-uri)
quads (apply to-quads triple-templates)]
- (add db quads)
+ (sparql/add db quads)
draft-graph-uri)))
@@ -275,7 +277,7 @@
"?live a <" drafter:ManagedGraph "> ;"
" <" drafter:hasDraft "> <" draft-graph-uri "> . ")
"} LIMIT 1")]
- (-> (doall (repo/query db q))
+ (-> (sparql/eager-query db q)
first
(:live))))
@@ -320,14 +322,14 @@
[db draft-set]
(if (empty? draft-set)
{}
- (let [drafts (clojure.string/join " " (map #(str "<" % ">") draft-set))
+ (let [drafts (str/join " " (map #(str "<" % ">") draft-set))
q (str "SELECT ?live ?draft WHERE {"
(with-state-graph
" VALUES ?draft {" drafts "}"
" ?live a <" drafter:ManagedGraph "> ;"
" <" drafter:hasDraft "> ?draft .")
"}")
- results (->> (doall (grafter.rdf.repository/query db q)))]
+ results (sparql/eager-query db q)]
(let [live-graphs (map :live results)]
(when (has-duplicates? live-graphs)
@@ -346,7 +348,7 @@
"?live a <" drafter:ManagedGraph "> ;"
" <" drafter:isPublic "> " online " .")
"}")
- results (repo/query db q)]
+ results (sparql/eager-query db q)]
(into #{} (map :live results))))
(defn graph-non-empty-query [graph-uri]
@@ -360,7 +362,7 @@
(defn graph-non-empty?
"Returns true if the graph contains any statements."
[repo graph-uri]
- (repo/query repo (graph-non-empty-query graph-uri)))
+ (sparql/eager-query repo (graph-non-empty-query graph-uri)))
(defn graph-empty?
"Returns true if there are no statements in the associated graph."
@@ -466,4 +468,4 @@
;;true for all current backends.
(with-open [conn (->repo-connection backend)]
(repo/with-transaction conn
- (add conn graph-uri triple-batch)))))
+ (sparql/add conn graph-uri triple-batch)))))
diff --git a/src/drafter/rdf/draftset_management.clj b/src/drafter/rdf/draftset_management.clj
index 216a8c616..d6663f779 100644
--- a/src/drafter/rdf/draftset_management.clj
+++ b/src/drafter/rdf/draftset_management.clj
@@ -15,7 +15,7 @@
[sparql :as sparql]]
[drafter.rdf.draft-management.jobs :as jobs]
[drafter.rdf.rewriting.result-rewriting :refer [rewrite-statement]]
- [grafter.rdf :refer [add context]]
+ [grafter.rdf :refer [context] :as rdf]
[grafter.rdf
[io :refer [IStatement->sesame-statement rdf-serializer]]
[protocols :refer [map->Quad map->Triple]]
@@ -26,10 +26,10 @@
[grafter.url :as url])
(:import [java.util Date UUID]
[java.io StringWriter]
- org.openrdf.model.impl.ContextStatementImpl
- org.openrdf.model.Resource
- [org.openrdf.query GraphQuery TupleQueryResultHandler]
- org.openrdf.queryrender.RenderUtils))
+ org.eclipse.rdf4j.model.impl.ContextStatementImpl
+ org.eclipse.rdf4j.model.Resource
+ [org.eclipse.rdf4j.query GraphQuery TupleQueryResultHandler]
+ org.eclipse.rdf4j.queryrender.RenderUtils))
(defn- create-draftset-statements [user-uri title description draftset-uri created-date]
(let [ss [draftset-uri
@@ -49,11 +49,12 @@
([db creator title] (create-draftset! db creator title nil))
([db creator title description] (create-draftset! db creator title description (UUID/randomUUID) (Date.)))
([db creator title description draftset-id created-date]
- (let [user-uri (user/user->uri creator)
- template (create-draftset-statements user-uri title description (url/append-path-segments draftset-uri draftset-id) created-date)
- quads (to-quads template)]
- (add db quads)
- (ds/->DraftsetId (str draftset-id)))))
+ (with-open [dbcon (repo/->connection db)]
+ (let [user-uri (user/user->uri creator)
+ template (create-draftset-statements user-uri title description (url/append-path-segments draftset-uri draftset-id) created-date)
+ quads (to-quads template)]
+ (rdf/add dbcon quads)
+ (ds/->DraftsetId (str draftset-id))))))
(defn- graph-exists-query [graph-uri]
(str
@@ -69,7 +70,7 @@
(defn draftset-exists? [db draftset-ref]
(let [q (draftset-exists-query draftset-ref)]
- (repo/query db q)))
+ (sparql/eager-query db q)))
(defn- delete-draftset-statements-query [draftset-ref]
(let [ds-uri (str (ds/->draftset-uri draftset-ref))]
@@ -111,7 +112,7 @@
(defn get-draftset-owner [backend draftset-ref]
(let [q (get-draftset-owner-query draftset-ref)
- result (first (sparql/query-eager-seq backend q))]
+ result (first (sparql/eager-query backend q))]
(when-let [owner-uri (:owner result)]
(user/uri->username owner-uri))))
@@ -135,7 +136,7 @@
{:live-graph-uri lg
:draft-graph-uri dg
:public public
- :draft-graph-exists (repo/query repo (graph-exists-query dg))})
+ :draft-graph-exists (sparql/eager-query repo (graph-exists-query dg))})
(defn- union-clauses [clauses]
(string/join " UNION " clauses))
@@ -195,7 +196,7 @@
(defn get-draftset-graph-states [repo draftset-ref]
(let [q (get-draftset-graph-mapping-query draftset-ref)]
(->> q
- (sparql/query-eager-seq repo)
+ (sparql/eager-query repo)
(map #(graph-mapping-result->graph-state repo %)))))
(defn get-draftset-graph-mapping [repo draftset-ref]
@@ -280,11 +281,11 @@
(defn- get-all-draftsets-properties-by [repo clauses]
(let [properties-query (get-draftsets-matching-properties-query clauses)]
- (sparql/query-eager-seq repo properties-query)))
+ (sparql/eager-query repo properties-query)))
(defn- get-all-draftsets-mappings-by [repo clauses]
(let [mappings-query (get-draftsets-matching-graph-mappings-query clauses)]
- (sparql/query-eager-seq repo mappings-query)))
+ (sparql/eager-query repo mappings-query)))
(defn- get-all-draftsets-by [repo clauses]
(let [properties (get-all-draftsets-properties-by repo clauses)
@@ -522,7 +523,7 @@
contain a draft for the graph."
[backend draftset-ref live-graph]
(let [q (find-draftset-draft-graph-query draftset-ref live-graph)
- [result] (sparql/query-eager-seq backend q)]
+ [result] (sparql/eager-query backend q)]
(:dg result)))
(defn revert-graph-changes!
@@ -595,7 +596,7 @@
{:graph-uri graph-uri :triples (map map->Triple quads)}
(let [sw (StringWriter.)
msg (format "All statements must have an explicit target graph")]
- (add (rdf-serializer sw :format formats/rdf-nquads) (take 5 quads))
+ (rdf/add (rdf-serializer sw :format formats/rdf-nquads) (take 5 quads))
(throw (IllegalArgumentException.
(str "All statements must have an explicit target graph. The following statements have no graph:\n" sw)))))))
@@ -609,7 +610,7 @@
(when-not (empty? triple-batch)
;;WARNING: This assumes the backend is a sesame backend which is
;;true for all current backends.
- (add conn graph-uri triple-batch)))
+ (sparql/add conn graph-uri triple-batch)))
(defn- append-draftset-quads*
[quad-batches live->draft backend job-started-at job draftset-ref state]
diff --git a/src/drafter/rdf/formats.clj b/src/drafter/rdf/formats.clj
index cb60347db..a8d710cb6 100644
--- a/src/drafter/rdf/formats.clj
+++ b/src/drafter/rdf/formats.clj
@@ -1,5 +1,5 @@
(ns drafter.rdf.formats
- (:import [org.openrdf.rio RDFFormat]
+ (:import [org.eclipse.rdf4j.rio RDFFormat]
[java.nio.charset Charset]))
(def ^:private ascii (Charset/forName "US-ASCII"))
diff --git a/src/drafter/rdf/rewriting/result_rewriting.clj b/src/drafter/rdf/rewriting/result_rewriting.clj
index fac634e10..27506011e 100644
--- a/src/drafter/rdf/rewriting/result_rewriting.clj
+++ b/src/drafter/rdf/rewriting/result_rewriting.clj
@@ -5,10 +5,10 @@
[clojure.tools.logging :as log]
[drafter.util :as util]
[grafter.rdf.protocols :refer [map->Quad]])
- (:import [org.openrdf.model.impl ContextStatementImpl StatementImpl]
- [org.openrdf.query BooleanQuery GraphQuery TupleQuery TupleQueryResultHandler]
- [org.openrdf.query.impl BindingImpl MapBindingSet]
- org.openrdf.rio.RDFHandler))
+ (:import [org.eclipse.rdf4j.model.impl ContextStatementImpl StatementImpl]
+ [org.eclipse.rdf4j.query BooleanQuery GraphQuery TupleQuery TupleQueryResultHandler]
+ [org.eclipse.rdf4j.query.impl BindingImpl MapBindingSet]
+ org.eclipse.rdf4j.rio.RDFHandler))
(defn- rewrite-binding
"Rewrites the value of a Binding if it appears in the given graph map"
diff --git a/src/drafter/rdf/sesame.clj b/src/drafter/rdf/sesame.clj
index ac08c9207..0a16a2f5e 100644
--- a/src/drafter/rdf/sesame.clj
+++ b/src/drafter/rdf/sesame.clj
@@ -5,11 +5,11 @@
[drafter.rdf.rewriting.arq :refer [sparql-string->arq-query]]
[grafter.rdf :refer [statements]]
[grafter.rdf.repository :as repo])
- (:import [org.openrdf.query BooleanQuery Dataset GraphQuery TupleQuery TupleQueryResultHandler Update]
- org.openrdf.query.resultio.QueryResultIO
- org.openrdf.repository.Repository
- org.openrdf.repository.sparql.SPARQLRepository
- [org.openrdf.rio RDFHandler Rio]))
+ (:import [org.eclipse.rdf4j.query BooleanQuery Dataset GraphQuery TupleQuery TupleQueryResultHandler Update]
+ org.eclipse.rdf4j.query.resultio.QueryResultIO
+ org.eclipse.rdf4j.repository.Repository
+ org.eclipse.rdf4j.repository.sparql.SPARQLRepository
+ [org.eclipse.rdf4j.rio RDFHandler Rio]))
(defn is-quads-format? [rdf-format]
(.supportsContexts rdf-format))
diff --git a/src/drafter/rdf/sparql.clj b/src/drafter/rdf/sparql.clj
index 12394658b..007fbd919 100644
--- a/src/drafter/rdf/sparql.clj
+++ b/src/drafter/rdf/sparql.clj
@@ -2,21 +2,38 @@
(:require [clojure.tools.logging :as log]
[cognician.dogstatsd :as datadog]
[drafter.rdf.drafter-ontology :refer :all]
+ [grafter.rdf :as rdf]
[grafter.rdf.protocols :as pr]
- [grafter.rdf.repository :as repo]))
+ [grafter.rdf.repository :as repo]
+ [medley.core :as med]))
-(defn query-eager-seq
+(defn eager-query
"Executes a SPARQL query which returns a sequence of results and
ensures it is eagerly consumed before being returned. The underlying
TCP connection is not released until all results have been iterated
over so this prevents holding connections open longer than
necessary."
- [repo query-string]
- (with-open [conn (repo/->connection repo)]
- (doall (repo/query conn query-string))))
+
+ ([repo query-str]
+ (eager-query repo query-str {}))
+ ([repo query-str opts]
+ (with-open [conn (repo/->connection repo)]
+ (let [res (med/mapply repo/query conn query-str opts)]
+ (if (seq? res)
+ (doall res)
+ res)))))
(defn update! [repo update-string]
(log/info "Running update: " update-string)
(datadog/measure!
"drafter.sparql.update.time" {}
- (pr/update! repo update-string)))
+ (with-open [conn (repo/->connection repo)]
+ (pr/update! conn update-string))))
+
+(defn add
+ ([db triples]
+ (with-open [conn (repo/->connection db)]
+ (rdf/add conn triples)))
+ ([db graph-uri triples]
+ (with-open [conn (repo/->connection db)]
+ (rdf/add conn graph-uri triples))))
diff --git a/src/drafter/rdf/sparql_protocol.clj b/src/drafter/rdf/sparql_protocol.clj
index 5862b8a4e..54f0f92ad 100644
--- a/src/drafter/rdf/sparql_protocol.clj
+++ b/src/drafter/rdf/sparql_protocol.clj
@@ -11,8 +11,8 @@
[create-signalling-query-handler get-query-type]])
(:import [java.io ByteArrayOutputStream PipedInputStream PipedOutputStream]
java.util.concurrent.TimeUnit
- org.openrdf.query.QueryInterruptedException
- org.openrdf.query.resultio.QueryResultIO))
+ org.eclipse.rdf4j.query.QueryInterruptedException
+ org.eclipse.rdf4j.query.resultio.QueryResultIO))
(defn- execute-boolean-query [pquery result-format response-content-type]
(let [os (ByteArrayOutputStream. 1024)
diff --git a/src/drafter/rdf/writers.clj b/src/drafter/rdf/writers.clj
index 598f8d0b0..69819bb57 100644
--- a/src/drafter/rdf/writers.clj
+++ b/src/drafter/rdf/writers.clj
@@ -1,10 +1,10 @@
(ns drafter.rdf.writers
(:require [drafter.rdf.formats :refer [csv-rdf-format tsv-rdf-format]])
(:import [java.io OutputStream Writer]
- [org.openrdf.query.impl MapBindingSet]
- [org.openrdf.query.resultio.text.csv SPARQLResultsCSVWriter]
- [org.openrdf.query.resultio.text.tsv SPARQLResultsTSVWriter]
- [org.openrdf.rio RDFWriter RDFWriterFactory RDFWriterRegistry]))
+ [org.eclipse.rdf4j.query.impl MapBindingSet]
+ [org.eclipse.rdf4j.query.resultio.text.csv SPARQLResultsCSVWriter]
+ [org.eclipse.rdf4j.query.resultio.text.tsv SPARQLResultsTSVWriter]
+ [org.eclipse.rdf4j.rio RDFWriter RDFWriterFactory RDFWriterRegistry]))
(defn- query-result-writer->rdf-writer [rdf-format result-writer]
(reify RDFWriter
diff --git a/src/drafter/routes/draftsets_api.clj b/src/drafter/routes/draftsets_api.clj
index 8c259d591..62ac5a279 100644
--- a/src/drafter/routes/draftsets_api.clj
+++ b/src/drafter/routes/draftsets_api.clj
@@ -13,7 +13,9 @@
[sesame :refer [is-quads-format? is-triples-format?]]
[sparql-protocol :refer [sparql-execution-handler sparql-protocol-handler]]]
[drafter.rdf.draft-management.jobs :refer [failed-job-result? make-job]]
- )
+
+ [grafter.rdf.protocols :as pr]
+ [grafter.rdf.repository :as repo])
(:require [compojure.core :refer [ANY GET POST PUT DELETE context routes]]
[ring.util.response :refer [redirect-after-post not-found response]]
[drafter.responses :refer [not-acceptable-response unprocessable-entity-response
diff --git a/src/drafter/util.clj b/src/drafter/util.clj
index b9dba0613..ddc396ae9 100644
--- a/src/drafter/util.clj
+++ b/src/drafter/util.clj
@@ -6,7 +6,7 @@
[buddy.core.codecs :as codecs])
(:import java.nio.charset.Charset
[javax.mail.internet AddressException InternetAddress]
- org.openrdf.model.impl.URIImpl))
+ org.eclipse.rdf4j.model.impl.URIImpl))
(defn str->base64 [s]
(codecs/bytes->str (base64/encode s)))
diff --git a/test/drafter/rdf/draft_management_test.clj b/test/drafter/rdf/draft_management_test.clj
index ce1c704eb..270e165e6 100644
--- a/test/drafter/rdf/draft_management_test.clj
+++ b/test/drafter/rdf/draft_management_test.clj
@@ -11,7 +11,6 @@
[grafter.vocabularies.dcterms :refer [dcterms:issued dcterms:modified]]
[drafter.test-helpers.draft-management-helpers :as mgmt]
[drafter.draftset :refer [->DraftsetId]]
- [grafter.rdf :refer [add]]
[grafter.rdf
[repository :as repo]
[templater :refer [triplify]]]
@@ -241,21 +240,21 @@
(deftest graph-restricted-queries-test
(testing "query"
(testing "supports graph restriction"
- (add *test-backend* "http://example.org/graph/1"
+ (sparql/add *test-backend* "http://example.org/graph/1"
test-triples)
- (add *test-backend* "http://example.org/graph/2"
+ (sparql/add *test-backend* "http://example.org/graph/2"
test-triples-2)
- (is (repo/query *test-backend*
+ (is (sparql/eager-query *test-backend*
(str "ASK WHERE {
GRAPH {
?s ?p ?o .
}
- }") :named-graphs ["http://example.org/graph/2"])
+ }") {:named-graphs ["http://example.org/graph/2"]})
"Can query triples in named graph 2")
- (is (repo/query *test-backend*
+ (is (sparql/eager-query *test-backend*
(str "ASK WHERE {
GRAPH {
?p1 ?o1 .
@@ -263,35 +262,35 @@
GRAPH {
?p2 ?o2 .
}
- }") :named-graphs ["http://example.org/graph/1" "http://example.org/graph/2"])
+ }") {:named-graphs ["http://example.org/graph/1" "http://example.org/graph/2"]})
"Can specify many named graphs as a query restriction.")
- (is (= false (repo/query *test-backend*
+ (is (= false (sparql/eager-query *test-backend*
(str "ASK WHERE {
GRAPH {
?s ?p ?o .
}
}")
- :named-graphs ["http://example.org/graph/1"]))
+ {:named-graphs ["http://example.org/graph/1"]}))
"Can't query triples in named graph 2")
- (is (= false (repo/query *test-backend*
+ (is (= false (sparql/eager-query *test-backend*
(str "ASK WHERE {
?s ?p ?o .
- }") :default-graph []))
+ }") {:default-graph []}))
"Can't query triples in union graph")
- (is (repo/query *test-backend*
+ (is (sparql/eager-query *test-backend*
(str "ASK WHERE {
?s ?p ?o .
- }") :default-graph ["http://example.org/graph/1"])
+ }") {:default-graph ["http://example.org/graph/1"]})
"Can query triples in union graph")
- (is (repo/query *test-backend*
+ (is (sparql/eager-query *test-backend*
(str "ASK WHERE {
?p1 ?o1 .
?p2 ?o2 .
- }") :default-graph ["http://example.org/graph/1" "http://example.org/graph/2"])
+ }") {:default-graph ["http://example.org/graph/1" "http://example.org/graph/2"]})
"Can set many graphs as union graph"))))
(deftest draft-graphs-test
@@ -323,15 +322,15 @@
(deftest upsert-single-object-insert-test
(let [db (repo/repo)]
(upsert-single-object! db "http://foo/" "http://bar/" "baz")
- (is (repo/query db "ASK { GRAPH { \"baz\"} }"))))
+ (is (sparql/eager-query db "ASK { GRAPH { \"baz\"} }"))))
(deftest upsert-single-object-update-test
(let [db (repo/repo)
subject (URI. "http://example.com/subject")
predicate (URI. "http://example.com/predicate")]
- (add db (triplify [subject [predicate "initial"]]))
+ (sparql/add db (triplify [subject [predicate "initial"]]))
(upsert-single-object! db subject predicate "updated")
- (is (repo/query db (str "ASK { GRAPH {"
+ (is (sparql/eager-query db (str "ASK { GRAPH {"
"<" subject "> <" predicate "> \"updated\""
"} }")))))
@@ -423,7 +422,7 @@
(set-modifed-at-on-draft-graph! *test-backend* draft-graph-uri (Date.))
- (is (repo/query *test-backend*
+ (is (sparql/eager-query *test-backend*
(str
"ASK {"
"<" draft-graph-uri "> <" drafter:modifiedAt "> ?modified . "
@@ -435,12 +434,12 @@
(deftest copy-graph-test
(let [repo (repo/repo)]
- (add repo (test-quads (URI. "http://test-graph/1")))
+ (sparql/add repo (test-quads (URI. "http://test-graph/1")))
(copy-graph repo "http://test-graph/1" "http://test-graph/2")
- (let [source-graph (set (repo/query repo "SELECT * WHERE { GRAPH { ?s ?p ?o }}"))
- dest-graph (set (repo/query repo "SELECT * WHERE { GRAPH { ?s ?p ?o }}"))]
+ (let [source-graph (set (sparql/eager-query repo "SELECT * WHERE { GRAPH { ?s ?p ?o }}"))
+ dest-graph (set (sparql/eager-query repo "SELECT * WHERE { GRAPH { ?s ?p ?o }}"))]
(is (not (empty? dest-graph))
"Should not be empty (and have the data we loaded)")
diff --git a/test/drafter/rdf/drafter_sparql_repository_test.clj b/test/drafter/rdf/drafter_sparql_repository_test.clj
index 779f2818b..2c1852e07 100644
--- a/test/drafter/rdf/drafter_sparql_repository_test.clj
+++ b/test/drafter/rdf/drafter_sparql_repository_test.clj
@@ -1,11 +1,12 @@
(ns drafter.rdf.drafter-sparql-repository-test
(:require [clojure.test :refer :all]
[drafter.test-common :as tc]
- [grafter.rdf.repository :as repo])
+ [grafter.rdf.repository :as repo]
+ [drafter.rdf.sparql :as sparql])
(:import drafter.rdf.DrafterSparqlSession
java.io.ByteArrayOutputStream
[java.util.concurrent CountDownLatch ExecutionException TimeUnit]
- org.openrdf.query.QueryInterruptedException))
+ org.eclipse.rdf4j.query.QueryInterruptedException))
(defn query-timeout-handler
"Handler which always returns a query timeout response in the format used by Stardog"
@@ -20,7 +21,7 @@
(testing "Raises QueryInterruptedException on timeout response"
(let [repo (tc/get-latched-http-server-repo test-port)]
(tc/with-server test-port query-timeout-handler
- (is (thrown? QueryInterruptedException (repo/query repo "SELECT * WHERE { ?s ?p ?o }"))))))
+ (is (thrown? QueryInterruptedException (sparql/eager-query repo "SELECT * WHERE { ?s ?p ?o }"))))))
(testing "sends timeout header when maxExecutionTime set"
(let [query-params (atom nil)
@@ -35,15 +36,17 @@
(let [query-params (atom nil)
repo (tc/get-latched-http-server-repo test-port)]
(tc/with-server test-port (tc/extract-query-params-handler query-params tc/ok-spo-query-response)
- (repo/query repo "SELECT * WHERE { ?s ?p ?o }")
+ (sparql/eager-query repo "SELECT * WHERE { ?s ?p ?o }")
(is (= false (contains? @query-params "timeout")))))))
+(def stardog-max-url-length 4083)
+
(deftest query-method-test
(testing "short query should be GET request"
(let [method (atom nil)
repo (tc/get-latched-http-server-repo test-port)]
(tc/with-server test-port (tc/extract-method-handler method tc/ok-spo-query-response)
- (repo/query repo "SELECT * WHERE { ?s ?p ?o }")
+ (sparql/eager-query repo "SELECT * WHERE { ?s ?p ?o }")
(is (= :get @method)))))
(testing "long query should be POST request"
@@ -53,13 +56,13 @@
method (atom nil)
repo (tc/get-latched-http-server-repo test-port)]
(loop [s bindings]
- (when (< (.length sb) DrafterSparqlSession/STARDOG_MAXIMUM_URL_LENGTH)
+ (when (< (.length sb) stardog-max-url-length)
(.append sb (first s))
(.append sb " ")
(recur (rest bindings))))
(.append sb "} ?u ?p ?o }")
(tc/with-server test-port (tc/extract-method-handler method tc/ok-spo-query-response)
- (repo/query repo (str sb))
+ (sparql/eager-query repo (str sb))
(is (= :post @method))))))
(defn- http-response->string [response]
@@ -69,7 +72,7 @@
(defn- make-blocking-connection [repo idx]
(future
- (repo/query repo "SELECT * WHERE { ?s ?p ?o }")
+ (sparql/eager-query repo "SELECT * WHERE { ?s ?p ?o }")
(keyword (str "future-" idx))))
(deftest connection-timeout
@@ -85,14 +88,16 @@
(do
;;server has accepted max number of connections so next query attempt should see a connection timeout
(let [rf (future
- (repo/query repo "SELECT * WHERE { ?s ?p ?o }"))]
+ (sparql/eager-query repo "SELECT * WHERE { ?s ?p ?o }"))]
;;should be rejected almost immediately
(try
(.get rf 5000 TimeUnit/MILLISECONDS)
(catch ExecutionException ex
(is (instance? QueryInterruptedException (.getCause ex))))
+ (catch java.util.concurrent.TimeoutException tex
+ (is (not tex) "Expected query to be rejected due to timeout"))
(catch Throwable ex
- (is false "Expected query to be rejected due to timeout"))))
+ (is (not ex) "Unexpected exception"))))
;;release previous connections and wait for them to complete
(.countDown release-latch)
diff --git a/test/drafter/rdf/draftset_management_test.clj b/test/drafter/rdf/draftset_management_test.clj
index c5c739aee..93bf9aa5f 100644
--- a/test/drafter/rdf/draftset_management_test.clj
+++ b/test/drafter/rdf/draftset_management_test.clj
@@ -8,28 +8,28 @@
[user-test :refer [test-editor test-manager test-publisher]]
[write-scheduler :as scheduler]]
[drafter.rdf
+ [sparql :as sparql]
[draft-management :as mgmt :refer [with-state-graph]]
[drafter-ontology :refer :all]
[draftset-management :refer :all]]
[drafter.test-helpers.draft-management-helpers :as mgmth]
[grafter.rdf :refer [context statements triple=]]
[grafter.rdf
- [protocols :refer [->Quad ->Triple]]
- [repository :refer [query]]]
+ [protocols :refer [->Quad ->Triple]]]
[grafter.vocabularies.rdf :refer :all]
[drafter.util :as util]
[grafter.url :as url])
- (:import org.openrdf.rio.RDFFormat
+ (:import org.eclipse.rdf4j.rio.RDFFormat
[java.net URI]))
(defn- has-uri-object? [s p uri-o]
- (query *test-backend* (str "ASK WHERE { <" s "> <" p "> <" uri-o "> }")))
+ (sparql/eager-query *test-backend* (str "ASK WHERE { <" s "> <" p "> <" uri-o "> }")))
(defn- has-string-object? [s p str-o]
- (query *test-backend* (str "ASK WHERE { <" s "> <" p "> \"" str-o "\" }")))
+ (sparql/eager-query *test-backend* (str "ASK WHERE { <" s "> <" p "> \"" str-o "\" }")))
(defn- has-any-object? [s p]
- (query *test-backend* (str "ASK WHERE { <" s "> <" p "> ?o }")))
+ (sparql/eager-query *test-backend* (str "ASK WHERE { <" s "> <" p "> ?o }")))
(defn- assert-user-is-creator-and-owner [user draftset-id]
(is (has-uri-object? (->draftset-uri draftset-id) drafter:createdBy (user/user->uri user)))
@@ -163,7 +163,7 @@
"<" (->draftset-uri draftset-id) "> <" drafter:hasSubmission "> ?submission ."
"?submission <" drafter:claimRole "> \"" (name role) "\" .")
"}")]
- (query *test-backend* q)))
+ (sparql/eager-query *test-backend* q)))
(deftest submit-draftset-to-role-test!
(testing "Existing owner"
@@ -189,7 +189,7 @@
"<" (->draftset-uri draftset-id) "> <" drafter:hasSubmission "> ?submission ."
"?submission <" drafter:claimUser "> <" (user/user->uri user) "> .")
"}")]
- (query *test-backend* q)))
+ (sparql/eager-query *test-backend* q)))
(defn is-draftset-submitter? [backend draftset-ref user]
(if-let [{:keys [submitted-by]} (get-draftset-info backend draftset-ref)]
@@ -239,7 +239,7 @@
"<" draftset-uri "> <" rdf:a "> <" drafter:DraftSet "> ."
"<" draftset-uri "> <" drafter:hasSubmission "> ?submission")
"}")]
- (query *test-backend* q)))
+ (sparql/eager-query *test-backend* q)))
(deftest claim-draftset-test!
(testing "No owner when user in role"
@@ -368,7 +368,7 @@
(is (= :not-found result))))
(defn- get-graph-triples [graph-uri]
- (let [results (query *test-backend* (select-all-in-graph graph-uri))]
+ (let [results (sparql/eager-query *test-backend* (select-all-in-graph graph-uri))]
(map (fn [{:keys [s p o]}] (->Triple s p o)) results)))
(deftest copy-live-graph-into-draftset-test
@@ -425,7 +425,7 @@
"} LIMIT 2")]
(let [res (-> *test-backend*
- (query modified-query))]
+ (sparql/eager-query modified-query))]
(assert (= 1 (count res)) "There were multiple modifiedAt timestamps, we expect just one.")
diff --git a/test/drafter/rdf/rewriting/result_rewriting_test.clj b/test/drafter/rdf/rewriting/result_rewriting_test.clj
index ebae16ef8..49365d0f9 100644
--- a/test/drafter/rdf/rewriting/result_rewriting_test.clj
+++ b/test/drafter/rdf/rewriting/result_rewriting_test.clj
@@ -14,7 +14,7 @@
[repository :as repo]
[templater :refer [triplify]]]
[schema.test :refer [validate-schemas]])
- (:import org.openrdf.model.impl.URIImpl
+ (:import org.eclipse.rdf4j.model.impl.URIImpl
[java.net URI]))
(use-fixtures :each validate-schemas)
diff --git a/test/drafter/rdf/sparql_protocol_test.clj b/test/drafter/rdf/sparql_protocol_test.clj
index 4466f730d..b0356c4b8 100644
--- a/test/drafter/rdf/sparql_protocol_test.clj
+++ b/test/drafter/rdf/sparql_protocol_test.clj
@@ -2,6 +2,7 @@
(:require [clojure-csv.core :as csv]
[clojure.test :refer :all]
[drafter.rdf.sparql-protocol :refer :all]
+ [drafter.rdf.sparql :as sparql]
[drafter.test-common :refer :all]
[grafter.rdf :as rdf]
[grafter.rdf
@@ -14,7 +15,7 @@
(use-fixtures :each validate-schemas)
(defn add-triple-to-db [db]
- (pr/add db (URI. "http://foo.com/my-graph") (test-triples (URI. "http://test.com/data/one"))))
+ (sparql/add db (URI. "http://foo.com/my-graph") (test-triples (URI. "http://test.com/data/one"))))
(deftest sparql-end-point-test
(let [end-point (sparql-end-point "/live/sparql" *test-backend*)]
diff --git a/test/drafter/routes/draftsets_api_test.clj b/test/drafter/routes/draftsets_api_test.clj
index a840929c1..3a1f909dd 100644
--- a/test/drafter/routes/draftsets_api_test.clj
+++ b/test/drafter/routes/draftsets_api_test.clj
@@ -11,6 +11,8 @@
[user :as user]
[user-test :refer [test-editor test-manager test-password test-publisher]]
[util :as util]]
+ [drafter.rdf
+ [sparql :as sparql]]
[drafter.rdf.draft-management.jobs :as jobs]
[drafter.rdf.drafter-ontology
:refer
@@ -29,8 +31,8 @@
[swirrl-server.async.jobs :refer [finished-jobs]])
(:import [java.io ByteArrayInputStream ByteArrayOutputStream]
java.util.Date
- org.openrdf.query.QueryResultHandler
- org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONParser
+ org.eclipse.rdf4j.query.QueryResultHandler
+ org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONParser
(java.net URI)))
(def ^:private ^:dynamic *route*)
@@ -563,7 +565,7 @@
;; test - so we can get away with a bit of
;; a sloppy query.
(-> *test-backend*
- (repo/query
+ (sparql/eager-query
(str "SELECT ?modified {"
" ?draftgraph a <" drafter:DraftGraph "> ;"
" <" drafter:modifiedAt "> ?modified ."
diff --git a/test/drafter/routes/sparql_test.clj b/test/drafter/routes/sparql_test.clj
index 1ea2b951e..e64a8883d 100644
--- a/test/drafter/routes/sparql_test.clj
+++ b/test/drafter/routes/sparql_test.clj
@@ -3,7 +3,9 @@
[clojure.test :refer :all]
[clojure.tools.logging :as log]
[drafter
- [test-common :refer [*test-backend* assert-is-forbidden-response import-data-to-draft! select-all-in-graph stream->string test-triples with-identity wrap-clean-test-db wrap-db-setup]]
+ [test-common :refer [*test-backend* assert-is-forbidden-response import-data-to-draft!
+ select-all-in-graph stream->string test-triples with-identity
+ wrap-clean-test-db wrap-db-setup]]
[timeouts :as timeouts]
[user-test :refer [test-editor test-system]]]
[drafter.rdf.draft-management :refer :all]
diff --git a/test/drafter/test_common.clj b/test/drafter/test_common.clj
index e66699eaf..b0a9f9ccb 100644
--- a/test/drafter/test_common.clj
+++ b/test/drafter/test_common.clj
@@ -1,7 +1,6 @@
(ns drafter.test-common
(:require [clojure.test :refer :all]
[drafter.util :as util]
- [grafter.rdf.protocols :refer [add]]
[grafter.rdf.templater :refer [triplify]]
[grafter.rdf.repository.registry :as reg]
[grafter.rdf.repository :as repo]
@@ -33,8 +32,8 @@
[org.apache.http.impl.io ChunkedOutputStream ContentLengthOutputStream DefaultHttpRequestParser DefaultHttpResponseWriter HttpTransportMetricsImpl IdentityOutputStream SessionInputBufferImpl SessionOutputBufferImpl]
org.apache.http.message.BasicHttpResponse
org.apache.http.ProtocolVersion
- org.openrdf.query.resultio.sparqljson.SPARQLResultsJSONWriter
- org.openrdf.rio.trig.TriGParserFactory))
+ org.eclipse.rdf4j.query.resultio.sparqljson.SPARQLResultsJSONWriter
+ org.eclipse.rdf4j.rio.trig.TriGParserFactory))
(use-fixtures :each validate-schemas)
@@ -111,7 +110,7 @@
(create-managed-graph! db graph)
(let [draftset-uri (and draftset-ref (url/->java-uri draftset-ref))
draft-graph (create-draft-graph! db graph draftset-uri)]
- (add db draft-graph triples)
+ (sparql/add db draft-graph triples)
draft-graph)))
(defn make-graph-live!
@@ -164,7 +163,7 @@
(defn ask? [& graphpatterns]
"Bodgy convenience function for ask queries"
- (repo/query *test-backend* (str "ASK WHERE {"
+ (sparql/eager-query *test-backend* (str "ASK WHERE {"
(-> (apply str (interpose " " graphpatterns))
(.replace " >" ">")
(.replace "< " "<"))
diff --git a/test/drafter/test_helpers/draft_management_helpers.clj b/test/drafter/test_helpers/draft_management_helpers.clj
index 9bd22ff6b..cbb0b4ab5 100644
--- a/test/drafter/test_helpers/draft_management_helpers.clj
+++ b/test/drafter/test_helpers/draft_management_helpers.clj
@@ -17,7 +17,7 @@
" }")
" LIMIT 1"
"}")]
- (repo/query db qry)))
+ (sparql/eager-query db qry)))
(defn draft-graphs
"Get all the draft graph URIs"
@@ -26,5 +26,5 @@
(with-state-graph
"?live <" drafter:hasDraft "> ?draft .")
"}")
- results (repo/query db query-str)]
+ results (sparql/eager-query db query-str)]
(into #{} (map :draft results))))