Search in sources :

Example 1 with UpdateException

use of org.apache.jena.update.UpdateException in project jena by apache.

the class ExecUpdateHTTPBuilder method build.

public X build() {
    Objects.requireNonNull(serviceURL, "No service URL");
    if (updateOperations == null && updateString == null)
        throw new QueryException("No update for UpdateExecutionHTTP");
    if (updateOperations != null && updateString != null)
        throw new InternalErrorException("UpdateRequest and update string");
    HttpClient hClient = HttpEnv.getHttpClient(serviceURL, httpClient);
    UpdateRequest updateActual = updateOperations;
    if (substitutionMap != null && !substitutionMap.isEmpty()) {
        if (updateActual == null)
            throw new UpdateException("Substitution only supported if an UpdateRequest object was provided");
        updateActual = UpdateTransformOps.transform(updateActual, substitutionMap);
    }
    Context cxt = (context != null) ? context : ARQ.getContext().copy();
    return buildX(hClient, updateActual, cxt);
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryException(org.apache.jena.query.QueryException) UpdateRequest(org.apache.jena.update.UpdateRequest) HttpClient(java.net.http.HttpClient) InternalErrorException(org.apache.jena.atlas.lib.InternalErrorException) UpdateException(org.apache.jena.update.UpdateException)

Example 2 with UpdateException

use of org.apache.jena.update.UpdateException in project jena by apache.

the class SPARQL_Update method execute.

protected void execute(HttpAction action, InputStream input) {
    UsingList usingList = processProtocol(action.getRequest());
    // If the dsg is transactional, then we can parse and execute the update in a streaming fashion.
    // If it isn't, we need to read the entire update request before performing any updates, because
    // we have to attempt to make the request atomic in the face of malformed updates.
    UpdateRequest req = null;
    if (!action.isTransactional()) {
        try {
            req = UpdateFactory.read(usingList, input, UpdateParseBase, Syntax.syntaxARQ);
        } catch (UpdateException ex) {
            ServletOps.errorBadRequest(ex.getMessage());
            return;
        } catch (QueryParseException ex) {
            ServletOps.errorBadRequest(messageForException(ex));
            return;
        }
    }
    action.beginWrite();
    try {
        if (req == null)
            UpdateAction.parseExecute(usingList, action.getActiveDSG(), input, UpdateParseBase, Syntax.syntaxARQ);
        else
            UpdateAction.execute(req, action.getActiveDSG());
        action.commit();
    } catch (UpdateException ex) {
        ActionLib.consumeBody(action);
        abortSilent(action);
        incCounter(action.getEndpoint().getCounters(), UpdateExecErrors);
        ServletOps.errorOccurred(ex.getMessage());
    } catch (QueryParseException ex) {
        ActionLib.consumeBody(action);
        abortSilent(action);
        String msg = messageForParseException(ex);
        action.log.warn(format("[%d] Parse error: %s", action.id, msg));
        ServletOps.errorBadRequest(messageForException(ex));
    } catch (QueryBuildException | QueryExceptionHTTP ex) {
        ActionLib.consumeBody(action);
        abortSilent(action);
        // Counter inc'ed further out.
        String msg = messageForException(ex);
        action.log.warn(format("[%d] Bad request: %s", action.id, msg));
        ServletOps.errorBadRequest(messageForException(ex));
    } catch (OperationDeniedException ex) {
        ActionLib.consumeBody(action);
        abortSilent(action);
        throw ex;
    } catch (Throwable ex) {
        ActionLib.consumeBody(action);
        if (!(ex instanceof ActionErrorException)) {
            abortSilent(action);
            ServletOps.errorOccurred(ex.getMessage(), ex);
        }
    } finally {
        action.end();
    }
}
Also used : UsingList(org.apache.jena.sparql.modify.UsingList) OperationDeniedException(org.apache.jena.shared.OperationDeniedException) UpdateRequest(org.apache.jena.update.UpdateRequest) QueryBuildException(org.apache.jena.query.QueryBuildException) UpdateException(org.apache.jena.update.UpdateException) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) QueryParseException(org.apache.jena.query.QueryParseException)

Example 3 with UpdateException

use of org.apache.jena.update.UpdateException in project jena by apache.

the class ParserSPARQL11Update method _parse.

