Search in sources :

Example 1 with TransactionalNull

use of org.apache.jena.sparql.core.TransactionalNull 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 TransactionalNull

use of org.apache.jena.sparql.core.TransactionalNull 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)

Aggregations

IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)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 Transactional (org.apache.jena.sparql.core.Transactional)2 TransactionalNull (org.apache.jena.sparql.core.TransactionalNull)2 ResultSetException (org.apache.jena.sparql.resultset.ResultSetException)2 CmdException (jena.cmd.CmdException)1 TerminationException (jena.cmd.TerminationException)1 CmdException (org.apache.jena.cmd.CmdException)1 TerminationException (org.apache.jena.cmd.TerminationException)1 NotFoundException (org.apache.jena.shared.NotFoundException)1