Skip to content

Package: TransactionalStatementExecutor

TransactionalStatementExecutor

nameinstructionbranchcomplexitylinemethod
TransactionalStatementExecutor(OntologySnapshot)
M: 0 C: 15
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
execute(QuerySpecification)
M: 17 C: 30
64%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 2 C: 6
75%
M: 0 C: 1
100%
executeQuery(QuerySpecification)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
executeUpdate(QuerySpecification)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getNoInferenceReasoner()
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%

Coverage

1: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.ontodriver.owlapi.query;
14:
15: import cz.cvut.kbss.ontodriver.ResultSet;
16: import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
17: import cz.cvut.kbss.ontodriver.owlapi.exception.OwlapiDriverException;
18: import cz.cvut.kbss.ontodriver.owlapi.exception.ReasonerNotAvailableException;
19: import cz.cvut.kbss.owl2query.engine.OWL2QueryEngine;
20: import cz.cvut.kbss.owl2query.model.QueryResult;
21: import cz.cvut.kbss.owl2query.model.owlapi.OWLAPIv3OWL2Ontology;
22: import org.semanticweb.owlapi.model.OWLObject;
23: import org.semanticweb.owlapi.model.OWLOntology;
24: import org.semanticweb.owlapi.model.OWLOntologyManager;
25: import org.semanticweb.owlapi.reasoner.OWLReasoner;
26:
27: public class TransactionalStatementExecutor implements StatementExecutor {
28:
29: private final OWLOntology ontology;
30: private final OWLOntologyManager ontologyManager;
31: private final OWLReasoner reasoner;
32:
33: public TransactionalStatementExecutor(OntologySnapshot snapshot) {
34: this.ontology = snapshot.getOntology();
35: this.ontologyManager = snapshot.getOntologyManager();
36: this.reasoner = snapshot.getReasoner();
37: }
38:
39: @Override
40: public ResultSet executeQuery(QuerySpecification query) throws OwlapiDriverException {
41: final QueryResult<OWLObject> res = execute(query);
42: return AbstractResultSet.createResultSet(res, query.getStatement(), query.getQuery());
43: }
44:
45: private QueryResult<OWLObject> execute(QuerySpecification query) throws OwlapiDriverException {
46:• if (reasoner == null) {
47: throw new ReasonerNotAvailableException("Cannot execute query without a reasoner.");
48: }
49:• final OWLReasoner reasonerToUse = query.isDisableInference() ? getNoInferenceReasoner() : reasoner;
50: final OWLAPIv3OWL2Ontology ont = new OWLAPIv3OWL2Ontology(ontologyManager, ontology, reasonerToUse);
51:
52: final QueryResult<OWLObject> res = OWL2QueryEngine.exec(query.getQuery(), ont);
53:• if (res == null) {
54: throw new OwlapiDriverException("Unable to evaluate statement " + query);
55: }
56: return res;
57: }
58:
59: private OWLReasoner getNoInferenceReasoner() {
60: return new NoOpReasoner(ontology);
61: }
62:
63: @Override
64: public void executeUpdate(QuerySpecification query) throws OwlapiDriverException {
65: execute(query);
66: }
67: }