Search in sources :

Example 11 with ElementData

use of org.apache.jena.sparql.syntax.ElementData 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);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) ContractTest(org.xenei.junit.contract.ContractTest)

Example 12 with ElementData

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

the class WhereHandlerTest method testAddValueRow_pfx_collection.

@Test
public void testAddValueRow_pfx_collection() {
    final Var v = Var.alloc("v");
    final Var x = Var.alloc("x");
    handler.addValueVar(query.getPrefixMapping(), v);
    handler.addValueVar(query.getPrefixMapping(), x);
    handler.addValueRow(query.getPrefixMapping(), Arrays.asList("<one>", "three"));
    handler.addValueRow(query.getPrefixMapping(), Arrays.asList("<two>", "four"));
    handler.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 : Var(org.apache.jena.sparql.core.Var) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementData(org.apache.jena.sparql.syntax.ElementData) Test(org.junit.Test)

Example 13 with ElementData

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

the class ValuesHandlerTest method testAsElement.

@Test
public void testAsElement() {
    final Var v = Var.alloc("v");
    final Var x = Var.alloc("x");
    final Node one = NodeFactory.createURI("one");
    final Node two = NodeFactory.createURI("two");
    final Node three = NodeFactory.createLiteral("three");
    final Node four = NodeFactory.createLiteral("four");
    handler.addValueVar(v, Arrays.asList(one, two));
    handler.addValueVar(x, Arrays.asList(three, four));
    ElementData edat = new ElementData();
    edat.add(v);
    edat.add(x);
    Binding binding1 = BindingFactory.binding(v, NodeFactory.createURI("one"), x, NodeFactory.createLiteral("three"));
    edat.add(binding1);
    Binding binding2 = BindingFactory.binding(v, NodeFactory.createURI("two"), x, NodeFactory.createLiteral("four"));
    edat.add(binding2);
    WhereValidator visitor = new WhereValidator(edat);
    handler.asElement().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) 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) Test(org.junit.Test)

Example 14 with ElementData

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

the class WhereClauseTest method testAddWhereValueRow_array.

@ContractTest
public void testAddWhereValueRow_array() {
    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("<one>", "three");
    AbstractQueryBuilder<?> builder = whereClause.addWhereValueRow("<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 15 with ElementData

use of org.apache.jena.sparql.syntax.ElementData 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);
}
Also used : 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) List(java.util.List) 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