public NMap getParameter() {

    NMap result = new NMap();
    result.putAll(entityParameter);
    result.putAll(userParameter);

    if (wheres.size() > 0) result.put(Const.db.ORM_PARAMETER_WHERE, StringUtil.join(wheres, "\n"));
    if (orderBy != null) result.put(Const.db.ORM_PARAMETER_ORDER_BY, orderBy);

    return result;
  }
Beispiel #2
0
  public String getSql() {

    StringBuilder sql = new StringBuilder();

    int index = 0;

    for (String line : binarySql) {

      if (line != null) {

        // remaining unbind sentence "#{param...}" cause NPE when running executeUpdate().
        // 'statement.setEscapeProcessing( false )' can not avoid error because it cause another
        // problem.
        // so remove remaining unbind sentence to avoid NPE.
        if (!line.startsWith("#{") || !line.endsWith("}")) {
          sql.append(line);
        }

        continue;
      }

      String key = binaryKeys.get(index++);

      BindParam bindParam = bindParams.get(key);

      if (bindParam.getType() == SqlType.LIST) {

        List params = (List) bindParam.getValue();

        List marks = new ArrayList<>();
        for (int i = 0; i < params.size(); i++) marks.add("?");

        sql.append(StringUtil.join(marks, ","));

      } else {
        sql.append('?');
      }
    }

    return sql.toString();
  }