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();
}
}
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();
}
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;
}
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));
}
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);
}
Aggregations