return handle(req, EMPTY_OPTS, null);
}
public Object handle(ParsedRequest req, Map<String, String> params, HttpServletResponse response) {
Object returnVal = null;
boolean normalFinish = false;
ApiService api = repo.newSession(req.getDb(), req);
if (Util.logger.isLoggable(Level.FINEST)) {
Util.logger.log(Level.FINEST, "ApiService given: "+api);
}
if (api == null) {
throw new ApiException("PermissionDenied","Permission denied");
}
try {
switch(req.getAction()) {
case call:
List<Object> args = (List<Object>)Util.jsonDecode(req.getArguments());
Object[] parsedArgs = new Object[args.size()+1];
parsedArgs[0] = api;
int idx=1;
for(Object arg : args) {
parsedArgs[idx++] = arg;
}
returnVal = repo.invokeFunction(req.getDb(), req.getFunctionName(), parsedArgs);
break;
case execute:
returnVal = repo.executeCode(api, req.getDb(), req.getCode());
break;
case query:
Object query = req.getQuery();
returnVal = api.query(req.getBagName(), query, req.getOptionsAsMap());
break;
case put:
Object entry = req.getEntry();
api.put(req.getBagName(), (Map<String,Object>)entry);
break;
case remove:
api.remove(req.getBagName(), req.getId());
break;
default:
throw new RuntimeException();
}
api.commit();
normalFinish = true;
} finally {
if (! normalFinish) api.rollback();
}
return returnVal;
}