Search in sources :

Example 11 with QueryExecException

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

the class QueryIterAssign method accept.

@Override
public Binding accept(Binding binding) {
    BindingMap b = BindingFactory.create(binding);
    for (Var v : exprs.getVars()) {
        // if "binding", not "b" used, we get (Lisp) "let" 
        // semantics, not the desired "let*" semantics
        Node n = exprs.get(v, b, getExecContext());
        if (n == null)
            // Expression failed to evaluate - no assignment
            continue;
        // Check is already has a value; if so, must be sameValueAs
        if (b.contains(v)) {
            // Optimization may linearize to push a stream through an (extend).
            if (false && mustBeNewVar)
                throw new QueryExecException("Already set: " + v);
            Node n2 = b.get(v);
            if (!n2.sameValueAs(n))
                // Error in single assignment.
                return null;
            continue;
        }
        b.add(v, n);
    }
    return b;
}
Also used : Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BindingMap(org.apache.jena.sparql.engine.binding.BindingMap) QueryExecException(org.apache.jena.query.QueryExecException)

Example 12 with QueryExecException

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

the class QueryEngineBase method prepareDataset.

private DatasetGraph prepareDataset(DatasetGraph originalDataset, Query query) {
    DatasetDescription dsDesc = DatasetDescription.create(query, context);
    DatasetGraph dsg = originalDataset;
    if (dsg != null) {
        if (dsDesc != null) {
            if (query.hasDatasetDescription())
                dsg = dynamicDataset(dsDesc, dsg, false);
        }
        return dsg;
    }
    // No DatasetGraph
    if (!query.hasDatasetDescription())
        throw new QueryExecException("No dataset and no dataset description for query");
    // DatasetDescription : Build it.
    String baseURI = query.getBaseURI();
    if (baseURI == null)
        baseURI = IRIs.getSystemBase().str();
    dsg = DatasetUtils.createDatasetGraph(dsDesc, baseURI);
    return dsg;
}
Also used : QueryExecException(org.apache.jena.query.QueryExecException) DatasetDescription(org.apache.jena.sparql.core.DatasetDescription) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 13 with QueryExecException

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

the class QueryExecDataset method constructQuads.

// -- Construct Quads
@Override
public Iterator<Quad> constructQuads() {
    checkNotClosed();
    if (!query.isConstructType())
        throw new QueryExecException("Attempt to get a CONSTRUCT model from a " + labelForQuery(query) + " query");
    // This causes there to be no PROJECT around the pattern.
    // That in turn, exposes the initial bindings.
    query.setQueryResultStar(true);
    startQueryIterator();
    Template template = query.getConstructTemplate();
    return TemplateLib.calcQuads(template.getQuads(), queryIterator);
}
Also used : QueryExecException(org.apache.jena.query.QueryExecException) Template(org.apache.jena.sparql.syntax.Template)

Example 14 with QueryExecException

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

the class QueryExecDataset method constructTriples.

@Override
public Iterator<Triple> constructTriples() {
    checkNotClosed();
    if (!query.isConstructType())
        throw new QueryExecException("Attempt to get a CONSTRUCT model from a " + labelForQuery(query) + " query");
    // This causes there to be no PROJECT around the pattern.
    // That in turn, exposes the initial bindings.
    query.setQueryResultStar(true);
    startQueryIterator();
    Template template = query.getConstructTemplate();
    return TemplateLib.calcTriples(template.getTriples(), queryIterator);
}
Also used : QueryExecException(org.apache.jena.query.QueryExecException) Template(org.apache.jena.sparql.syntax.Template)

Example 15 with QueryExecException

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

the class QueryExecDataset method ask.

@Override
public boolean ask() {
    checkNotClosed();
    if (!query.isAskType())
        throw new QueryExecException("Attempt to have boolean from a " + labelForQuery(query) + " query");
    startQueryIterator();
    boolean r;
    try {
        // Not hasNext because setting timeout1 which applies to getting
        // the first result, not testing for it.
        queryIterator.next();
        r = true;
    } catch (NoSuchElementException ex) {
        r = false;
    } finally {
        this.close();
    }
    return r;
}
Also used : QueryExecException(org.apache.jena.query.QueryExecException)

Aggregations

QueryExecException (org.apache.jena.query.QueryExecException)16 Node (org.apache.jena.graph.Node)5 Var (org.apache.jena.sparql.core.Var)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4 HashMap (java.util.HashMap)2 Query (org.apache.jena.query.Query)2 RDFNode (org.apache.jena.rdf.model.RDFNode)2 Op (org.apache.jena.sparql.algebra.Op)2 OpAsQuery (org.apache.jena.sparql.algebra.OpAsQuery)2 HttpParams (org.apache.jena.sparql.engine.http.HttpParams)2 Template (org.apache.jena.sparql.syntax.Template)2 InputStream (java.io.InputStream)1 HttpClient (java.net.http.HttpClient)1 List (java.util.List)1 Map (java.util.Map)1 IndentedLineBuffer (org.apache.jena.atlas.io.IndentedLineBuffer)1 JsonArray (org.apache.jena.atlas.json.JsonArray)1 JsonObject (org.apache.jena.atlas.json.JsonObject)1 JsonValue (org.apache.jena.atlas.json.JsonValue)1 HttpException (org.apache.jena.atlas.web.HttpException)1