public void setBinding(String name, Value value) { delegate.setBinding(name, value); }
public void setBinding(String name, Value value) { query.setBinding(name, value); }
public void setBinding(String name, Value value) { query.setBinding(name, value); }
private void setBinding(String name, Value value) { if (query == null) throw new UnsupportedOperationException(); query.setBinding(name, value); }
@Override public void setBinding(String variable, NODE node) { bindings.put(variable, node); query.setBinding(variable, dialect.getNode(node)); }
String query = "SELECT * WHERE {?X ?P ?Y }"; TupleQuery preparedQuery = conn.prepareQuery(QuerLanguage.SPARQL, query); preparedQuery.setBinding("X", someValue); ... TupleQueryResult result = preparedQuery.evaluate();
@Override public void setBinding(String variable, NODE node) { bindings.put(variable, node); query.setBinding(variable, dialect.getNode(node)); }
@Override public void setBinding(String variable, NODE node) { bindings.put(variable, node); query.setBinding(variable, dialect.getNode(node)); }
private void addDuringQueryExec(final RepositoryConnection conn, final Resource subj, final URI pred, final Value obj, final Resource... ctx) throws RepositoryException, MalformedQueryException, QueryEvaluationException { final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, "select distinct ?s ?p ?o where{?s ?p ?t . ?t <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o }" ); tq.setBinding("s", subj); tq.setBinding("p", pred); tq.setBinding("o", obj); final TupleQueryResult tqr = tq.evaluate(); try { if (!tqr.hasNext()) { conn.add(subj, pred, obj, ctx); } } finally { tqr.close(); } } }
private void addDuringQueryExec(final RepositoryConnection conn, final Resource subj, final URI pred, final Value obj, final Resource... ctx) throws RepositoryException, MalformedQueryException, QueryEvaluationException { final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, "select distinct ?s ?p ?o where{?s ?p ?t . ?t <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o }" ); tq.setBinding("s", subj); tq.setBinding("p", pred); tq.setBinding("o", obj); final TupleQueryResult tqr = tq.evaluate(); try { if (!tqr.hasNext()) { conn.add(subj, pred, obj, ctx); } } finally { tqr.close(); } } }
private void addDuringQueryExec(final RepositoryConnection conn, final Resource subj, final URI pred, final Value obj, final Resource... ctx) throws RepositoryException, MalformedQueryException, QueryEvaluationException { final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, "select distinct ?s ?p ?o where{?s ?p ?t . ?t <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o }" ); tq.setBinding("s", subj); tq.setBinding("p", pred); tq.setBinding("o", obj); final TupleQueryResult tqr = tq.evaluate(); try { if (!tqr.hasNext()) { conn.add(subj, pred, obj, ctx); } } finally { tqr.close(); } } }
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().createURI(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); } }
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); } }
private void addDuringQueryExec(final RepositoryConnection conn, final Resource subj, final URI pred, final Value obj, final Resource... ctx) throws RepositoryException, MalformedQueryException, QueryEvaluationException { final TupleQuery tq = conn.prepareTupleQuery(QueryLanguage.SPARQL, "select distinct ?s ?p ?o where{?s ?p ?t . ?t <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?o }" ); tq.setBinding("s", subj); tq.setBinding("p", pred); tq.setBinding("o", obj); final TupleQueryResult tqr = tq.evaluate(); try { if (!tqr.hasNext()) { conn.add(subj, pred, obj, ctx); } } finally { tqr.close(); } } }
@Test public void testQueryWithSpecifiedSubject() throws RepositoryException, MalformedQueryException, QueryEvaluationException { // fire a query with the subject pre-specified TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SERQL, QUERY_STRING); query.setBinding("Subject", SUBJECT_1); query.setBinding("Query", new LiteralImpl("one")); TupleQueryResult result = query.evaluate(); // check that this subject and only this subject is returned assertTrue(result.hasNext()); BindingSet bindings = result.next(); assertEquals(SUBJECT_1, bindings.getValue("Subject")); assertNotNull(bindings.getValue("Score")); assertFalse(result.hasNext()); result.close(); }
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().createURI(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); } }
private void executeQuery(final URI serviceUri, final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); final ValueFactory vf = conn.getValueFactory(); conn.setAutoCommit(false); try { final String query = "SELECT ?x { SERVICE <" + serviceUri.stringValue() + "> { ?x <u:1> ?bool1 } }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("bool1", vf.createLiteral(true)); final TupleQueryResult tqr = q.evaluate(); try { tqr.hasNext(); } finally { tqr.close(); } } finally { conn.close(); } } finally { repo.shutDown(); } }
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); } }
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); } }
private void executeQuery(final URI serviceUri, final SailRepository repo) throws RepositoryException, MalformedQueryException, QueryEvaluationException, RDFParseException, IOException, RDFHandlerException { try { repo.initialize(); final RepositoryConnection conn = repo.getConnection(); final ValueFactory vf = conn.getValueFactory(); conn.setAutoCommit(false); try { final String query = "SELECT ?x { SERVICE <" + serviceUri.stringValue() + "> { ?x <u:1> ?bool1 } }"; final TupleQuery q = conn.prepareTupleQuery(QueryLanguage.SPARQL, query); q.setBinding("bool1", vf.createLiteral(true)); final TupleQueryResult tqr = q.evaluate(); try { tqr.hasNext(); } finally { tqr.close(); } } finally { conn.close(); } } finally { repo.shutDown(); } }