Session databaseSession = Database.getInstance().getSessionFactory().openSession();
Gson gson = new GsonBuilder()
.setDateFormat(DateOperator.getDateFormatString())
.excludeFieldsWithoutExposeAnnotation()
.create();
Response queryResponse = null;
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
String queryName = request.getParameter("queryName");
String queryString = request.getParameter("queryString");
//System.out.println(">> DEBUG: Got query from user: " + queryName + " => " + queryString);
if (queryName != null && queryString != null && queryName.length() > 0 && queryString.length() > 0) {
Query query = QueryFactory.factory(queryName, queryString);
if (query != null) {
queryResponse = query.execute(request, databaseSession);
} else {
queryResponse = new Response(ResponseStatus.FAIL, "Unknown query requested");
}
} else {
queryResponse = new Response(ResponseStatus.FAIL, "Bad query request");
}
out.write(gson.toJson(queryResponse));
out.close();
databaseSession.close();