Package: ConnectionStatementExecutor
ConnectionStatementExecutor
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ConnectionStatementExecutor(RepositoryConnection) |
|
|
|
|
|
||||||||||||||||||||
executeBooleanQuery(QuerySpecification) |
|
|
|
|
|
||||||||||||||||||||
executeSelectQuery(QuerySpecification) |
|
|
|
|
|
||||||||||||||||||||
executeUpdate(QuerySpecification) |
|
|
|
|
|
Coverage
1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.rdf4j.connector;
19:
20: import cz.cvut.kbss.ontodriver.rdf4j.exception.Rdf4jDriverException;
21: import cz.cvut.kbss.ontodriver.rdf4j.query.QuerySpecification;
22: import org.eclipse.rdf4j.query.*;
23: import org.eclipse.rdf4j.repository.RepositoryConnection;
24: import org.eclipse.rdf4j.repository.RepositoryException;
25:
26: /**
27: * Actual implementation of statement processing.
28: */
29: class ConnectionStatementExecutor implements StatementExecutor {
30:
31: private final RepositoryConnection connection;
32:
33: ConnectionStatementExecutor(RepositoryConnection connection) {
34: this.connection = connection;
35: }
36:
37: @Override
38: public TupleQueryResult executeSelectQuery(QuerySpecification query) throws Rdf4jDriverException {
39: try {
40: final TupleQuery tq = connection.prepareTupleQuery(QueryLanguage.SPARQL, query.getQuery());
41: tq.setIncludeInferred(query.isIncludeInference());
42: return new QueryResult(tq.evaluate(), connection);
43: } catch (MalformedQueryException | QueryEvaluationException | RepositoryException e) {
44: throw new Rdf4jDriverException(e);
45: }
46: }
47:
48: @Override
49: public boolean executeBooleanQuery(QuerySpecification query) throws Rdf4jDriverException {
50: try {
51: final BooleanQuery bq = connection.prepareBooleanQuery(QueryLanguage.SPARQL, query.getQuery());
52: bq.setIncludeInferred(query.isIncludeInference());
53: return bq.evaluate();
54: } catch (MalformedQueryException | QueryEvaluationException | RepositoryException e) {
55: throw new Rdf4jDriverException(e);
56: }
57: }
58:
59: @Override
60: public void executeUpdate(QuerySpecification query) throws Rdf4jDriverException {
61: try {
62: final Update u = connection.prepareUpdate(QueryLanguage.SPARQL, query.getQuery());
63: u.setIncludeInferred(query.isIncludeInference());
64: u.execute();
65: } catch (MalformedQueryException | UpdateExecutionException | RepositoryException e) {
66: throw new Rdf4jDriverException(e);
67: }
68: }
69: }