/** * 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; }
@Override protected void runTestForReal() throws Throwable { Query query = null; try { try { query = queryFromTestItem(testItem); } catch (QueryException qEx) { query = null; qEx.printStackTrace(System.err); fail("Parse failure: " + qEx.getMessage()); throw qEx; } Dataset dataset = setUpDataset(query, testItem); if (dataset == null && !doesQueryHaveDataset(query)) fail("No dataset for query"); QueryExecution qe = null; if (dataset == null) qe = QueryExecutionFactory.create(query, queryFileManager); else qe = QueryExecutionFactory.create(query, dataset); try { if (query.isSelectType()) runTestSelect(query, qe); else if (query.isConstructType()) runTestConstruct(query, qe); else if (query.isDescribeType()) runTestDescribe(query, qe); else if (query.isAskType()) runTestAsk(query, qe); } finally { qe.close(); } } catch (IOException ioEx) { // log.debug("IOException: ",ioEx) ; fail("IOException: " + ioEx.getMessage()); throw ioEx; } catch (NullPointerException ex) { throw ex; } catch (Exception ex) { ex.printStackTrace(System.err); fail("Exception: " + ex.getClass().getName() + ": " + ex.getMessage()); } }