Search in sources :

Example 1 with UpdateParser

use of org.apache.jena.sparql.lang.UpdateParser in project jena by apache.

the class UpdateAction method parseExecute.

/**
     * Parse update operations into a GraphStore by parsing from an InputStream.
     * @param usingList    A list of USING or USING NAMED statements that be added to all {@link UpdateWithUsing} queries
     * @param dataset      The dataset to apply the changes to
     * @param input        The source of the update request (must be UTF-8). 
     * @param inputBinding Initial binding to be applied to Update operations that can apply an initial binding
     *                     (i.e. UpdateDeleteWhere, UpdateModify).  May be <code>null</code>
     * @param baseURI      The base URI for resolving relative URIs (may be <code>null</code>)
     * @param syntax       The update language syntax 
     */
public static void parseExecute(UsingList usingList, DatasetGraph dataset, InputStream input, Binding inputBinding, String baseURI, Syntax syntax) {
    UpdateProcessorStreaming uProc = UpdateExecutionFactory.createStreaming(dataset, inputBinding);
    if (uProc == null)
        throw new ARQException("No suitable update procesors are registered/able to execute your updates");
    uProc.startRequest();
    try {
        UpdateSink sink = new UsingUpdateSink(uProc.getUpdateSink(), usingList);
        try {
            UpdateParser parser = UpdateFactory.setupParser(sink.getPrologue(), baseURI, syntax);
            parser.parse(sink, input);
        } finally {
            sink.close();
        }
    } finally {
        uProc.finishRequest();
    }
}
Also used : UsingUpdateSink(org.apache.jena.sparql.modify.UsingUpdateSink) UpdateSink(org.apache.jena.sparql.modify.UpdateSink) UsingUpdateSink(org.apache.jena.sparql.modify.UsingUpdateSink) ARQException(org.apache.jena.sparql.ARQException) UpdateParser(org.apache.jena.sparql.lang.UpdateParser)

Example 2 with UpdateParser

use of org.apache.jena.sparql.lang.UpdateParser in project jena by apache.

the class UpdateFactory method make.

// Worker.
/** Append update operations to a request */
private static void make(UpdateRequest request, String input, String baseURI, Syntax syntax) {
    UpdateParser parser = setupParser(request, baseURI, syntax);
    parser.parse(new UpdateRequestSink(request), input);
}
Also used : UpdateRequestSink(org.apache.jena.sparql.modify.UpdateRequestSink) UpdateParser(org.apache.jena.sparql.lang.UpdateParser)

Example 3 with UpdateParser

use of org.apache.jena.sparql.lang.UpdateParser in project jena by apache.

the class UpdateFactory method make.

/** Append update operations to a request */
private static void make(UpdateRequest request, UsingList usingList, InputStream input, String baseURI, Syntax syntax) {
    UpdateParser parser = setupParser(request, baseURI, syntax);
    UpdateSink sink = new UsingUpdateSink(new UpdateRequestSink(request), usingList);
    try {
        parser.parse(sink, input);
    } finally {
        sink.close();
    }
}
Also used : UsingUpdateSink(org.apache.jena.sparql.modify.UsingUpdateSink) UpdateSink(org.apache.jena.sparql.modify.UpdateSink) UsingUpdateSink(org.apache.jena.sparql.modify.UsingUpdateSink) UpdateRequestSink(org.apache.jena.sparql.modify.UpdateRequestSink) UpdateParser(org.apache.jena.sparql.lang.UpdateParser)

Example 4 with UpdateParser

use of org.apache.jena.sparql.lang.UpdateParser in project jena by apache.

the class UpdateFactory method setupParser.

/** Append update operations to a request */
protected static UpdateParser setupParser(Prologue prologue, String baseURI, Syntax syntax) {
    UpdateParser parser = UpdateParser.createParser(syntax);
    if (parser == null)
        throw new UnsupportedOperationException("Unrecognized syntax for parsing update: " + syntax);
    if (prologue.getResolver() == null) {
        IRIResolver resolver = null;
        try {
            if (baseURI != null)
                // Sort out the baseURI - if that fails, dump in a dummy one and continue.
                resolver = IRIResolver.create(baseURI);
            else
                resolver = IRIResolver.create();
        } catch (Exception ex) {
        }
        if (resolver == null)
            resolver = IRIResolver.create("http://localhost/update/defaultBase#");
        prologue.setResolver(resolver);
    }
    return parser;
}
Also used : IRIResolver(org.apache.jena.riot.system.IRIResolver) UpdateParser(org.apache.jena.sparql.lang.UpdateParser)

Aggregations

UpdateParser (org.apache.jena.sparql.lang.UpdateParser)4 UpdateRequestSink (org.apache.jena.sparql.modify.UpdateRequestSink)2 UpdateSink (org.apache.jena.sparql.modify.UpdateSink)2 UsingUpdateSink (org.apache.jena.sparql.modify.UsingUpdateSink)2 IRIResolver (org.apache.jena.riot.system.IRIResolver)1 ARQException (org.apache.jena.sparql.ARQException)1