/** * Perform the {@link QueryExecution} once. * * @param action * @param queryExecution * @param query * @param queryStringLog Informational string created from the initial query. * @return */ protected SPARQLResult executeQuery( HttpAction action, QueryExecution queryExecution, Query query, String queryStringLog) { setAnyTimeouts(queryExecution, action); if (query.isSelectType()) { ResultSet rs = queryExecution.execSelect(); // Force some query execution now. // If the timeout-first-row goes off, the output stream has not // been started so the HTTP error code is sent. rs.hasNext(); // If we wanted perfect query time cancellation, we could consume // the result now to see if the timeout-end-of-query goes off. // rs = ResultSetFactory.copyResults(rs) ; // action.log.info(format("[%d] exec/select", action.id)) ; return new SPARQLResult(rs); } if (query.isConstructType()) { Dataset dataset = queryExecution.execConstructDataset(); // action.log.info(format("[%d] exec/construct", action.id)); return new SPARQLResult(dataset); } if (query.isDescribeType()) { Model model = queryExecution.execDescribe(); // action.log.info(format("[%d] exec/describe", action.id)) ; return new SPARQLResult(model); } if (query.isAskType()) { boolean b = queryExecution.execAsk(); // action.log.info(format("[%d] exec/ask", action.id)) ; return new SPARQLResult(b); } ServletOps.errorBadRequest("Unknown query type - " + queryStringLog); return null; }
void runTestAsk(Query query, QueryExecution qe) throws Exception { boolean result = qe.execAsk(); if (results != null) { if (results.isBoolean()) { boolean b = results.getBooleanResult(); assertEquals("ASK test results do not match", b, result); } else { Model resultsAsModel = results.getModel(); StmtIterator sIter = results.getModel().listStatements(null, RDF.type, ResultSetGraphVocab.ResultSet); if (!sIter.hasNext()) throw new QueryTestException("Can't find the ASK result"); Statement s = sIter.nextStatement(); if (sIter.hasNext()) throw new QueryTestException("Too many result sets in ASK result"); Resource r = s.getSubject(); Property p = resultsAsModel.createProperty(ResultSetGraphVocab.getURI() + "boolean"); boolean x = r.getRequiredProperty(p).getBoolean(); if (x != result) assertEquals("ASK test results do not match", x, result); } } return; }