Skip to content

Package: ConnectionStatementExecutor

ConnectionStatementExecutor

nameinstructionbranchcomplexitylinemethod
ConnectionStatementExecutor(RepositoryConnection)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
executeBooleanQuery(String)
M: 6 C: 7
54%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 1
33%
M: 0 C: 1
100%
executeSelectQuery(String)
M: 6 C: 14
70%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 2
50%
M: 0 C: 1
100%
executeUpdate(String)
M: 6 C: 10
63%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 2 C: 4
67%
M: 0 C: 1
100%

Coverage

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