}
}
@ManagedOperation(description = "Parses and executes IspnCliQL statements")
public Map<String, String> execute(final String sessionId, final String s) throws Exception {
Session session = null;
ClassLoader oldCL = SecurityActions.setThreadContextClassLoader(cacheManager.getCacheManagerConfiguration().classLoader());
Map<String, String> response = new HashMap<String, String>();
try {
session = validateSession(sessionId);
CharStream stream = new ANTLRStringStream(s);
IspnCliQLLexer lexer = new IspnCliQLLexer(stream);
CommonTokenStream tokens = new CommonTokenStream(lexer);
IspnCliQLParser parser = new IspnCliQLParser(tokens);
parser.statements();
if (parser.hasParserErrors()) {
throw new ParseException(parser.getParserErrors());
}
StringBuilder output = new StringBuilder();
for (Statement stmt : parser.statements) {
Result result = stmt.execute(session);
if (result != EmptyResult.RESULT) {
output.append(result.getResult());
}
}
if (output.length() > 0) {
response.put(ResultKeys.OUTPUT.toString(), output.toString());
}
} catch (Throwable t) {
log.interpreterError(t);
response.put(ResultKeys.ERROR.toString(), t.getMessage());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
response.put(ResultKeys.STACKTRACE.toString(), sw.toString());
} finally {
if (session != null) {
session.reset();
response.put(ResultKeys.CACHE.toString(), session.getCurrentCacheName());
}
SecurityActions.setThreadContextClassLoader(oldCL);
}
return response;