use of org.apache.jena.sparql.syntax.ElementBind in project jena by apache.
the class ElementRewriter method visit.
@Override
public void visit(ElementBind el) {
Node n = changeNode(el.getVar());
if (n.equals(el.getVar())) {
ExprRewriter exprRewriter = new ExprRewriter(values);
el.getExpr().visit(exprRewriter);
push(new ElementBind(el.getVar(), exprRewriter.getResult()));
} else {
// push( new ElementBind( el.getVar(), NodeValue.makeNode( n )) );
// no op
push(new ElementTriplesBlock());
}
}
use of org.apache.jena.sparql.syntax.ElementBind in project jena by apache.
the class WhereHandlerTest method testBindExprVar.
@Test
public void testBindExprVar() {
Var v = Var.alloc("foo");
handler.addBind(new E_Random(), v);
handler.build();
ElementBind bind = new ElementBind(Var.alloc("foo"), new E_Random());
WhereValidator visitor = new WhereValidator(bind);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementBind in project jena by apache.
the class WhereHandlerTest method testBindStringVar.
@Test
public void testBindStringVar() throws ParseException {
Var v = Var.alloc("foo");
handler.addBind("rand()", v);
handler.build();
ElementBind bind = new ElementBind(Var.alloc("foo"), new E_Random());
WhereValidator visitor = new WhereValidator(bind);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementBind in project jena by apache.
the class WhereClauseTest method testBindStringVar_Node_Variable.
@ContractTest
public void testBindStringVar_Node_Variable() throws ParseException {
Node v = NodeFactory.createVariable("foo");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addBind("rand()", v);
Query query = builder.build();
ElementBind bind = new ElementBind(Var.alloc(v), new E_Random());
WhereValidator visitor = new WhereValidator(bind);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
Node three = NodeFactory.createURI("three");
builder.setVar(v, three);
query = builder.build();
visitor = new WhereValidator(new ElementTriplesBlock());
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementBind in project jena by apache.
the class WhereClauseTest method testBindExprVar.
@ContractTest
public void testBindExprVar() {
Var v = Var.alloc("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);
}
Aggregations