use of org.apache.jena.arq.querybuilder.WhereValidator 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.WhereValidator in project jena by apache.
the class WhereClauseTest method testSetVarsInWhereValues_NodeVariable.
@ContractTest
public void testSetVarsInWhereValues_NodeVariable() {
Node v = NodeFactory.createVariable("v");
Node value = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?x", "<one>", "?v");
builder.setVar(v, value);
Query query = builder.build();
ElementData edat = new ElementData();
Var x = Var.alloc("x");
edat.add(x);
Binding binding1 = BindingFactory.binding(x, NodeFactory.createURI("one"));
edat.add(binding1);
Binding binding2 = BindingFactory.binding(x, value);
edat.add(binding2);
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 testAddOptionalStringWithPath.
@ContractTest
public void testAddOptionalStringWithPath() {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional("<one>", "<two>/<dos>", "three");
Path path = new P_Seq(new P_Link(NodeFactory.createURI("two")), new P_Link(NodeFactory.createURI("dos")));
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createLiteral("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 testSetVarsInWhereValues.
@ContractTest
public void testSetVarsInWhereValues() {
Var v = Var.alloc("v");
Node value = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
Map<Var, Node> values = new HashMap<>();
values.put(v, value);
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?x", "<one>", "?v");
builder.setVar(v, value);
Query query = builder.build();
ElementData edat = new ElementData();
Var x = Var.alloc("x");
edat.add(x);
Binding binding1 = BindingFactory.binding(x, NodeFactory.createURI("one"));
edat.add(binding1);
Binding binding2 = BindingFactory.binding(x, value);
edat.add(binding2);
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 testAddWhereValueVar_var.
@ContractTest
public void testAddWhereValueVar_var() {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?v");
Query query = builder.build();
ElementData edat = new ElementData();
edat.add(Var.alloc("v"));
WhereValidator visitor = new WhereValidator(edat);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations