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