HTTPRepository repo = (HTTPRepository)request.getSession().getAttribute(SessionKeys.REPOSITORY_KEY);
SelectQueryInfo qInfo = (SelectQueryInfo)command;
TupleQueryResult queryResult = null;
RepositoryConnection conn = null;
try {
conn = repo.getConnection();
HTTPTupleQuery query = (HTTPTupleQuery)conn.prepareTupleQuery(qInfo.getQueryLanguage(),
qInfo.getQueryString());
query.setIncludeInferred(qInfo.isIncludeInferred());
try {
queryResult = query.evaluate();
}
catch (HTTPQueryEvaluationException e) {
if (e.isCausedByMalformedQueryException()) {
throw e.getCauseAsMalformedQueryException();
}
else if (e.isCausedByRepositoryException()) {
throw e.getCauseAsRepositoryException();
}
else if (e.isCausedByIOException()) {
throw e.getCauseAsIOException();
}
else {
throw e;
}
}
}
catch (RepositoryException e) {
logger.info("Unable to process query", e);
errors.reject("repository.error");
}
catch (MalformedQueryException e) {
errors.rejectValue("queryString", "repository.query.error.malformed", new String[] { e.getMessage() }, "Malformed query");
}
catch (QueryEvaluationException e) {
errors.reject("repository.query.error.evaluation");
}
finally {
// FIXME: check to see where this connection gets closed
// if (conn != null) {
// try {
// conn.close();
// }
// catch (RepositoryException e) {
// e.printStackTrace();
// }
// }
}
if (errors.hasErrors()) {
result = showForm(request, response, errors, errors.getModel());
}
else {
@SuppressWarnings("unchecked")
Map<String, Object> model = errors.getModel();
model.put("bindingNames", queryResult.getBindingNames());
model.put("solutions", queryResult);
result = new ModelAndView(getSuccessView(), model);
}