Search in sources :

Example 21 with TupleQueryResultHandlerException

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);
    }
}
Also used : TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Example 22 with TupleQueryResultHandlerException

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);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) IOException(java.io.IOException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException)

Example 23 with TupleQueryResultHandlerException

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();
    }
}
Also used : TupleQueryResultBuilder(org.eclipse.rdf4j.query.impl.TupleQueryResultBuilder) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) BackgroundTupleResult(org.eclipse.rdf4j.query.resultio.helpers.BackgroundTupleResult) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException)

Example 24 with TupleQueryResultHandlerException

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);
        }
    }
}
Also used : TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) QueryResultHandlerException(org.eclipse.rdf4j.query.QueryResultHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException)

Aggregations

TupleQueryResultHandlerException (org.eclipse.rdf4j.query.TupleQueryResultHandlerException)24 IOException (java.io.IOException)12 QueryResultHandlerException (org.eclipse.rdf4j.query.QueryResultHandlerException)9 Value (org.eclipse.rdf4j.model.Value)6 Binding (org.eclipse.rdf4j.query.Binding)4 TupleQueryResultBuilder (org.eclipse.rdf4j.query.impl.TupleQueryResultBuilder)4 RDFHandlerException (org.eclipse.rdf4j.rio.RDFHandlerException)4 BNode (org.eclipse.rdf4j.model.BNode)2 Literal (org.eclipse.rdf4j.model.Literal)2 Resource (org.eclipse.rdf4j.model.Resource)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 HttpResponse (org.apache.http.HttpResponse)1 Graph (org.eclipse.rdf4j.model.Graph)1 IRI (org.eclipse.rdf4j.model.IRI)1 GraphImpl (org.eclipse.rdf4j.model.impl.GraphImpl)1 GraphUtilException (org.eclipse.rdf4j.model.util.GraphUtilException)1 ListBindingSet (org.eclipse.rdf4j.query.impl.ListBindingSet)1 MapBindingSet (org.eclipse.rdf4j.query.impl.MapBindingSet)1 SimpleBinding (org.eclipse.rdf4j.query.impl.SimpleBinding)1 BooleanQueryResultFormat (org.eclipse.rdf4j.query.resultio.BooleanQueryResultFormat)1