use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddUnion.
@ContractTest
public void testAddUnion() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addVar("?x").addWhere("<one>", "<two>", "three");
WhereClause<?> whereClause = getProducer().newInstance();
whereClause.getWhereHandler().addWhere(new TriplePath(Triple.ANY));
AbstractQueryBuilder<?> builder = whereClause.addUnion(sb);
ElementUnion union = new ElementUnion();
ElementPathBlock epb = new ElementPathBlock();
union.addElement(epb);
epb.addTriple(Triple.ANY);
Query subQuery = new Query();
ElementSubQuery esq = new ElementSubQuery(subQuery);
union.addElement(esq);
epb = new ElementPathBlock();
subQuery.setQuerySelectType();
subQuery.addProjectVars(Arrays.asList("x"));
subQuery.setQueryPattern(epb);
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
epb.addTriple(t);
WhereValidator visitor = new WhereValidator(union);
Query result = builder.build();
result.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
assertEquals("uri", result.getPrefixMapping().getNsPrefixURI("pfx"));
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddWhereValueRow_array.
@ContractTest
public void testAddWhereValueRow_array() {
final Var v = Var.alloc("v");
final Var x = Var.alloc("x");
WhereClause<?> whereClause = getProducer().newInstance();
whereClause = (WhereClause<?>) whereClause.addWhereValueVar(v);
whereClause = (WhereClause<?>) whereClause.addWhereValueVar(x);
whereClause = (WhereClause<?>) whereClause.addWhereValueRow("<one>", "three");
AbstractQueryBuilder<?> builder = whereClause.addWhereValueRow("<two>", "four");
Query query = builder.build();
ElementData edat = new ElementData();
edat.add(v);
edat.add(x);
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 testSetVarsInSubQuery.
@ContractTest
public void testSetVarsInSubQuery() {
Var v = Var.alloc("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);
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createVariable("v"));
epb.addTriple(t);
WhereValidator visitor = new WhereValidator(esq);
Query result = builder.build();
result.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);
t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
epb.addTriple(t);
visitor = new WhereValidator(esq);
result = builder.build();
result.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddWhereWhereClause.
@ContractTest
public void testAddWhereWhereClause() {
WhereBuilder whereBuilder = new WhereBuilder().addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhere(whereBuilder);
ElementPathBlock epb = new ElementPathBlock();
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
epb.addTriple(t);
WhereValidator 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 testAddGraph_triple.
@ContractTest
public void testAddGraph_triple() {
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>", new Triple(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);
}
Aggregations