use of org.apache.jena.query.Query in project jena by apache.
the class QBQuadHolder method getQuads.
@Override
public ExtendedIterator<Quad> getQuads() {
Query q = qb.build();
QuadIteratorBuilder builder = new QuadIteratorBuilder(defaultGraphName);
q.getQueryPattern().visit(builder);
return builder.iter;
}
use of org.apache.jena.query.Query in project jena by apache.
the class QuadIteratorBuilder method visit.
@Override
public void visit(ElementSubQuery el) {
Query q = el.getQuery();
q.getQueryPattern().visit(this);
}
use of org.apache.jena.query.Query in project jena by apache.
the class WhereClauseTest method testBindStringVar.
@ContractTest
public void testBindStringVar() throws ParseException {
Var v = Var.alloc("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind("rand()", v);
assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
builder.setVar(v, NodeFactory.createURI("three"));
Query q = builder.build();
ElementGroup eg = (ElementGroup) q.getQueryPattern();
List<Element> lst = eg.getElements();
assertEquals("Should only be one element", 1, lst.size());
assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
assertTrue("ElementGroup should be empty", etb.isEmpty());
}
use of org.apache.jena.query.Query in project jena by apache.
the class WhereClauseTest method testAddOptionalGroupPattern.
@ContractTest
public void testAddOptionalGroupPattern() throws ParseException {
Var s = Var.alloc("s");
Node q = NodeFactory.createURI("urn:q");
Node v = NodeFactory.createURI("urn:v");
Var x = Var.alloc("x");
Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
SelectBuilder pattern = new SelectBuilder();
pattern.addWhere(new Triple(s, q, n123));
pattern.addWhere(new Triple(s, v, x));
pattern.addFilter("?x>56");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional(pattern);
Query expected = QueryFactory.create("SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
Assert.assertEquals(expected.getQueryPattern(), builder.build().getQueryPattern());
}
use of org.apache.jena.query.Query in project jena by apache.
the class AbstractClauseTest method getQuery.
protected static final Query getQuery(AbstractQueryBuilder<?> builder) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
Field f = AbstractQueryBuilder.class.getDeclaredField("query");
f.setAccessible(true);
return (Query) f.get(builder);
}
Aggregations