@Override public void close() throws QueryEvaluationException { try { result.close(); } finally { try { connection.close(); } catch (RepositoryException e) { throw new QueryEvaluationException("Exception closing connection.", e); } } }
/** * Get a {@link GeoSearchFunction} for a give URI. * * @param searchFunction * @return */ public SearchFunction getSearchFunction(final URI searchFunction) { SearchFunction geoFunc = null; try { geoFunc = getSearchFunctionInternal(searchFunction); } catch (QueryEvaluationException e) { e.printStackTrace(); } return geoFunc; }
@Test public void testSES1991NOWEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?d WHERE {?s ?p ?o . BIND(NOW() as ?d) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal d1 = (Literal)result.next().getValue("d"); Literal d2 = (Literal)result.next().getValue("d"); assertNotNull(d1); assertEquals(d1, d2); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
query = conn.prepareTupleQuery(QueryLanguage.SERQL, zeroQueryString); res = query.evaluate(); while(res.hasNext()) retList.add(res.next().getValue("contrib").toString()); res.close(); conn.close(); } catch (RepositoryException e) { log.error(e.toString()); log.error(s.toString()); } catch (QueryEvaluationException e) { log.error(e.toString()); for(StackTraceElement s: e.getStackTrace()) log.error(s.toString());
data.append("<urn:s5> <urn:q> <urn:s6> .\n"); conn.begin(); conn.add(new StringReader(data.toString()), "", RDFFormat.NTRIPLES); conn.commit(); TupleQueryResult result = tq.evaluate(); assertNotNull(result); assertTrue(result.hasNext()); Value x = result.next().getValue("x"); assertNotNull(x); assertTrue(x instanceof IRI); e.printStackTrace(); fail(e.getMessage());
public TupleQueryResult evaluate() throws QueryEvaluationException { try { RepositoryConnection con = getConnection(); QueryLanguage ql = getQueryLanguage(); String query = getQuery(); String baseURI = getBaseURI(); TupleQuery qry = con.prepareTupleQuery(ql, query, baseURI); qry.setDataset(getDataset()); qry.setIncludeInferred(getIncludeInferred()); BindingSet bindings = getBindings(); for (String name : bindings.getBindingNames()) { qry.setBinding(name, bindings.getValue(name)); } return qry.evaluate(); } catch (MalformedQueryException e) { throw new QueryEvaluationException(e); } catch (RepositoryException e) { throw new QueryEvaluationException(e); } }
@Test public void testSES1979MinMaxInf() throws Exception { loadTestData("/testdata-query/dataset-ses1979.trig"); String query = "prefix : <http://example.org/> select (min(?o) as ?min) (max(?o) as ?max) where { ?s :float ?o }"; ValueFactory vf = conn.getValueFactory(); TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { List<BindingSet> result = QueryResults.asList(tq.evaluate()); assertNotNull(result); assertEquals(1, result.size()); assertEquals(vf.createLiteral(Float.NEGATIVE_INFINITY), result.get(0).getValue("min")); assertEquals(vf.createLiteral(Float.POSITIVE_INFINITY), result.get(0).getValue("max")); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
@Override protected QueryEvaluationException convert(Exception exception) { return new QueryEvaluationException(exception); } };
public GraphQueryResult evaluate() throws QueryEvaluationException { try { RepositoryConnection con = getConnection(); QueryLanguage ql = getQueryLanguage(); String query = getQuery(); String baseURI = getBaseURI(); GraphQuery qry = con.prepareGraphQuery(ql, query, baseURI); qry.setDataset(getDataset()); qry.setIncludeInferred(getIncludeInferred()); BindingSet bindings = getBindings(); for (String name : bindings.getBindingNames()) { qry.setBinding(name, bindings.getValue(name)); } return qry.evaluate(); } catch (MalformedQueryException e) { throw new QueryEvaluationException(e); } catch (RepositoryException e) { throw new QueryEvaluationException(e); } }
public boolean evaluate() throws QueryEvaluationException { try { RepositoryConnection con = getConnection(); QueryLanguage ql = getQueryLanguage(); String query = getQuery(); String baseURI = getBaseURI(); BooleanQuery qry = con.prepareBooleanQuery(ql, query, baseURI); qry.setDataset(getDataset()); qry.setIncludeInferred(getIncludeInferred()); BindingSet bindings = getBindings(); for (String name : bindings.getBindingNames()) { qry.setBinding(name, bindings.getValue(name)); } return qry.evaluate(); } catch (MalformedQueryException e) { throw new QueryEvaluationException(e); } catch (RepositoryException e) { throw new QueryEvaluationException(e); } }
@Override public void close() throws QueryEvaluationException { try { result.close(); } finally { try { connection.close(); } catch (RepositoryException e) { throw new QueryEvaluationException("Exception closing connection.", e); } } }
private void query(TupleQuery query, TupleQueryResultWriter writer) throws QueryEvaluationException { try { query.evaluate(writer); } catch (TupleQueryResultHandlerException e) { throw new QueryEvaluationException("error while writing query tuple result: ",e); } }
public CloseableIteration<? extends Statement, QueryEvaluationException> getStatements( Resource subj, URI pred, Value obj, Resource... contexts) throws QueryEvaluationException { RepositoryResult<Statement> result; try { result = repo.getStatements(subj, pred, obj, true, contexts); } catch (RepositoryException e) { throw new QueryEvaluationException(e); } return new ExceptionConvertingIteration<Statement, QueryEvaluationException>(result){ @Override protected QueryEvaluationException convert(Exception e) { return new QueryEvaluationException(e); }}; }
@Override public double analyze(String contributionIdA, String contributionIdB){ try { RepositoryConnection conn = getConn(); double result = checkIfSimilar(conn, contributionIdA,contributionIdB); conn.close(); return result; } catch (RepositoryException e) { log.error(e.toString()); // log.error(Arrays.toString(e.getStackTrace())); for(StackTraceElement s: e.getStackTrace()) log.error(s.toString()); } catch (MalformedQueryException e) { log.error(e.toString()); for(StackTraceElement s: e.getStackTrace()) log.error(s.toString()); } catch (QueryEvaluationException e) { log.error(e.toString()); for(StackTraceElement s: e.getStackTrace()) log.error(s.toString()); } catch (Exception e) { log.error(e.toString()); for(StackTraceElement s: e.getStackTrace()) log.error(s.toString()); } return 0; }
public void checkException() throws QueryEvaluationException { synchronized (exceptions) { if (!exceptions.isEmpty()) { try { throw exceptions.remove(); } catch (QueryEvaluationException e) { List<StackTraceElement> stack = new ArrayList<StackTraceElement>(); stack.addAll(Arrays.asList(e.getStackTrace())); StackTraceElement[] thisStack = new Throwable().getStackTrace(); stack.addAll(Arrays.asList(thisStack).subList(1, thisStack.length)); e.setStackTrace(stack.toArray(new StackTraceElement[stack.size()])); throw e; } catch (RuntimeException e) { List<StackTraceElement> stack = new ArrayList<StackTraceElement>(); stack.addAll(Arrays.asList(e.getStackTrace())); StackTraceElement[] thisStack = new Throwable().getStackTrace(); stack.addAll(Arrays.asList(thisStack)); e.setStackTrace(stack.toArray(new StackTraceElement[stack.size()])); throw e; } catch (Throwable e) { throw new QueryEvaluationException(e); } } } }
@Test public void testSES1991NOWEvaluation() throws Exception { loadTestData("/testdata-query/defaultgraph.ttl"); String query = "SELECT ?d WHERE {?s ?p ?o . BIND(NOW() as ?d) } LIMIT 2"; TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); try { TupleQueryResult result = tq.evaluate(); assertNotNull(result); Literal d1 = (Literal)result.next().getValue("d"); Literal d2 = (Literal)result.next().getValue("d"); assertNotNull(d1); assertEquals(d1, d2); result.close(); } catch (QueryEvaluationException e) { e.printStackTrace(); fail(e.getMessage()); } }
query = conn.prepareTupleQuery(QueryLanguage.SERQL, zeroQueryString); res = query.evaluate(); while(res.hasNext()) roles.add(res.next().getValue("role").toString()); res.close(); conn.close(); return roles; log.error(s.toString()); } catch (QueryEvaluationException e) { log.error(e.toString()); for(StackTraceElement s: e.getStackTrace()) log.error(s.toString());
public void evaluate(TupleQueryResultHandler handler) throws QueryEvaluationException, TupleQueryResultHandlerException { try { RepositoryConnection con = getConnection(); QueryLanguage ql = getQueryLanguage(); String query = getQuery(); String baseURI = getBaseURI(); TupleQuery qry = con.prepareTupleQuery(ql, query, baseURI); qry.setDataset(getDataset()); qry.setIncludeInferred(getIncludeInferred()); BindingSet bindings = getBindings(); for (String name : bindings.getBindingNames()) { qry.setBinding(name, bindings.getValue(name)); } qry.evaluate(handler); } catch (MalformedQueryException e) { throw new QueryEvaluationException(e); } catch (RepositoryException e) { throw new QueryEvaluationException(e); } }
@Override protected QueryEvaluationException convert(Exception e) { return new QueryEvaluationException(e); } };
private void query(TupleQuery query, TupleQueryResultWriter writer) throws QueryEvaluationException { try { query.evaluate(writer); } catch (TupleQueryResultHandlerException e) { throw new QueryEvaluationException("error while writing query tuple result: ",e); } }