use of org.apache.jena.arq.querybuilder.SelectBuilder in project jena by apache.
the class WhereHandlerTest method testAddUnionOfOne.
@Test
public void testAddUnionOfOne() {
Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
SelectBuilder sb = new SelectBuilder().addWhere(t1);
handler.addUnion(sb);
handler.build();
ElementPathBlock epb1 = new ElementPathBlock();
epb1.addTriple(t1);
WhereValidator visitor = new WhereValidator(epb1);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.SelectBuilder in project jena by apache.
the class WhereClauseTest method testAddSubQuery.
@ContractTest
public void testAddSubQuery() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "urn:uri:").addVar("?x").addWhere("pfx:one", "pfx:two", "pfx:three");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
Query query = builder.build();
Query q2 = new Query();
q2.setQuerySelectType();
q2.addProjectVars(Arrays.asList(Var.alloc("x")));
ElementPathBlock epb = new ElementPathBlock();
q2.setQueryPattern(epb);
epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("urn:uri:one"), NodeFactory.createURI("urn:uri:two"), NodeFactory.createURI("urn:uri:three"))));
ElementSubQuery esq = new ElementSubQuery(q2);
WhereValidator visitor = new WhereValidator(esq);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.SelectBuilder 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.SelectBuilder 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);
}
use of org.apache.jena.arq.querybuilder.SelectBuilder in project jena by apache.
the class WhereClauseTest method testSetVarsInSubQuery_Node_Variable.
@ContractTest
public void testSetVarsInSubQuery_Node_Variable() {
Node v = NodeFactory.createVariable("v");
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
Query subQuery = new Query();
subQuery.setQuerySelectType();
subQuery.setQueryResultStar(true);
ElementSubQuery esq = new ElementSubQuery(subQuery);
ElementPathBlock epb = new ElementPathBlock();
subQuery.setQueryPattern(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), new P_Link(NodeFactory.createURI("two")), NodeFactory.createVariable("v"));
epb.addTriple(tp);
WhereValidator visitor = new WhereValidator(esq);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, NodeFactory.createURI("three"));
subQuery = new Query();
subQuery.setQuerySelectType();
subQuery.setQueryResultStar(true);
esq = new ElementSubQuery(subQuery);
epb = new ElementPathBlock();
subQuery.setQueryPattern(epb);
tp = new TriplePath(NodeFactory.createURI("one"), new P_Link(NodeFactory.createURI("two")), NodeFactory.createURI("three"));
epb.addTriple(tp);
visitor = new WhereValidator(esq);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations