Search in sources :

Example 6 with ElementData

use of org.apache.jena.sparql.syntax.ElementData in project jena by apache.

the class WhereClauseTest method testAddWhereValueVar_var_values.

@ContractTest
public void testAddWhereValueVar_var_values() {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueVar("?v", "<one>");
    Query query = builder.build();
    final Var v = Var.alloc("v");
    Binding binding = BindingFactory.binding(v, NodeFactory.createURI("one"));
    ElementData edat = new ElementData();
    edat.add(v);
    edat.add(binding);
    WhereValidator visitor = new WhereValidator(edat);
    query.getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 7 with ElementData

use of org.apache.jena.sparql.syntax.ElementData in project jena by apache.

the class WhereClauseTest method testAddWhereValueRow_array_Node_Variable.

@ContractTest
public void testAddWhereValueRow_array_Node_Variable() {
    WhereClause<?> whereClause = getProducer().newInstance();
    whereClause = (WhereClause<?>) whereClause.addWhereValueVar(NodeFactory.createVariable("v"));
    whereClause = (WhereClause<?>) whereClause.addWhereValueVar(NodeFactory.createVariable("x"));
    whereClause = (WhereClause<?>) whereClause.addWhereValueRow("<one>", "three");
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueRow("<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);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 8 with ElementData

use of org.apache.jena.sparql.syntax.ElementData in project jena by apache.

the class WhereClauseTest method testAddWhereValueRow_collection.

@ContractTest
public void testAddWhereValueRow_collection() {
    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(Arrays.asList("<one>", "three"));
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueRow(Arrays.asList("<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);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 9 with ElementData

use of org.apache.jena.sparql.syntax.ElementData 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);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 10 with ElementData

use of org.apache.jena.sparql.syntax.ElementData 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);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) Node(org.apache.jena.graph.Node) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ElementData (org.apache.jena.sparql.syntax.ElementData)20 Var (org.apache.jena.sparql.core.Var)19 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)18 Query (org.apache.jena.query.Query)11 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)11 ContractTest (org.xenei.junit.contract.ContractTest)11 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 Binding (org.apache.jena.sparql.engine.binding.Binding)7 Test (org.junit.Test)7 Node (org.apache.jena.graph.Node)6 HashMap (java.util.HashMap)5 List (java.util.List)4 LinkedHashMap (java.util.LinkedHashMap)2 ArrayList (java.util.ArrayList)1 QueryBuildException (org.apache.jena.query.QueryBuildException)1 BindingBuilder (org.apache.jena.sparql.engine.binding.BindingBuilder)1