use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testSetVarsInUnion.
@ContractTest
public void testSetVarsInUnion() {
Var v = Var.alloc("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, 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);
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 testAddWhereValueVars_Node_Variable.
@ContractTest
public void testAddWhereValueVars_Node_Variable() {
Map<Object, List<?>> map = new HashMap<Object, List<?>>();
map.put(NodeFactory.createVariable("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");
Var v = Var.alloc("v");
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 testAddWhereValueVars_InSubQuery.
@ContractTest
public void testAddWhereValueVars_InSubQuery() {
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();
WhereClause<?> whereClause2 = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhereValueVars(map);
builder = whereClause2.addSubQuery(builder);
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 testBindExprVar_Node_Variable.
@ContractTest
public void testBindExprVar_Node_Variable() {
Node v = NodeFactory.createVariable("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind(new E_Random(), v);
Query query = builder.build();
WhereValidator visitor = new WhereValidator(new ElementBind(Var.alloc("foo"), new E_Random()));
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, NodeFactory.createURI("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 testAddWhereValueRow_collection_Node_Variable.
@ContractTest
public void testAddWhereValueRow_collection_Node_Variable() {
WhereClause<?> whereClause = getProducer().newInstance();
whereClause = (WhereClause<?>) whereClause.addWhereValueVar(NodeFactory.createVariable("v"));
whereClause = (WhereClause<?>) whereClause.addWhereValueVar(NodeFactory.createVariable("x"));
whereClause = (WhereClause<?>) whereClause.addWhereValueRow(Arrays.asList("<one>", "three"));
AbstractQueryBuilder<?> builder = whereClause.addWhereValueRow(Arrays.asList("<two>", "four"));
Query query = builder.build();
ElementData edat = new ElementData();
final Var v = Var.alloc("v");
final Var x = Var.alloc("x");
edat.add(v);
edat.add(x);
setupBindings(edat, x, v);
WhereValidator visitor = new WhereValidator(edat);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations