use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testSetVarsInUnion.
@Test
public void testSetVarsInUnion() {
Var v = Var.alloc("v");
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
handler.addUnion(sb);
SelectBuilder sb2 = new SelectBuilder().addWhere("<uno>", "<dos>", "<tres>");
handler.addUnion(sb2);
handler.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, v.asNode());
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);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
Map<Var, Node> values = new HashMap<>();
values.put(v, three);
handler.setVars(values);
handler.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);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromSelectWithVar.
@Test
public void testMakeSubQueryFromSelectWithVar() {
SelectBuilder sb = new SelectBuilder().addVar("?x").addWhere("?x", RDF.type, RDF.Alt);
ElementSubQuery esq = handler.makeSubQuery(sb);
Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
TriplePath tp = new TriplePath(t1);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
Query q = new Query();
q.setQuerySelectType();
q.addResultVar(NodeFactory.createVariable("x"));
q.setQueryPattern(epb);
ElementSubQuery esq2 = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq2);
esq.visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromWhere.
@Test
public void testMakeSubQueryFromWhere() {
AbstractQueryBuilder<?> sb = new WhereBuilder().addWhere("?x", RDF.type, RDF.Alt);
ElementSubQuery esq = handler.makeSubQuery(sb);
Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
TriplePath tp = new TriplePath(t1);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
Query q = new Query();
q.setQuerySelectType();
q.setQueryResultStar(true);
q.setQueryPattern(epb);
ElementSubQuery esq2 = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq2);
esq.visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddWhereValueVars.
@ContractTest
public void testAddWhereValueVars() {
final Var v = Var.alloc("v");
Map<Object, List<?>> map = new HashMap<Object, List<?>>();
map.put(Var.alloc("v"), Arrays.asList("<one>", "<two>"));
map.put("?x", Arrays.asList("three", "four"));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhereValueVars(map);
Query query = builder.build();
Var x = Var.alloc("x");
ElementData edat = new ElementData();
edat.add(x);
edat.add(v);
setupBindings(edat, x, v);
WhereValidator visitor = new WhereValidator(edat);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddOptionalGroupPattern_VariableNode.
@ContractTest
public void testAddOptionalGroupPattern_VariableNode() {
Node s = NodeFactory.createVariable("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));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional(pattern);
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(new Triple(Var.alloc(s), q, n123));
epb.addTriplePath(tp);
tp = new TriplePath(new Triple(Var.alloc(s), v, x));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations