use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddOptionalTriplePath.
@ContractTest
public void testAddOptionalTriplePath() {
WhereClause<?> whereClause = getProducer().newInstance();
PrefixMapping pmap = new PrefixMappingImpl();
pmap.setNsPrefix("ts", "urn:test:");
Path path = PathParser.parse("ts:two/ts:dos", pmap);
AbstractQueryBuilder<?> builder = whereClause.addOptional(new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createURI("three")));
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createURI("three"));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testSetVarsInTriple_Node_Variable.
@ContractTest
public void testSetVarsInTriple_Node_Variable() {
Node v = NodeFactory.createVariable("v");
Node one = NodeFactory.createURI("one");
Node two = NodeFactory.createURI("two");
Node three = NodeFactory.createURI("three");
Node four = NodeFactory.createURI("four");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(one, two, v));
TriplePath tp = new TriplePath(new Triple(one, two, Var.alloc(v)));
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
WhereValidator visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, three);
tp = new TriplePath(new Triple(one, two, three));
epb = new ElementPathBlock();
epb.addTriple(tp);
visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, four);
tp = new TriplePath(new Triple(one, two, four));
epb = new ElementPathBlock();
epb.addTriple(tp);
visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, null);
tp = new TriplePath(new Triple(one, two, Var.alloc("v")));
epb = new ElementPathBlock();
epb.addTriple(tp);
visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testSetVarsInUnion_Node_Variable.
@ContractTest
public void testSetVarsInUnion_Node_Variable() {
Node v = NodeFactory.createVariable("v");
SelectBuilder sb1 = new SelectBuilder().addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
WhereClause<?> whereClause = getProducer().newInstance();
whereClause.addUnion(sb1);
SelectBuilder sb2 = new SelectBuilder().addWhere("<uno>", "<dos>", "<tres>");
AbstractQueryBuilder<?> builder = whereClause.addUnion(sb2);
Query query = builder.build();
Node one = NodeFactory.createURI("one");
Node two = NodeFactory.createURI("two");
Node three = NodeFactory.createURI("three");
Node uno = NodeFactory.createURI("uno");
Node dos = NodeFactory.createURI("dos");
Node tres = NodeFactory.createURI("tres");
ElementUnion union = new ElementUnion();
ElementPathBlock epb = new ElementPathBlock();
Triple t = new Triple(one, two, Var.alloc(v));
epb.addTriple(t);
union.addElement(epb);
ElementPathBlock epb2 = new ElementPathBlock();
t = new Triple(uno, dos, tres);
epb2.addTriple(t);
union.addElement(epb2);
WhereValidator visitor = new WhereValidator(union);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, NodeFactory.createURI("three"));
query = builder.build();
union = new ElementUnion();
epb = new ElementPathBlock();
t = new Triple(one, two, three);
epb.addTriple(t);
union.addElement(epb);
epb2 = new ElementPathBlock();
t = new Triple(uno, dos, tres);
epb2.addTriple(t);
union.addElement(epb2);
visitor = new WhereValidator(union);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testBindStringVar_Node_Variable.
@ContractTest
public void testBindStringVar_Node_Variable() throws ParseException {
Node v = NodeFactory.createVariable("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind("rand()", v);
Query query = builder.build();
ElementBind bind = new ElementBind(Var.alloc(v), new E_Random());
WhereValidator visitor = new WhereValidator(bind);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
Node three = NodeFactory.createURI("three");
builder.setVar(v, three);
query = builder.build();
visitor = new WhereValidator(new ElementTriplesBlock());
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddGraph_frontsTriple.
@ContractTest
public void testAddGraph_frontsTriple() {
final Node s = NodeFactory.createURI("s");
final Node p = NodeFactory.createURI("p");
final Node o = NodeFactory.createURI("o");
FrontsTriple ft = new FrontsTriple() {
@Override
public Triple asTriple() {
return new Triple(s, p, o);
}
};
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addGraph("<g>", ft);
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);
}
Aggregations