LiveOntologyStatementExecutor implements StatementExecutor { @Override public ResultSet executeQuery(final String query, final Statement statement) throws OwlapiDriverException { final ResultSet resultSet = connector.executeRead(snapshot -> { if (snapshot.getReasoner() == null) { throw new ReasonerNotAvailableException("Cannot execute query without a reasoner."); } final OWLAPIv3OWL2Ontology ont = new OWLAPIv3OWL2Ontology(snapshot.getOntologyManager(), snapshot.getOntology(), snapshot.getReasoner()); final QueryResult<OWLObject> res = OWL2QueryEngine.exec(query, ont); return res != null ? AbstractResultSet.createResultSet(res, statement, query) : null; }); if (resultSet == null) { throw new OwlapiDriverException("Unable to execute query " + query); } return resultSet; } LiveOntologyStatementExecutor(Connector connector); @Override ResultSet executeQuery(final String query, final Statement statement); @Override void executeUpdate(final String update);  }
@Test public void executeQueryPassesFunctionToConnectorForExecutionInReadOnly() throws Exception { final SelectResultSet resultSet = mock(SelectResultSet.class); when(connectorMock.executeRead(any(Function.class))).thenReturn(resultSet); final ResultSet res = executor.executeQuery(QUERY, statementMock); assertNotNull(res); assertEquals(resultSet, res); verify(connectorMock).executeRead(any(Function.class)); }
@Test(expected = OntoDriverException.class) public void executeQueryReturningNullThrowsDriverException() throws Exception { executor.executeQuery(QUERY, statementMock); }