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%
executeQuery(String, Statement)
M: 17 C: 24
59%
M: 2 C: 2
50%
M: 2 C: 1
33%
M: 2 C: 5
71%
M: 0 C: 1
100%
executeUpdate(String)
M: 37 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

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.owlapi.query;
16:
17: import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
18: import cz.cvut.kbss.ontodriver.owlapi.exception.OwlapiDriverException;
19: import cz.cvut.kbss.ontodriver.owlapi.exception.ReasonerNotAvailableException;
20: import cz.cvut.kbss.ontodriver.ResultSet;
21: import cz.cvut.kbss.ontodriver.Statement;
22: import cz.cvut.kbss.owl2query.engine.OWL2QueryEngine;
23: import cz.cvut.kbss.owl2query.model.QueryResult;
24: import cz.cvut.kbss.owl2query.model.owlapi.OWLAPIv3OWL2Ontology;
25: import org.semanticweb.owlapi.model.OWLObject;
26: import org.semanticweb.owlapi.model.OWLOntology;
27: import org.semanticweb.owlapi.model.OWLOntologyManager;
28: import org.semanticweb.owlapi.reasoner.OWLReasoner;
29:
30: public class TransactionalStatementExecutor implements StatementExecutor {
31:
32: private final OWLOntology ontology;
33: private final OWLOntologyManager ontologyManager;
34: private final OWLReasoner reasoner;
35:
36: public TransactionalStatementExecutor(OntologySnapshot snapshot) {
37: this.ontology = snapshot.getOntology();
38: this.ontologyManager = snapshot.getOntologyManager();
39: this.reasoner = snapshot.getReasoner();
40: }
41:
42: @Override
43: public ResultSet executeQuery(String query, Statement statement) throws OwlapiDriverException {
44:• if (reasoner == null) {
45: throw new ReasonerNotAvailableException("Cannot execute query without a reasoner.");
46: }
47: final OWLAPIv3OWL2Ontology ont = new OWLAPIv3OWL2Ontology(ontologyManager, ontology, reasoner);
48:
49: final QueryResult<OWLObject> res = OWL2QueryEngine.exec(query, ont);
50:• if (res == null) {
51: throw new OwlapiDriverException("Unable to evaluate statement " + query);
52: }
53: return AbstractResultSet.createResultSet(res, statement, query);
54: }
55:
56: @Override
57: public void executeUpdate(String update) throws OwlapiDriverException {
58:• if (reasoner == null) {
59: throw new ReasonerNotAvailableException("Cannot execute query without a reasoner.");
60: }
61: final OWLAPIv3OWL2Ontology ont = new OWLAPIv3OWL2Ontology(ontologyManager, ontology, reasoner);
62:
63: final QueryResult<OWLObject> res = OWL2QueryEngine.exec(update, ont);
64:• if (res == null) {
65: throw new OwlapiDriverException("Unable to evaluate statement " + update);
66: }
67: }
68: }