Search in sources :

Example 86 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class QBQuadHolder method getQuads.

@Override
public ExtendedIterator<Quad> getQuads() {
    Query q = qb.build();
    QuadIteratorBuilder builder = new QuadIteratorBuilder(defaultGraphName);
    q.getQueryPattern().visit(builder);
    return builder.iter;
}
Also used : Query(org.apache.jena.query.Query)

Example 87 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class QuadIteratorBuilder method visit.

@Override
public void visit(ElementSubQuery el) {
    Query q = el.getQuery();
    q.getQueryPattern().visit(this);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query)

Example 88 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class WhereClauseTest method testBindStringVar.

@ContractTest
public void testBindStringVar() throws ParseException {
    Var v = Var.alloc("foo");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addBind("rand()", v);
    assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("three"));
    Query q = builder.build();
    ElementGroup eg = (ElementGroup) q.getQueryPattern();
    List<Element> lst = eg.getElements();
    assertEquals("Should only be one element", 1, lst.size());
    assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
    ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
    assertTrue("ElementGroup should be empty", etb.isEmpty());
}
Also used : Query(org.apache.jena.query.Query) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ContractTest(org.xenei.junit.contract.ContractTest)

Example 89 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class WhereClauseTest method testAddOptionalGroupPattern.

@ContractTest
public void testAddOptionalGroupPattern() throws ParseException {
    Var s = Var.alloc("s");
    Node q = NodeFactory.createURI("urn:q");
    Node v = NodeFactory.createURI("urn:v");
    Var x = Var.alloc("x");
    Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
    SelectBuilder pattern = new SelectBuilder();
    pattern.addWhere(new Triple(s, q, n123));
    pattern.addWhere(new Triple(s, v, x));
    pattern.addFilter("?x>56");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addOptional(pattern);
    Query expected = QueryFactory.create("SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
    Assert.assertEquals(expected.getQueryPattern(), builder.build().getQueryPattern());
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ContractTest(org.xenei.junit.contract.ContractTest)

Example 90 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class AbstractClauseTest method getQuery.

protected static final Query getQuery(AbstractQueryBuilder<?> builder) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    Field f = AbstractQueryBuilder.class.getDeclaredField("query");
    f.setAccessible(true);
    return (Query) f.get(builder);
}
Also used : Field(java.lang.reflect.Field) Query(org.apache.jena.query.Query)

Aggregations

Query (org.apache.jena.query.Query)106 Test (org.junit.Test)22 Op (org.apache.jena.sparql.algebra.Op)17 QueryExecution (org.apache.jena.query.QueryExecution)13 ResultSet (org.apache.jena.query.ResultSet)11 Var (org.apache.jena.sparql.core.Var)11 HashMap (java.util.HashMap)9 QuerySolution (org.apache.jena.query.QuerySolution)9 ContractTest (org.xenei.junit.contract.ContractTest)9 Node (org.apache.jena.graph.Node)8 WhereHandler (org.apache.jena.arq.querybuilder.handlers.WhereHandler)7 VarExprList (org.apache.jena.sparql.core.VarExprList)7 Element (org.apache.jena.sparql.syntax.Element)7 Triple (org.apache.jena.graph.Triple)6 Before (org.junit.Before)6 Map (java.util.Map)5 QueryEngineHTTP (org.apache.jena.sparql.engine.http.QueryEngineHTTP)5 Context (org.apache.jena.sparql.util.Context)5 StringReader (java.io.StringReader)4 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)4