Search in sources :

Example 21 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class UpdateAction method parseExecute.

/**
 * Parse update operations into a DatasetGraph 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) {
    @SuppressWarnings("deprecation") 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(uProc.getPrologue(), baseURI, syntax);
            parser.parse(sink, uProc.getPrologue(), 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 22 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class UpdateAction method execute$.

// All non-streaming updates come through here.
private static void execute$(UpdateRequest request, DatasetGraph datasetGraph, Binding inputBinding) {
    UpdateExec uProc = UpdateExec.newBuilder().update(request).dataset(datasetGraph).initialBinding(inputBinding).build();
    if (uProc == null)
        throw new ARQException("No suitable update procesors are registered/able to execute your updates");
    uProc.execute();
}
Also used : ARQException(org.apache.jena.sparql.ARQException) UpdateExec(org.apache.jena.sparql.exec.UpdateExec)

Example 23 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class RowSetReaderCSV method booleanFromCSV.

/**
 * Read boolean after header
 */
private static boolean booleanFromCSV(CSVParser parser) {
    List<String> line = parser.parse1();
    if (line.size() != 1) {
        throw new ARQException("CSV Boolean Results malformed: data line='" + line + "'");
    }
    String str = line.get(0);
    boolean b;
    if (str.equalsIgnoreCase("true") || str.equalsIgnoreCase("yes"))
        b = true;
    else if (str.equalsIgnoreCase("false") || str.equalsIgnoreCase("no"))
        b = false;
    else {
        throw new ARQException("CSV Boolean Results malformed, expected one of - true yes false no - but got " + str);
    }
    List<String> line2 = parser.parse1();
    if (line2 != null) {
        FmtLog.warn(log, "Extra rows: first is " + line2);
    }
    return b;
}
Also used : ARQException(org.apache.jena.sparql.ARQException)

Example 24 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class RowSetReaderTSV method resultSetFromTSV.

/**
 * Reads SPARQL Results from TSV format into a {@link RowSet} instance
 * @param in Input Stream
 */
public static RowSet resultSetFromTSV(InputStream in) {
    BufferedReader reader = IO.asBufferedUTF8(in);
    List<Var> vars = new ArrayList<>();
    String str = null;
    try {
        // Here we try to parse only the Header Row
        str = reader.readLine();
        if (str == null)
            throw new ARQException("TSV Results malformed, input is empty (no header row)");
        if (!str.isEmpty()) {
            String[] tokens = pattern.split(str, -1);
            for (String token : tokens) {
                Node v;
                try {
                    v = NodeFactoryExtra.parseNode(token);
                    if (v == null || !v.isVariable())
                        throw new ResultSetException("TSV Results malformed, not a variable: " + token);
                } catch (RiotException ex) {
                    throw new ResultSetException("TSV Results malformed, variable names must begin with a ? in the header: " + token);
                }
                Var var = Var.alloc(v);
                vars.add(var);
            }
        }
    } catch (IOException ex) {
        throw new ARQException(ex);
    }
    // This will parse actual result rows as needed thus minimising memory usage
    return RowSetStream.create(vars, new TSVInputIterator(reader, vars));
}
Also used : ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) RiotException(org.apache.jena.riot.RiotException) ARQException(org.apache.jena.sparql.ARQException) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 25 with ARQException

use of org.apache.jena.sparql.ARQException in project jena by apache.

the class OpExtRegistry method register.

public static void register(OpExtBuilder builder) {
    extensions.put(builder.getTagName(), builder);
    if (BuilderOp.contains(builder.getTagName()))
        throw new ARQException("Tag '" + builder.getTagName() + "' already defined");
    BuilderOp.add(builder.getTagName(), buildExt2);
}
Also used : ARQException(org.apache.jena.sparql.ARQException)

Aggregations

ARQException (org.apache.jena.sparql.ARQException)48 IOException (java.io.IOException)11 Var (org.apache.jena.sparql.core.Var)7 ArrayList (java.util.ArrayList)5 Lang (org.apache.jena.riot.Lang)5 BufferedReader (java.io.BufferedReader)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 Node (org.apache.jena.graph.Node)4 Syntax (org.apache.jena.query.Syntax)4 RDFNode (org.apache.jena.rdf.model.RDFNode)4 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Triple (org.apache.jena.graph.Triple)2 Query (org.apache.jena.query.Query)2 Model (org.apache.jena.rdf.model.Model)2 Resource (org.apache.jena.rdf.model.Resource)2 RiotException (org.apache.jena.riot.RiotException)2 HttpParams (org.apache.jena.sparql.engine.http.HttpParams)2 Item (org.apache.jena.sparql.sse.Item)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 BufferedWriter (java.io.BufferedWriter)1