public void close() { aTupleQueryResult.close(); } };
@Override public void close() { try { result.close(); } catch (QueryEvaluationException e) { throw new RuntimeException(e); } }
private void closeQuietly(TupleQueryResult res) { try { if (res != null) res.close(); } catch (Exception e) { logger.debug("Could not close connection properly: " + e.getMessage(), e); } }
private void closeQuietly(TupleQueryResult res) { try { if (res != null) res.close(); } catch (Exception e) { logger.debug("Could not close connection properly: " + e.getMessage(), e); } }
private void closeQuietly(TupleQueryResult res) { try { if (res != null) res.close(); } catch (Exception e) { logger.debug("Could not close connection properly: " + e.getMessage(), e); } }
@Override public void close() { try { this.it.close(); } catch (QueryEvaluationException e) { if (RDF4jStore.LOGGER.isErrorEnabled()) { RDF4jStore.LOGGER.error("Error during iteration closing", e); } throw new RuntimeException("An error occurs while closing iterator", e); } }
@Override public void handleClose() throws QueryEvaluationException { try { super.handleClose(); } finally { queryResult.close(); } } }
@Override public void close() throws QueryEvaluationException { try { result.close(); } finally { try { connection.close(); } catch (RepositoryException e) { throw new QueryEvaluationException("Exception closing connection.", e); } } }
/** * Returns a single element from the query result. The QueryResult is automatically closed by this method. * * @return a single query result element. * @throws QueryEvaluationException */ public static BindingSet singleResult(TupleQueryResult result) throws QueryEvaluationException { BindingSet singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
/** * Returns a single element from the query result. The QueryResult is automatically closed by this method. * * @return a single query result element. * @throws QueryEvaluationException */ public static BindingSet singleResult(TupleQueryResult result) throws QueryEvaluationException { BindingSet singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
/** * Returns a single element from the query result. The QueryResult is automatically closed by this method. * * @return a single query result element. * @throws QueryEvaluationException */ public static BindingSet singleResult(TupleQueryResult result) throws QueryEvaluationException { BindingSet singleResult = null; try { if (result.hasNext()) { singleResult = result.next(); } } finally { result.close(); } return singleResult; }
/** * Query a connection for conformance tests matching a particular * test type. */ Set<Value> getTestURIs(final RepositoryConnection conn, final String testType) throws IOException, RDF4JException { final Set<Value> testURIs = new HashSet<>(); final TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, "select ?test where { " + "?test <" + TYPE + "> <" + testType + "> .\n" + "?test <" + TEST_PROFILE + "> <" + TEST_RL + "> .\n" + "?test <" + TEST_SEMANTICS + "> <" + TEST_RDFBASED + "> .\n" + "}"); final TupleQueryResult queryResult = query.evaluate(); while (queryResult.hasNext()) { final BindingSet bindings = queryResult.next(); testURIs.add(bindings.getValue("test")); } queryResult.close(); return testURIs; }
protected static String getManifestName(Repository manifestRep, RepositoryConnection con, String manifestFileURL) throws QueryEvaluationException, RepositoryException, MalformedQueryException { // Try to extract suite name from manifest file TupleQuery manifestNameQuery = con.prepareTupleQuery(QueryLanguage.SERQL, "SELECT ManifestName FROM {ManifestURL} rdfs:label {ManifestName}"); manifestNameQuery.setBinding("ManifestURL", manifestRep.getValueFactory().createIRI(manifestFileURL)); TupleQueryResult manifestNames = manifestNameQuery.evaluate(); try { if (manifestNames.hasNext()) { return manifestNames.next().getValue("ManifestName").stringValue(); } } finally { manifestNames.close(); } // Derive name from manifest URL int lastSlashIdx = manifestFileURL.lastIndexOf('/'); int secLastSlashIdx = manifestFileURL.lastIndexOf('/', lastSlashIdx - 1); return manifestFileURL.substring(secLastSlashIdx + 1, lastSlashIdx); } }
@Test public void testSimpleTupleQueryUnicodeSparql() throws Exception { testCon.add(alexander, name, Александър); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append(" PREFIX foaf: <" + FOAF_NS + ">"); queryBuilder.append(" SELECT ?person"); queryBuilder.append(" WHERE { ?person foaf:name '"); queryBuilder.append(Александър.getLabel()).append("' .}"); TupleQueryResult result = testCon.prepareTupleQuery( QueryLanguage.SPARQL, queryBuilder.toString()).evaluate(); try { assertTrue(result != null); assertTrue(result.hasNext()); while (result.hasNext()) { BindingSet solution = result.next(); assertTrue(solution.hasBinding("person")); assertEquals(alexander, solution.getValue("person")); } } finally { result.close(); } }
@Test(expected = QueryEvaluationException.class) public void testSimpleTupleQueryUnicode() throws Exception { testCon.add(alexander, name, Александър); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append(" SELECT person"); queryBuilder.append(" FROM {person} foaf:name {").append(Александър.getLabel()).append("}"); queryBuilder.append(" USING NAMESPACE foaf = <" + FOAF_NS + ">"); TupleQueryResult result = testCon.prepareTupleQuery(QueryLanguage.SERQL, queryBuilder.toString()).evaluate(); try { assertTrue(result != null); assertTrue(result.hasNext()); while (result.hasNext()) { BindingSet solution = result.next(); assertTrue(solution.hasBinding("person")); assertEquals(alexander, solution.getValue("person")); } } finally { result.close(); } }
public void testBaseURIInQueryString() throws Exception { testCon.add(vf.createIRI("urn:test:s1"), vf.createIRI("urn:test:p1"), vf.createIRI("urn:test:o1")); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "BASE <urn:test:s1> SELECT * { <> ?p ?o }").evaluate(); try { assertTrue(rs.hasNext()); } finally { rs.close(); } }
public void testBaseURIInParam() throws Exception { testCon.add(vf.createIRI("http://example.org/s1"), vf.createIRI("urn:test:p1"), vf.createIRI("urn:test:o1")); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { <s1> ?p ?o }", "http://example.org").evaluate(); try { assertTrue(rs.hasNext()); } finally { rs.close(); } }
public void testBaseURIInParamWithTrailingSlash() throws Exception { testCon.add(vf.createIRI("http://example.org/s1"), vf.createIRI("urn:test:p1"), vf.createIRI("urn:test:o1")); TupleQueryResult rs = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { <s1> ?p ?o }", "http://example.org/").evaluate(); try { assertTrue(rs.hasNext()); } finally { rs.close(); } }
private int size(IRI defaultGraph) throws RepositoryException, MalformedQueryException, QueryEvaluationException { TupleQuery qry = testCon.prepareTupleQuery(QueryLanguage.SPARQL, "SELECT * { ?s ?p ?o }"); DatasetImpl dataset = new DatasetImpl(); dataset.addDefaultGraph(defaultGraph); qry.setDataset(dataset); TupleQueryResult result = qry.evaluate(); try { int count = 0; while (result.hasNext()) { result.next(); count++; } return count; } finally { result.close(); } }
@Override public void testOrPredicate() throws Exception { String union = "{ :s ?p :o FILTER (?p = :p1 || ?p = :p2) }"; IRI s = vf.createIRI("urn:test:s"); IRI p1 = vf.createIRI("urn:test:p1"); IRI p2 = vf.createIRI("urn:test:p2"); IRI o = vf.createIRI("urn:test:o"); testCon.add(s, p1, o); testCon.add(s, p2, o); String qry = "PREFIX :<urn:test:> SELECT ?p WHERE " + union; TupleQuery query = testCon.prepareTupleQuery(QueryLanguage.SPARQL, qry); TupleQueryResult result = query.evaluate(); List<Value> list = new ArrayList<Value>(); while (result.hasNext()) { BindingSet bindings = result.next(); list.add(bindings.getValue("p")); } result.close(); assertThat(list, hasItem(p1)); assertThat(list, hasItem(p2)); }