private void _parse(UpdateSink sink, Reader r) {
    SPARQLParser11 parser = null;
    try {
        parser = new SPARQLParser11(r);
        parser.setUpdateSink(sink);
        parser.UpdateUnit();
    } catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (UpdateException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.error(this, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Example 4 with UpdateException

use of org.apache.jena.update.UpdateException in project jena by apache.

the class UpdateEngineWorker method visit.

@Override
public void visit(UpdateLoad update) {
    // LOAD SILENT? iri ( INTO GraphRef )?
    String source = update.getSource();
    Node dest = update.getDest();
    Graph graph = graph(datasetGraph, dest);
    // We must load buffered if silent so that the dataset graph sees
    // all or no triples/quads when there is a parse error
    // (no nested transaction abort).
    boolean loadBuffered = update.getSilent() || !datasetGraph.supportsTransactionAbort();
    try {
        if (dest == null) {
            // Quads accepted (extension).
            if (loadBuffered) {
                DatasetGraph dsg2 = DatasetGraphFactory.create();
                RDFDataMgr.read(dsg2, source);
                dsg2.find().forEachRemaining(datasetGraph::add);
            } else {
                RDFDataMgr.read(datasetGraph, source);
            }
            return;
        }
        // LOAD SILENT? iri INTO GraphRef
        // Load triples. To give a decent error message and also not have the usual
        // parser behaviour of just selecting default graph triples when the
        // destination is a graph, we need to do the same steps as RDFParser.parseURI,
        // with different checking.
        TypedInputStream input = RDFDataMgr.open(source);
        String contentType = input.getContentType();
        Lang lang = RDFDataMgr.determineLang(source, contentType, Lang.TTL);
        if (lang == null)
            throw new UpdateException("Failed to determine the syntax for '" + source + "'");
        if (!RDFLanguages.isTriples(lang))
            throw new UpdateException("Attempt to load quads into a graph");
        RDFParser parser = RDFParser.source(input.getInputStream()).forceLang(lang).build();
        if (loadBuffered) {
            Graph g = GraphFactory.createGraphMem();
            parser.parse(g);
            GraphUtil.addInto(graph, g);
        } else {
            parser.parse(graph);
        }
    } catch (RuntimeException ex) {
        if (!update.getSilent()) {
            if (ex instanceof UpdateException)
                throw ex;
            throw new UpdateException("Failed to LOAD '" + source + "' :: " + ex.getMessage(), ex);
        }
    }
}
Also used : ElementNamedGraph(org.apache.jena.sparql.syntax.ElementNamedGraph) TemplateLib.remapDefaultGraph(org.apache.jena.sparql.modify.TemplateLib.remapDefaultGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) Lang(org.apache.jena.riot.Lang) UpdateException(org.apache.jena.update.UpdateException) RDFParser(org.apache.jena.riot.RDFParser) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream)

Example 5 with UpdateException

use of org.apache.jena.update.UpdateException in project jena by apache.

the class ParserSPARQL11Update method executeParse.

@Override
protected void executeParse(UpdateSink sink, Prologue prologue, Reader r) {
    SPARQLParser11 parser = null;
    try {
        parser = new SPARQLParser11(r);
        parser.setUpdate(prologue, sink);
        parser.UpdateUnit();
    } catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
        throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
    } catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
        // Last valid token : not the same as token error message - but this
        // should not happen
        int col = parser.token.endColumn;
        int line = parser.token.endLine;
        throw new QueryParseException(tErr.getMessage(), line, col);
    } catch (UpdateException ex) {
        throw ex;
    } catch (JenaException ex) {
        throw new QueryException(ex.getMessage(), ex);
    } catch (Error err) {
        // The token stream can throw errors.
        throw new QueryParseException(err.getMessage(), err, -1, -1);
    } catch (Throwable th) {
        Log.error(this, "Unexpected throwable: ", th);
        throw new QueryException(th.getMessage(), th);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) QueryException(org.apache.jena.query.QueryException) SPARQLParser11(org.apache.jena.sparql.lang.sparql_11.SPARQLParser11) UpdateException(org.apache.jena.update.UpdateException) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

UpdateException (org.apache.jena.update.UpdateException)7 QueryException (org.apache.jena.query.QueryException)3 QueryParseException (org.apache.jena.query.QueryParseException)3 UpdateRequest (org.apache.jena.update.UpdateRequest)3 JenaException (org.apache.jena.shared.JenaException)2 SPARQLParser11 (org.apache.jena.sparql.lang.sparql_11.SPARQLParser11)2 Context (org.apache.jena.sparql.util.Context)2 HttpClient (java.net.http.HttpClient)1 InternalErrorException (org.apache.jena.atlas.lib.InternalErrorException)1 TypedInputStream (org.apache.jena.atlas.web.TypedInputStream)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 QueryBuildException (org.apache.jena.query.QueryBuildException)1 Lang (org.apache.jena.riot.Lang)1 RDFParser (org.apache.jena.riot.RDFParser)1 OperationDeniedException (org.apache.jena.shared.OperationDeniedException)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)1 TemplateLib.remapDefaultGraph (org.apache.jena.sparql.modify.TemplateLib.remapDefaultGraph)1 UpdateEngineFactory (org.apache.jena.sparql.modify.UpdateEngineFactory)1