use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddUnionToExistingWithVar.
@Test
public void testAddUnionToExistingWithVar() {
handler.addWhere(new TriplePath(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o"))));
SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
handler.addUnion(sb);
handler.build();
Query q = new Query();
q.setQuerySelectType();
ElementPathBlock epb1 = new ElementPathBlock();
epb1.addTriple(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
q.setQueryPattern(epb1);
q.addProjectVars(Arrays.asList(Var.alloc("x")));
ElementSubQuery sq = new ElementSubQuery(q);
ElementPathBlock epb2 = new ElementPathBlock();
epb2.addTriple(new Triple(NodeFactory.createURI("s"), NodeFactory.createURI("p"), NodeFactory.createURI("o")));
ElementUnion union = new ElementUnion();
union.addElement(epb2);
union.addElement(sq);
WhereValidator visitor = new WhereValidator(union);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddOptionalWhereHandler.
@Test
public void testAddOptionalWhereHandler() {
WhereHandler pattern = new WhereHandler(new Query());
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));
pattern.addWhere(new TriplePath(new Triple(s, q, n123)));
pattern.addWhere(new TriplePath(new Triple(s, v, x)));
handler.addOptional(pattern);
handler.build();
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(new Triple(s, q, n123));
epb.addTriplePath(tp);
tp = new TriplePath(new Triple(s, v, x));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddOptionalObjects.
@Test
public void testAddOptionalObjects() {
handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode())));
handler.build();
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode()));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method addGraph_GSPO.
public void addGraph_GSPO() {
final Node s = NodeFactory.createURI("s");
final Node p = NodeFactory.createURI("p");
final Node o = NodeFactory.createURI("o");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addGraph("<g>", s, p, o);
Query query = builder.build();
ElementPathBlock epb = new ElementPathBlock();
ElementNamedGraph eng = new ElementNamedGraph(NodeFactory.createURI("g"), epb);
epb.addTriplePath(new TriplePath(new Triple(s, p, o)));
WhereValidator visitor = new WhereValidator(eng);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddFilter.
@ContractTest
public void testAddFilter() throws ParseException {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addFilter("?one<10");
E_LessThan lt = new E_LessThan(new ExprVar(Var.alloc("one")), new NodeValueInteger(10));
ElementFilter ef = new ElementFilter(lt);
WhereValidator visitor = new WhereValidator(ef);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations