return construct(sparql, null, mapper);
}
public <T> List<T> construct(String sparql, Map<String, Object> args, GraphMapper<T> mapper) {
Connection connection = dataSource.getConnection();
GraphQueryResult result = null;
try {
GraphQuery query = connection.graph(sparql);
if (args != null) {
for (Entry<String, Object> arg : args.entrySet()) {
query.parameter(arg.getKey(), arg.getValue());
}
}
ArrayList<T> list = new ArrayList<T>();
result = query.execute();
// return empty lists for empty queries
if (result == null) {
return list;
}
while (result.hasNext()) {
list.add(mapper.mapRow(result.next()));
}
return list;
} catch (StardogException e) {
log.error("Error sending construct query to Stardog", e);
throw new RuntimeException(e);
} catch (QueryEvaluationException e) {
log.error("Error evaluating SPARQL construct query", e);
throw new RuntimeException(e);
} finally {
if (result != null) {
try {
result.close();
}
catch (QueryEvaluationException e) { }
}
dataSource.releaseConnection(connection);
}