Package dovetaildb.api

Examples of dovetaildb.api.ApiService


    return rec;
  }

  public ApiService newSession(String db, ParsedRequest request) {
    DbRecord rec = getDbRec(db);
    ApiService api = new ChangesetBuffer(rec.db);
    return rec.wrapApiService(api, request);
  }
View Full Code Here


    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;
  }
View Full Code Here

TOP

Related Classes of dovetaildb.api.ApiService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.