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);
}
}
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();
}
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();
}
}
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);
}
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);
}
Aggregations