Search in sources :

Example 16 with TupleQueryResultHandlerException

use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.

the class DAWGTestResultSetParser method reportSolution.

private void reportSolution(Resource solutionNode, List<String> bindingNames) throws RDFHandlerException, GraphUtilException {
    MapBindingSet bindingSet = new MapBindingSet(bindingNames.size());
    Iterator<Value> bindingIter = GraphUtil.getObjectIterator(graph, solutionNode, BINDING);
    while (bindingIter.hasNext()) {
        Value bindingNode = bindingIter.next();
        if (bindingNode instanceof Resource) {
            Binding binding = getBinding((Resource) bindingNode);
            bindingSet.addBinding(binding);
        } else {
            throw new RDFHandlerException("Value for " + BINDING + " is not a resource: " + bindingNode);
        }
    }
    try {
        tqrHandler.handleSolution(bindingSet);
    } catch (TupleQueryResultHandlerException e) {
        throw new RDFHandlerException(e.getMessage(), e);
    }
}
Also used : Binding(org.eclipse.rdf4j.query.Binding) SimpleBinding(org.eclipse.rdf4j.query.impl.SimpleBinding) RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) Value(org.eclipse.rdf4j.model.Value) Resource(org.eclipse.rdf4j.model.Resource) MapBindingSet(org.eclipse.rdf4j.query.impl.MapBindingSet)

Example 17 with TupleQueryResultHandlerException

use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.

the class DAWGTestResultSetUtil method toGraph.

public static Graph toGraph(TupleQueryResult tqr) throws QueryEvaluationException {
    Graph graph = new GraphImpl();
    DAWGTestResultSetWriter writer = new DAWGTestResultSetWriter(new StatementCollector(graph));
    try {
        writer.startQueryResult(tqr.getBindingNames());
        while (tqr.hasNext()) {
            writer.handleSolution(tqr.next());
        }
        writer.endQueryResult();
    } catch (TupleQueryResultHandlerException e) {
        // StatementCollector, foud a bug?
        throw new RuntimeException(e);
    }
    return graph;
}
Also used : Graph(org.eclipse.rdf4j.model.Graph) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) GraphImpl(org.eclipse.rdf4j.model.impl.GraphImpl) StatementCollector(org.eclipse.rdf4j.rio.helpers.StatementCollector)

Example 18 with TupleQueryResultHandlerException

use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.

the class DAWGTestResultSetWriter method startQueryResult.

/*---------*
	 * Methods *
	 *---------*/
@Override
public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
    try {
        rdfHandler.startRDF();
        resultSetNode = vf.createBNode();
        bnodeMap.clear();
        reportStatement(resultSetNode, RDF.TYPE, RESULTSET);
        for (String bindingName : bindingNames) {
            Literal bindingNameLit = vf.createLiteral(bindingName);
            reportStatement(resultSetNode, RESULTVARIABLE, bindingNameLit);
        }
    } catch (RDFHandlerException e) {
        throw new TupleQueryResultHandlerException(e);
    }
}
Also used : RDFHandlerException(org.eclipse.rdf4j.rio.RDFHandlerException) TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) Literal(org.eclipse.rdf4j.model.Literal)

Example 19 with TupleQueryResultHandlerException

use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.

the class BinaryQueryResultWriter method startDocument.

@Override
public void startDocument() throws TupleQueryResultHandlerException {
    documentStarted = true;
    try {
        out.write(MAGIC_NUMBER);
        out.writeInt(FORMAT_VERSION);
    } catch (IOException e) {
        throw new TupleQueryResultHandlerException(e);
    }
}
Also used : TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) IOException(java.io.IOException)

Example 20 with TupleQueryResultHandlerException

use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.

the class BinaryQueryResultWriter method endQueryResult.

@Override
public void endQueryResult() throws TupleQueryResultHandlerException {
    if (!tupleVariablesFound) {
        throw new IllegalStateException("Could not end query result as startQueryResult was not called first.");
    }
    try {
        out.writeByte(TABLE_END_RECORD_MARKER);
        endDocument();
    } catch (IOException e) {
        throw new TupleQueryResultHandlerException(e);
    }
}
Also used : TupleQueryResultHandlerException(org.eclipse.rdf4j.query.TupleQueryResultHandlerException) IOException(java.io.IOException)

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