コード例 #1
0
  public void addWhere(String where, Object parameter) {

    if (StringUtil.isBlank(where)) return;

    int currentWhereIndex = wheres.size();

    String prefix = String.format("%s%d-", Const.db.ORM_PARAMETER_USER, currentWhereIndex);

    NMap inputParam = setParameter(prefix, parameter);

    where = where.trim().replaceFirst("(?ims)^WHERE ", "").replaceFirst("(?ims)^AND ", "");

    String singleParamKey = String.format("%s%s", prefix, Const.db.PARAMETER_SINGLE);

    if (parameter == null) {
      inputParam.put(singleParamKey, null);
    }

    if (inputParam.containsKey(singleParamKey)) {
      where = where.replaceAll("#\\{(.+?)\\}", String.format("#{%s}", singleParamKey));

    } else {
      where = where.replaceAll("#\\{(.+?)\\}", String.format("#{%s$1}", prefix));
    }

    userParameter.putAll(inputParam);

    this.wheres.add(String.format("AND ( %s )", where));
  }
コード例 #2
0
  public void addWhere(String where) {

    if (StringUtil.isBlank(where)) return;

    where =
        where.replaceAll("#\\{(.+?)\\}", String.format("#{%s$1}", Const.db.ORM_PARAMETER_ENTITY));

    this.wheres.add(String.format("AND ( %s )", where));
  }
コード例 #3
0
  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;
  }
コード例 #4
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();
  }
コード例 #5
0
 public void setOrderBy(String orderBy) {
   if (StringUtil.isBlank(orderBy)) return;
   this.orderBy = "ORDER BY " + orderBy.trim().replaceFirst("(?ims)^ORDER +?BY ", "");
 }