use of org.apache.jena.sparql.core.Transactional in project jena by apache.
the class query method queryExec.
protected void queryExec(boolean timed, ResultsFormat fmt) {
try {
Query query = modQuery.getQuery();
if (isVerbose()) {
IndentedWriter out = new IndentedWriter(System.out, true);
query.serialize(out);
out.flush();
System.out.println();
}
if (isQuiet())
LogCtl.setError(SysRIOT.riotLoggerName);
Dataset dataset = getDataset(query);
// The default policy is to create an empty one - convenience for VALUES and BIND providing the data.
if (dataset == null && !query.hasDatasetDescription()) {
System.err.println("Dataset not specified in query nor provided on command line.");
throw new TerminationException(1);
}
Transactional transactional = (dataset != null && dataset.supportsTransactionAbort()) ? dataset : new TransactionalNull();
Txn.executeRead(transactional, () -> {
modTime.startTimer();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
try {
QueryExecUtils.executeQuery(query, qe, fmt);
} catch (QueryCancelledException ex) {
System.out.flush();
System.err.println("Query timed out");
}
long time = modTime.endTimer();
if (timed) {
totalTime += time;
System.err.println("Time: " + modTime.timeStr(time) + " sec");
}
} catch (ResultSetException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
} catch (QueryException qEx) {
// System.err.println(qEx.getMessage()) ;
throw new CmdException("Query Exeception", qEx);
}
});
} catch (ARQInternalErrorException intEx) {
System.err.println(intEx.getMessage());
if (intEx.getCause() != null) {
System.err.println("Cause:");
intEx.getCause().printStackTrace(System.err);
System.err.println();
}
intEx.printStackTrace(System.err);
} catch (JenaException | CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
use of org.apache.jena.sparql.core.Transactional in project jena by apache.
the class TestTxn method txn_threaded_03.
@Test
public void txn_threaded_03() {
Transactional tx = DatasetGraphFactory.createTxnMem();
// Transactional tx = counter;
// Start and enter the W transaction.
ThreadAction a = ThreadTxn.threadTxnWriteAbort(tx, () -> {
});
// ThreadAction started ... in W transaction.
Txn.exec(tx, TxnType.READ_PROMOTE, () -> {
// ... have the thread action abort..
a.run();
// Does not block promotion.
boolean b = tx.promote();
assertTrue(b);
assertEquals(ReadWrite.WRITE, tx.transactionMode());
});
}
use of org.apache.jena.sparql.core.Transactional in project jena by apache.
the class update method execUpdate.
// Subclass for specialised commands making common updates more convenient
@Override
protected void execUpdate(DatasetGraph graphStore) {
if (requestFiles.size() == 0 && getPositional().size() == 0)
throw new CmdException("Nothing to do");
Transactional transactional = graphStore;
for (String filename : requestFiles) Txn.executeWrite(transactional, () -> execOneFile(filename, graphStore));
for (String requestString : super.getPositional()) {
String requestString2 = indirect(requestString);
Txn.executeWrite(transactional, () -> execOne(requestString2, graphStore));
}
if (!(transactional instanceof DatasetGraph))
// Unlikely/impossible in Jena 3.7.0 onwards.
SystemARQ.sync(graphStore);
if (dump)
Txn.executeRead(transactional, () -> RDFDataMgr.write(System.out, graphStore, Lang.TRIG));
}
use of org.apache.jena.sparql.core.Transactional in project jena by apache.
the class query method queryExec.
protected void queryExec(boolean timed, ResultsFormat fmt, PrintStream resultsDest) {
try {
Query query = getQuery();
if (isVerbose()) {
IndentedWriter out = new IndentedWriter(resultsDest, true);
query.serialize(out);
out.setLineNumbers(false);
out.println();
out.flush();
}
if (isQuiet())
LogCtl.setError(SysRIOT.riotLoggerName);
Dataset dataset = getDataset(query);
// The default policy is to create an empty one - convenience for VALUES and BIND providing the data.
if (dataset == null && !query.hasDatasetDescription()) {
System.err.println("Dataset not specified in query nor provided on command line.");
throw new TerminationException(1);
}
Transactional transactional = (dataset != null && dataset.supportsTransactions()) ? dataset : new TransactionalNull();
Txn.executeRead(transactional, () -> {
modTime.startTimer();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
try {
QueryExecUtils.executeQuery(query, qe, fmt, resultsDest);
} catch (QueryCancelledException ex) {
IO.flush(resultsDest);
System.err.println("Query timed out");
}
long time = modTime.endTimer();
if (timed) {
totalTime += time;
System.err.println("Time: " + modTime.timeStr(time) + " sec");
}
} catch (ResultSetException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
} catch (QueryException qEx) {
// System.err.println(qEx.getMessage()) ;
throw new CmdException("Query Exeception", qEx);
}
});
} catch (ARQInternalErrorException intEx) {
System.err.println(intEx.getMessage());
if (intEx.getCause() != null) {
System.err.println("Cause:");
intEx.getCause().printStackTrace(System.err);
System.err.println();
}
intEx.printStackTrace(System.err);
} catch (JenaException | CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
use of org.apache.jena.sparql.core.Transactional in project jena by apache.
the class AsyncHttpRDF method asyncGetToStream.
private static CompletableFuture<Void> asyncGetToStream(HttpClient httpClient, String url, Consumer<HttpRequest.Builder> modifier, StreamRDF dest, Transactional _transactional) {
CompletableFuture<HttpResponse<InputStream>> cf = asyncGetToInput(httpClient, url, modifier);
Transactional transact = (_transactional == null) ? TransactionalNull.create() : _transactional;
return cf.thenApply(httpResponse -> {
transact.executeWrite(() -> HttpRDF.httpResponseToStreamRDF(url, httpResponse, dest));
return null;
});
}
Aggregations