public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
subject = triples.getValueFactory().createURI(resourceUri);
try {
con = triples.getConnection();
} catch (RepositoryException e) {
throw new TupleQueryResultHandlerException("error while creating repository connection",e);
}
}
@Override
public void endQueryResult() throws TupleQueryResultHandlerException {
try {
con.commit();
} catch (RepositoryException e) {
throw new TupleQueryResultHandlerException("error while committing repository connection",e);
} finally {
try {
con.close();
} catch(RepositoryException e) {
throw new TupleQueryResultHandlerException("error while closing repository connection",e);
}
}
}
@Override
public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
try {
Value predicate = bindingSet.getValue("p");
Value object = bindingSet.getValue("o");
if(predicate instanceof URI) {
con.add(triples.getValueFactory().createStatement(subject,(URI)predicate,object));
} else {
log.error("ignoring binding as predicate {} is not a URI",predicate);
}
} catch (RepositoryException e) {
throw new TupleQueryResultHandlerException("error while adding triple to repository connection",e);
}
}
@Override
public void handleBoolean(boolean bool ) throws QueryResultHandlerException {