Search in sources :

Example 1 with ElementBind

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());
    }
}
Also used : ElementBind(org.apache.jena.sparql.syntax.ElementBind) Node(org.apache.jena.graph.Node) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock)

Example 2 with ElementBind

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);
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) ElementBind(org.apache.jena.sparql.syntax.ElementBind) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Test(org.junit.Test)

Example 3 with ElementBind

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);
}
Also used : ElementBind(org.apache.jena.sparql.syntax.ElementBind) E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Test(org.junit.Test)

Example 4 with ElementBind

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);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ElementBind(org.apache.jena.sparql.syntax.ElementBind) E_Random(org.apache.jena.sparql.expr.E_Random) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Example 5 with ElementBind

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);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) E_Random(org.apache.jena.sparql.expr.E_Random) ElementBind(org.apache.jena.sparql.syntax.ElementBind) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ElementBind (org.apache.jena.sparql.syntax.ElementBind)7 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)6 E_Random (org.apache.jena.sparql.expr.E_Random)6 ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)5 Node (org.apache.jena.graph.Node)4 Query (org.apache.jena.query.Query)4 Var (org.apache.jena.sparql.core.Var)4 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)4 ContractTest (org.xenei.junit.contract.ContractTest)4 ExprVar (org.apache.jena.sparql.expr.ExprVar)2 Test (org.junit.Test)2