Search in sources :

Example 1 with ResultSetException

use of org.apache.jena.sparql.resultset.ResultSetException 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 ResultSetException

use of org.apache.jena.sparql.resultset.ResultSetException in project jena by apache.

the class ReaderTriX method read.

@Override
public void read(Reader reader, String baseURI, ContentType ct, StreamRDF output, Context context) {
    XMLInputFactory xf = XMLInputFactory.newInstance();
    XMLStreamReader xReader;
    try {
        xReader = xf.createXMLStreamReader(reader);
    } catch (XMLStreamException e) {
        throw new ResultSetException("Can't initialize StAX parsing engine", e);
    }
    read(xReader, baseURI, output);
}
Also used : ResultSetException(org.apache.jena.sparql.resultset.ResultSetException)

Example 3 with ResultSetException

use of org.apache.jena.sparql.resultset.ResultSetException in project jena by apache.

the class qparse method exec.

@Override
protected void exec() {
    try {
        Query query = modQuery.getQuery();
        try {
            LogCtl.disable(ParserBase.ParserLoggerName);
            QueryUtils.checkQuery(query, true);
        } catch (QueryCheckException ex) {
            System.err.println();
            System.err.println("**** Check failure: " + ex.getMessage());
            if (ex.getCause() != null)
                ex.getCause().printStackTrace(System.err);
        } finally {
            LogCtl.setLevel(ParserBase.ParserLoggerName, "INFO");
        }
        // Print the query out in some syntax
        if (printQuery) {
            divider();
            modOutput.output(query);
        }
        // Print internal forms.
        if (printOp) {
            divider();
            modOutput.outputOp(query, false);
        }
        if (printQuad) {
            divider();
            modOutput.outputQuad(query, false);
        }
        if (printOpt) {
            divider();
            modOutput.outputOp(query, true);
        }
        if (printQuadOpt) {
            divider();
            modOutput.outputQuad(query, true);
        }
        if (printPlan) {
            divider();
            // This forces internal query initialization - must be after QueryUtils.checkQuery
            QueryExecution qExec = QueryExecutionFactory.create(query, DatasetFactory.createGeneral());
            QueryOutputUtils.printPlan(query, qExec);
        }
    } 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 (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 (JenaException ex) {
        ex.printStackTrace();
        throw ex;
    } catch (CmdException ex) {
        throw ex;
    } catch (Exception ex) {
        throw new CmdException("Exception", ex);
    }
}
Also used : JenaException(org.apache.jena.shared.JenaException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) QueryCheckException(org.apache.jena.sparql.core.QueryCheckException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) JenaException(org.apache.jena.shared.JenaException)

Aggregations

ResultSetException (org.apache.jena.sparql.resultset.ResultSetException)3 CmdException (jena.cmd.CmdException)2 JenaException (org.apache.jena.shared.JenaException)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 TerminationException (jena.cmd.TerminationException)1 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)1 RiotException (org.apache.jena.riot.RiotException)1 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)1 QueryCheckException (org.apache.jena.sparql.core.QueryCheckException)1 Transactional (org.apache.jena.sparql.core.Transactional)1 TransactionalNull (org.apache.jena.sparql.core.TransactionalNull)1