Package: LiveOntologyStatementExecutor
LiveOntologyStatementExecutor
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LiveOntologyStatementExecutor(Connector) |
|
|
|
|
|
||||||||||||||||||||
executeQuery(String, Statement) |
|
|
|
|
|
||||||||||||||||||||
executeUpdate(String) |
|
|
|
|
|
||||||||||||||||||||
lambda$executeQuery$0(String, Statement, OntologySnapshot) |
|
|
|
|
|
||||||||||||||||||||
lambda$executeUpdate$1(String, OntologySnapshot) |
|
|
|
|
|
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.Connector;
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:
27: public class LiveOntologyStatementExecutor implements StatementExecutor {
28:
29: private final Connector connector;
30:
31: public LiveOntologyStatementExecutor(Connector connector) {
32: this.connector = connector;
33: }
34:
35: @Override
36: public ResultSet executeQuery(final String query, final Statement statement) throws OwlapiDriverException {
37: final ResultSet resultSet = connector.executeRead(snapshot -> {
38:• if (snapshot.getReasoner() == null) {
39: throw new ReasonerNotAvailableException("Cannot execute query without a reasoner.");
40: }
41: final OWLAPIv3OWL2Ontology ont = new OWLAPIv3OWL2Ontology(snapshot.getOntologyManager(),
42: snapshot.getOntology(), snapshot.getReasoner());
43:
44: final QueryResult<OWLObject> res = OWL2QueryEngine.exec(query, ont);
45:
46:• return res != null ? AbstractResultSet.createResultSet(res, statement, query) : null;
47: });
48:• if (resultSet == null) {
49: throw new OwlapiDriverException("Unable to execute query " + query);
50: }
51: return resultSet;
52: }
53:
54: @Override
55: public void executeUpdate(final String update) throws OwlapiDriverException {
56: connector.executeWrite(snapshot -> {
57:• if (snapshot.getReasoner() == null) {
58: throw new ReasonerNotAvailableException("Cannot execute query without a reasoner.");
59: }
60: final OWLAPIv3OWL2Ontology ont = new OWLAPIv3OWL2Ontology(snapshot.getOntologyManager(),
61: snapshot.getOntology(), snapshot.getReasoner());
62:
63: OWL2QueryEngine.exec(update, ont);
64: });
65: }
66: }