Search in sources :

Example 41 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter 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 42 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class sse method exec.

@Override
protected void exec(Item item) {
    if (!print)
        return;
    if (item == null) {
        System.err.println("No expression");
        throw new TerminationException(9);
    }
    divider();
    IndentedWriter out = new IndentedWriter(System.out, lineNumbers);
    // Need to check if used.
    // PrefixMapping pmap = SSE.getDefaultPrefixMapWrite() ;
    PrefixMapping pmap = null;
    SerializationContext sCxt = new SerializationContext(pmap);
    ItemWriter.write(out, item, sCxt);
    // item.output(out) ;
    out.ensureStartOfLine();
    out.flush();
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) SerializationContext(org.apache.jena.sparql.serializer.SerializationContext) PrefixMapping(org.apache.jena.shared.PrefixMapping) TerminationException(org.apache.jena.cmd.TerminationException)

Example 43 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class load method execUpdate.

@Override
protected void execUpdate(DatasetGraph dataset) {
    if (loadFiles.size() == 0)
        throw new CmdException("Nothing to do");
    UpdateRequest req = new UpdateRequest();
    for (String filename : loadFiles) {
        UpdateLoad loadReq = new UpdateLoad(filename, graphName);
        req.add(loadReq);
    }
    if (true) {
        // Need a better way
        monitor(dataset.getDefaultGraph());
        for (Iterator<Node> iter = dataset.listGraphNodes(); iter.hasNext(); ) {
            Graph g = dataset.getGraph(iter.next());
            monitor(g);
        }
    }
    UpdateExec.newBuilder().update(req).dataset(dataset).execute();
    if (dump) {
        IndentedWriter out = IndentedWriter.stdout;
        SSE.write(dataset);
        out.flush();
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) CmdException(org.apache.jena.cmd.CmdException) UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateLoad(org.apache.jena.sparql.modify.request.UpdateLoad) Node(org.apache.jena.graph.Node)

Example 44 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class WriterTriX method write.

@Override
public void write(Writer out, Graph graph, PrefixMap prefixMap, String baseURI, Context context) {
    IndentedWriter iOut = RiotLib.create(out);
    write(iOut, graph, prefixMap, baseURI, null);
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Example 45 with IndentedWriter

use of org.apache.jena.atlas.io.IndentedWriter in project jena by apache.

the class WriterTriX method write.

@Override
public void write(Writer out, DatasetGraph datasetGraph, PrefixMap prefixMap, String baseURI, Context context) {
    IndentedWriter iOut = RiotLib.create(out);
    write(iOut, datasetGraph, prefixMap, baseURI, null);
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter)

Aggregations

IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)57 SerializationContext (org.apache.jena.sparql.serializer.SerializationContext)5 TerminationException (org.apache.jena.cmd.TerminationException)4 Node (org.apache.jena.graph.Node)4 PrefixMapping (org.apache.jena.shared.PrefixMapping)4 CmdException (org.apache.jena.cmd.CmdException)3 Triple (org.apache.jena.graph.Triple)3 Syntax (org.apache.jena.query.Syntax)3 IOException (java.io.IOException)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 Pair (org.apache.jena.atlas.lib.Pair)2 RiotException (org.apache.jena.riot.RiotException)2 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)2 NodeFormatter (org.apache.jena.riot.out.NodeFormatter)2 NodeFormatterTTL (org.apache.jena.riot.out.NodeFormatterTTL)2 JenaException (org.apache.jena.shared.JenaException)2 ARQException (org.apache.jena.sparql.ARQException)2 Var (org.apache.jena.sparql.core.Var)2 Plan (org.apache.jena.sparql.engine.Plan)2 Expr (org.apache.jena.sparql.expr.Expr)2