use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method endHeader.
@Override
public void endHeader() throws QueryResultHandlerException {
if (!headerComplete) {
try {
jg.writeEndObject();
if (tupleVariablesFound) {
// Write results
jg.writeObjectFieldStart("results");
jg.writeArrayFieldStart("bindings");
}
headerComplete = true;
} catch (IOException e) {
throw new QueryResultHandlerException(e);
}
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method startDocument.
@Override
public void startDocument() throws QueryResultHandlerException {
if (!documentOpen) {
documentOpen = true;
headerOpen = false;
headerComplete = false;
tupleVariablesFound = false;
firstTupleWritten = false;
linksFound = false;
if (getWriterConfig().get(BasicWriterSettings.PRETTY_PRINT)) {
// SES-2011: Always use \n for consistency
Indenter indenter = DefaultIndenter.SYSTEM_LINEFEED_INSTANCE;
// By default Jackson does not pretty print, so enable this unless
// PRETTY_PRINT setting is disabled
DefaultPrettyPrinter pp = new DefaultPrettyPrinter().withArrayIndenter(indenter).withObjectIndenter(indenter);
jg.setPrettyPrinter(pp);
}
try {
if (getWriterConfig().isSet(BasicQueryWriterSettings.JSONP_CALLBACK)) {
// SES-1019 : Write the callbackfunction name as a wrapper for
// the results here
String callbackName = getWriterConfig().get(BasicQueryWriterSettings.JSONP_CALLBACK);
jg.writeRaw(callbackName);
jg.writeRaw("(");
}
jg.writeStartObject();
} catch (IOException e) {
throw new QueryResultHandlerException(e);
}
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method handleSolution.
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
try {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
if (!headerComplete) {
endHeader();
}
if (!tupleVariablesFound) {
throw new IllegalStateException("Must call startQueryResult before handleSolution");
}
firstTupleWritten = true;
jg.writeStartObject();
Iterator<Binding> bindingIter = bindingSet.iterator();
while (bindingIter.hasNext()) {
Binding binding = bindingIter.next();
jg.writeFieldName(binding.getName());
writeValue(binding.getValue());
}
jg.writeEndObject();
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
} catch (TupleQueryResultHandlerException e) {
throw e;
} catch (QueryResultHandlerException e) {
throw new TupleQueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class QueryResultIO method parseTupleInternal.
private static TupleQueryResult parseTupleInternal(InputStream in, QueryResultFormat format, boolean parseOnBackgroundThread) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException {
TupleQueryResultParser parser = createTupleParser(format);
if (parseOnBackgroundThread) {
BackgroundTupleResult result = new BackgroundTupleResult(new QueueCursor<>(new LinkedBlockingQueue<>(1)), parser, in);
// Start a new thread in the background, which will be completed
// when the BackgroundTupleResult is either closed or interrupted
boolean allGood = false;
try {
ForkJoinPool.commonPool().submit(result);
allGood = true;
} finally {
if (!allGood) {
result.close();
}
}
return result;
} else {
TupleQueryResultBuilder qrBuilder = new TupleQueryResultBuilder();
try {
parser.setQueryResultHandler(qrBuilder).parseQueryResult(in);
} catch (QueryResultHandlerException e) {
if (e instanceof TupleQueryResultHandlerException) {
throw (TupleQueryResultHandlerException) e;
} else {
throw new TupleQueryResultHandlerException(e);
}
}
return qrBuilder.getQueryResult();
}
}
use of org.eclipse.rdf4j.query.QueryResultHandlerException in project rdf4j by eclipse.
the class QueryResultIO method parseTuple.
/**
* Parses a query result document, reporting the parsed solutions to the supplied TupleQueryResultHandler.
*
* @param in
* An InputStream to read the query result document from.
* @param format
* The query result format of the document to parse. Supported formats are
* {@link TupleQueryResultFormat#SPARQL} and {@link TupleQueryResultFormat#BINARY}.
* @param handler
* The TupleQueryResultHandler to report the parse results to.
* @throws IOException
* If an I/O error occured while reading the query result document from the stream.
* @throws TupleQueryResultHandlerException
* If such an exception is thrown by the supplied TupleQueryResultHandler.
* @throws UnsupportedQueryResultFormatException
* @throws IllegalArgumentException
* If an unsupported query result file format was specified.
*/
public static void parseTuple(InputStream in, QueryResultFormat format, TupleQueryResultHandler handler, ValueFactory valueFactory) throws IOException, QueryResultParseException, TupleQueryResultHandlerException, UnsupportedQueryResultFormatException {
TupleQueryResultParser parser = createTupleParser(format);
parser.setValueFactory(valueFactory);
parser.setQueryResultHandler(handler);
try {
parser.parseQueryResult(in);
} catch (QueryResultHandlerException e) {
if (e instanceof TupleQueryResultHandlerException) {
throw (TupleQueryResultHandlerException) e;
} else {
throw new TupleQueryResultHandlerException(e);
}
}
}
Aggregations