Search in sources :

Example 1 with Transactional

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);
    }
}
Also used : CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RiotException(org.apache.jena.riot.RiotException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) TerminationException(jena.cmd.TerminationException) JenaException(org.apache.jena.shared.JenaException) RiotNotFoundException(org.apache.jena.riot.RiotNotFoundException) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) JenaException(org.apache.jena.shared.JenaException) TerminationException(jena.cmd.TerminationException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) Transactional(org.apache.jena.sparql.core.Transactional)

Example 2 with Transactional

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());
    });
}
Also used : Transactional(org.apache.jena.sparql.core.Transactional) Test(org.junit.Test)

Example 3 with Transactional

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));
}
Also used : CmdException(org.apache.jena.cmd.CmdException) Transactional(org.apache.jena.sparql.core.Transactional) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 4 with Transactional

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);
    }
}
Also used : CmdException(org.apache.jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RiotException(org.apache.jena.riot.RiotException) CmdException(org.apache.jena.cmd.CmdException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) NotFoundException(org.apache.jena.shared.NotFoundException) JenaException(org.apache.jena.shared.JenaException) TerminationException(org.apache.jena.cmd.TerminationException) RiotNotFoundException(org.apache.jena.riot.RiotNotFoundException) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) JenaException(org.apache.jena.shared.JenaException) TerminationException(org.apache.jena.cmd.TerminationException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) Transactional(org.apache.jena.sparql.core.Transactional)

Example 5 with Transactional

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;
    });
}
Also used : HttpResponse(java.net.http.HttpResponse) Transactional(org.apache.jena.sparql.core.Transactional)

Aggregations

Transactional (org.apache.jena.sparql.core.Transactional)6 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 CmdException (org.apache.jena.cmd.CmdException)2 RiotException (org.apache.jena.riot.RiotException)2 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)2 JenaException (org.apache.jena.shared.JenaException)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 TransactionalNull (org.apache.jena.sparql.core.TransactionalNull)2 ResultSetException (org.apache.jena.sparql.resultset.ResultSetException)2 Test (org.junit.Test)2 HttpResponse (java.net.http.HttpResponse)1 CmdException (jena.cmd.CmdException)1 TerminationException (jena.cmd.TerminationException)1 TerminationException (org.apache.jena.cmd.TerminationException)1 NotFoundException (org.apache.jena.shared.NotFoundException)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1