Skip to content

Package: OwlapiStatement

OwlapiStatement

nameinstructionbranchcomplexitylinemethod
OwlapiStatement(StatementExecutorFactory, OwlapiConnection)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
close()
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%
closeExistingResultSet()
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
disableInference()
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
ensureOpen()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
executeQuery(String)
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
executeUpdate(String)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getExecutor()
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getStatementOntology()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isInferenceDisabled()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isOpen()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
querySpec(String)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
useOntology(Statement.StatementOntology)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2024 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.owlapi.query;
19:
20: import cz.cvut.kbss.ontodriver.ResultSet;
21: import cz.cvut.kbss.ontodriver.Statement;
22: import cz.cvut.kbss.ontodriver.exception.OntoDriverException;
23: import cz.cvut.kbss.ontodriver.owlapi.OwlapiConnection;
24:
25: import java.util.Objects;
26:
27: public class OwlapiStatement implements Statement {
28:
29: private StatementOntology targetOntology;
30: private boolean open;
31: private boolean disableInference;
32:
33: private final StatementExecutorFactory executorFactory;
34: final OwlapiConnection connection;
35:
36: ResultSet resultSet;
37:
38: public OwlapiStatement(StatementExecutorFactory executorFactory, OwlapiConnection connection) {
39: this.executorFactory = executorFactory;
40: this.connection = connection;
41: this.open = true;
42: }
43:
44: void ensureOpen() {
45:• if (!open) {
46: throw new IllegalStateException("The statement is closed.");
47: }
48: }
49:
50: @Override
51: public ResultSet executeQuery(String sparql) throws OntoDriverException {
52: ensureOpen();
53: Objects.requireNonNull(sparql);
54: closeExistingResultSet();
55: this.resultSet = getExecutor().executeQuery(querySpec(sparql));
56: return resultSet;
57: }
58:
59: StatementExecutor getExecutor() {
60: return executorFactory.getStatementExecutor(targetOntology);
61: }
62:
63: QuerySpecification querySpec(String query) {
64: return QuerySpecification.query(query).disableInference(disableInference).statement(this);
65: }
66:
67: @Override
68: public void executeUpdate(String sparql) throws OntoDriverException {
69: ensureOpen();
70: Objects.requireNonNull(sparql);
71: closeExistingResultSet();
72: getExecutor().executeUpdate(querySpec(sparql));
73: connection.commitIfAuto();
74: }
75:
76: @Override
77: public void useOntology(StatementOntology ontology) {
78: this.targetOntology = ontology;
79: }
80:
81: @Override
82: public StatementOntology getStatementOntology() {
83: return targetOntology;
84: }
85:
86:
87: @Override
88: public boolean isOpen() {
89: return open;
90: }
91:
92: @Override
93: public void close() throws OntoDriverException {
94: this.open = false;
95: closeExistingResultSet();
96: }
97:
98: @Override
99: public void disableInference() {
100: this.disableInference = true;
101: }
102:
103: @Override
104: public boolean isInferenceDisabled() {
105: return disableInference;
106: }
107:
108: void closeExistingResultSet() throws OntoDriverException {
109:• if (resultSet != null) {
110: resultSet.close();
111: this.resultSet = null;
112: }
113: }
114: }