Search in sources :

Example 1 with UsingList

use of org.apache.jena.sparql.modify.UsingList 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 2 with UsingList

use of org.apache.jena.sparql.modify.UsingList in project jena by apache.

the class SPARQL_Update method processProtocol.

/* [It is an error to supply the using-graph-uri or using-named-graph-uri parameters
     * when using this protocol to convey a SPARQL 1.1 Update request that contains an
     * operation that uses the USING, USING NAMED, or WITH clause.]
     *
     * We will simply capture any using parameters here and pass them to the parser, which will be
     * responsible for throwing an UpdateException if the query violates the above requirement,
     * and will also be responsible for adding the using parameters to update queries that can
     * accept them.
     */
private UsingList processProtocol(HttpServletRequest request) {
    UsingList toReturn = new UsingList();
    String[] usingArgs = request.getParameterValues(paramUsingGraphURI);
    String[] usingNamedArgs = request.getParameterValues(paramUsingNamedGraphURI);
    if (usingArgs == null && usingNamedArgs == null)
        return toReturn;
    if (usingArgs == null)
        usingArgs = new String[0];
    if (usingNamedArgs == null)
        usingNamedArgs = new String[0];
    for (String nodeUri : usingArgs) {
        toReturn.addUsing(createNode(nodeUri));
    }
    for (String nodeUri : usingNamedArgs) {
        toReturn.addUsingNamed(createNode(nodeUri));
    }
    return toReturn;
}
Also used : UsingList(org.apache.jena.sparql.modify.UsingList)

Aggregations

UsingList (org.apache.jena.sparql.modify.UsingList)2 QueryBuildException (org.apache.jena.query.QueryBuildException)1 QueryParseException (org.apache.jena.query.QueryParseException)1 OperationDeniedException (org.apache.jena.shared.OperationDeniedException)1 QueryExceptionHTTP (org.apache.jena.sparql.engine.http.QueryExceptionHTTP)1 UpdateException (org.apache.jena.update.UpdateException)1 UpdateRequest (org.apache.jena.update.UpdateRequest)1