use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.
the class DAWGTestResultSetWriter method handleSolution.
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
try {
BNode solutionNode = vf.createBNode();
reportStatement(resultSetNode, SOLUTION, solutionNode);
for (Binding binding : bindingSet) {
BNode bindingNode = vf.createBNode();
reportStatement(solutionNode, BINDING, bindingNode);
reportStatement(bindingNode, VARIABLE, vf.createLiteral(binding.getName()));
Value value = binding.getValue();
// generated for the result format
if (value instanceof BNode) {
BNode mappedBNode = bnodeMap.get(value);
if (mappedBNode == null) {
mappedBNode = vf.createBNode();
bnodeMap.put((BNode) value, mappedBNode);
}
value = mappedBNode;
}
reportStatement(bindingNode, VALUE, value);
}
} catch (RDFHandlerException e) {
throw new TupleQueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.
the class AbstractSPARQLJSONWriter method endQueryResult.
@Override
public void endQueryResult() throws TupleQueryResultHandlerException {
try {
if (!documentOpen) {
startDocument();
}
if (!headerOpen) {
startHeader();
}
if (!headerComplete) {
endHeader();
}
if (!tupleVariablesFound) {
throw new IllegalStateException("Could not end query result as startQueryResult was not called first.");
}
// bindings array
jg.writeEndArray();
// results braces
jg.writeEndObject();
endDocument();
} 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 writeValue.
protected void writeValue(Value value) throws IOException, QueryResultHandlerException {
jg.writeStartObject();
if (value instanceof IRI) {
jg.writeStringField("type", "uri");
jg.writeStringField("value", ((IRI) value).toString());
} else if (value instanceof BNode) {
jg.writeStringField("type", "bnode");
jg.writeStringField("value", ((BNode) value).getID());
} else if (value instanceof Literal) {
Literal lit = (Literal) value;
if (Literals.isLanguageLiteral(lit)) {
jg.writeObjectField("xml:lang", lit.getLanguage().orElse(null));
} else {
IRI datatype = lit.getDatatype();
boolean ignoreDatatype = datatype.equals(XMLSchema.STRING) && xsdStringToPlainLiteral();
if (!ignoreDatatype) {
jg.writeObjectField("datatype", lit.getDatatype().stringValue());
}
}
jg.writeObjectField("type", "literal");
jg.writeObjectField("value", lit.getLabel());
} else {
throw new TupleQueryResultHandlerException("Unknown Value object type: " + value.getClass());
}
jg.writeEndObject();
}
use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.
the class BinaryQueryResultWriter method startQueryResult.
@Override
public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
tupleVariablesFound = true;
if (!documentStarted) {
startDocument();
}
// Copy supplied column headers list and make it unmodifiable
bindingNames = new ArrayList<String>(bindingNames);
this.bindingNames = Collections.unmodifiableList(bindingNames);
try {
out.writeInt(this.bindingNames.size());
for (String bindingName : this.bindingNames) {
writeString(bindingName);
}
List<Value> nullTuple = Collections.nCopies(this.bindingNames.size(), (Value) null);
previousBindings = new ListBindingSet(this.bindingNames, nullTuple);
nextNamespaceID = 0;
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
}
}
use of org.eclipse.rdf4j.query.TupleQueryResultHandlerException in project rdf4j by eclipse.
the class SPARQLResultsTSVWriter method handleSolution.
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
if (!tupleVariablesFound) {
throw new IllegalStateException("Must call startQueryResult before handleSolution");
}
try {
for (int i = 0; i < bindingNames.size(); i++) {
String name = bindingNames.get(i);
Value value = bindingSet.getValue(name);
if (value != null) {
writeValue(value);
}
if (i < bindingNames.size() - 1) {
writer.write("\t");
}
}
writer.write("\n");
} catch (IOException e) {
throw new TupleQueryResultHandlerException(e);
}
}
Aggregations