Search in sources :

Example 16 with ElementSubQuery

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

the class WhereHandlerTest method testMakeSubQueryFromSelectWithOutVar.

@Test
public void testMakeSubQueryFromSelectWithOutVar() {
    SelectBuilder sb = new SelectBuilder().addWhere("?x", RDF.type, RDF.Alt);
    ElementSubQuery esq = handler.makeSubQuery(sb);
    Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
    TriplePath tp = new TriplePath(t1);
    ElementPathBlock epb = new ElementPathBlock();
    epb.addTriple(tp);
    Query q = new Query();
    q.setQuerySelectType();
    q.setQueryResultStar(true);
    q.setQueryPattern(epb);
    ElementSubQuery esq2 = new ElementSubQuery(q);
    WhereValidator wv = new WhereValidator(esq2);
    esq.visit(wv);
    assertTrue(wv.matching);
}
Also used : Triple(org.apache.jena.graph.Triple) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) TriplePath(org.apache.jena.sparql.core.TriplePath) SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) ElementPathBlock(org.apache.jena.sparql.syntax.ElementPathBlock) Test(org.junit.Test)

Example 17 with ElementSubQuery

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

the class WhereHandler method makeSubQuery.

/**
 * Convert a subquery into a subquery element.
 *
 * @param subQuery The sub query to convert
 * @return THe converted element.
 */
public ElementSubQuery makeSubQuery(AbstractQueryBuilder<?> subQuery) {
    Query q = new Query();
    q.setQuerySelectType();
    PrologHandler ph = new PrologHandler(query);
    ph.addPrefixes(subQuery.getPrologHandler().getPrefixes());
    HandlerBlock handlerBlock = new HandlerBlock(q);
    handlerBlock.addAll(subQuery.getHandlerBlock());
    // remove the prefix mappings from the sub query.
    handlerBlock.getPrologHandler().clearPrefixes();
    // make sure we have a query pattern before we start building.
    if (q.getQueryPattern() == null) {
        q.setQueryPattern(new ElementGroup());
    }
    handlerBlock.build();
    return new ElementSubQuery(q);
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup)

Example 18 with ElementSubQuery

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

the class ElementRewriter method visit.

@Override
public void visit(ElementSubQuery el) {
    Query q = AbstractQueryBuilder.clone(el.getQuery());
    push(new ElementSubQuery(AbstractQueryBuilder.rewrite(q, values)));
}
Also used : ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) ElementSubQuery(org.apache.jena.sparql.syntax.ElementSubQuery) Query(org.apache.jena.query.Query)

Example 19 with ElementSubQuery

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

the class QuadIteratorBuilder method visit.

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

Aggregations

Query (org.apache.jena.query.Query)19 ElementSubQuery (org.apache.jena.sparql.syntax.ElementSubQuery)19 WhereValidator (org.apache.jena.arq.querybuilder.WhereValidator)15 ElementPathBlock (org.apache.jena.sparql.syntax.ElementPathBlock)15 Triple (org.apache.jena.graph.Triple)14 TriplePath (org.apache.jena.sparql.core.TriplePath)13 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)11 Test (org.junit.Test)11 ContractTest (org.xenei.junit.contract.ContractTest)4 FrontsTriple (org.apache.jena.graph.FrontsTriple)3 ElementUnion (org.apache.jena.sparql.syntax.ElementUnion)3 Var (org.apache.jena.sparql.core.Var)2 HttpClient (java.net.http.HttpClient)1 AskBuilder (org.apache.jena.arq.querybuilder.AskBuilder)1 ConstructBuilder (org.apache.jena.arq.querybuilder.ConstructBuilder)1 DescribeBuilder (org.apache.jena.arq.querybuilder.DescribeBuilder)1 WhereBuilder (org.apache.jena.arq.querybuilder.WhereBuilder)1 HttpException (org.apache.jena.atlas.web.HttpException)1 Node (org.apache.jena.graph.Node)1 RegistryHttpClient (org.apache.jena.http.RegistryHttpClient)1