Esempio n. 1
0
  /**
   * 执行操作
   *
   * @param context
   * @param modelName
   * @param executeName
   * @param currentPath
   * @return
   */
  public static ResponseObject execute(
      Context context, String modelName, String executeName, String currentPath) {

    LogUtil.info("-----------------------execute begin------------------------------------");
    try {
      if (executeName == null || "".equals(executeName)) executeName = "_default";

      Model model = context.getModel(modelName);

      Execute execute = model.getExecute(executeName);
      if (execute == null) {
        throw new ExecuteNotFoundException(
            "can not found Execute:" + executeName + ", on Model:" + modelName);
      }
      execute.setCurrentPath(currentPath);
      execute(context, model, execute);

      // 向客服端传送成功消息
      ResponseObject ro = new ResponseObject();
      ro.setSuccess(true);
      ro.setMessage("success");
      ro.setOutParam(getOutParams(context, execute.getParams()));
      return ro;
    } finally {
      context.closeConns();
      LogUtil.info("-----------------------execute end--------------------------------------");
    }
  }
Esempio n. 2
0
  /**
   * 执行execute
   *
   * @param context
   * @param model
   * @param execute
   */
  private static void execute(Context context, Model model, Execute execute) {

    String modelName = model.getModelName();
    String currentPath = execute.getCurrentPath();
    LogUtil.info(
        "Execute info (modelName:" + modelName + ", executeName:" + execute.getName() + ")");

    // 把model、currentPath对象放入到 当前线程里
    context.setCurrentPath(currentPath);
    context.setCurrentModel(modelName);

    // 设想sql查询参数
    Collection<Param> params = execute.getParams().values();
    for (Param nfParam : params) {
      setParam(nfParam, context, currentPath);
    }
    execute.execute(context, model.getConnectionProvide(context)); // 执行
  }
Esempio n. 3
0
  /**
   * 批量执行操作
   *
   * @param context
   * @param modelName
   * @param executeName
   * @param sourcePath
   * @return
   */
  public static ResponseObject batchExecute(
      Context context, String modelName, String executeName, String sourcePath) {

    LogUtil.info("-----------------------batch execute begin------------------------------");
    try {
      if (executeName == null || "".equals(executeName)) executeName = "addOrUpdate";

      // 批量执行查找客户端数据的路径
      String batchExecutePath = defaultBatchPath;
      Execute execute = null;

      Model model = context.getModel(modelName);

      // 查询数据,返回结果
      if (sourcePath != null && !"".equals(sourcePath)) {
        batchExecutePath = sourcePath;
      }

      Object object = context.getData(batchExecutePath);
      int size = 0;
      if (object != null) {
        if (object instanceof Object[]) {
          Object[] objects = (Object[]) object;
          size = objects.length;
        } else if (object instanceof List) {
          List list = (List) object;
          size = list.size();
        } else if (object instanceof Set) {
          Set set = (Set) object;
          size = set.size();
        }
      }

      // 向客服端传送成功消息
      ResponseObject ro = new ResponseObject();
      ro.setSuccess(true);
      ro.setMessage("success");

      if (size > 0) {
        for (int j = 0; j < size; j++) {
          String en = null;
          String currentPath = batchExecutePath + "[" + j + "]";
          if ("addOrUpdate".equals(executeName)) {
            String status = context.getString(currentPath + "._status");
            if (status != null) status = status.toUpperCase();
            if ("NEW".equals(status)) {
              en = "add";
            } else if ("OLD".equals(status)) {
              en = "update";
            } else {
              throw new ExecuteNotFoundException(
                  "cant not found (_status) field,can not found Execute");
            }
          } else {
            en = executeName;
          }
          execute = model.getExecute(en);
          if (execute == null) {
            throw new ExecuteNotFoundException(
                "can not found Execute:" + executeName + ", on Model:" + modelName);
          }
          execute.setCurrentPath(currentPath);
          execute(context, model, execute);
        }
        ro.setOutParam(getOutParams(context, execute.getParams()));
      }

      return ro;

    } finally {
      context.closeConns();
      LogUtil.info("-----------------------batch execute end--------------------------------");
    }
  }