use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method startQueryResult.
@Override
public void startQueryResult(List<String> columnHeaders) throws TupleQueryResultHandlerException {
try {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
tupleVariablesFound = true;
jg.writeArrayFieldStart("vars");
for (String nextColumn : columnHeaders) {
jg.writeString(nextColumn);
}
jg.writeEndArray();
} 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.TupleQueryResultHandlerException 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.TupleQueryResultHandlerException 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.TupleQueryResultHandlerException 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