Logger.log("Ping received from: " + getThreadLocalRequest().getRemoteAddr());
}
public String executeHQL(String query, boolean executeUpdate) {
if (StringUtils.isEmpty(query)) {
throw new SimpleMessageException("Query not supplied.");
}
User authUser = getAuthenticatedUser(session.get());
if (authUser == null || !authUser.isAdministrator()) {
throw new SimpleMessageException("Insufficient authorization.");
}
Transaction tx = null;
try {
tx = session.get().beginTransaction();
String result;
if (executeUpdate) {
result = "Rows affected: " + session.get().createQuery(query).executeUpdate();
} else {
List<?> list = session.get().createQuery(query).list();
result = "Objects returned: " + list.size() + "\r\n";
for (int i = 0; i < list.size(); i++) {
result += "Obj[" + i + "]: " + list.get(i).toString() + "\r\n";
}
}
tx.commit();
return result;
} catch (Throwable t) {
Logger.log(t);
try {
tx.rollback();
} catch (Throwable tt) {
}
throw new SimpleMessageException(t.getMessage());
}
}