Exemplo n.º 1
0
  public void setLike(String fieldName, Object fieldValue) {
    if (fieldName != null && fieldValue != null) {
      boolean haveField = false;

      for (Field field : entityField) {
        if (fieldName.equals(field.getFieldName())
            && field.getWhereRule().equals(Field.RULE_LIKE)) {

          if (fieldValue.getClass().isAssignableFrom(String.class)) {
            String value = fieldValue.toString();

            if (!StringUtils.isNull(value)) {
              field.setFieldValue("%" + fieldValue + "%");

              haveField = true;
              break;
            }
          }
        }
      }

      if (!haveField) {
        extendField.add(
            new Field(fieldName, fieldValue, 1000, Field.WHERE_BY_AND, Field.RULE_LIKE, false));
      }
    }
  }
Exemplo n.º 2
0
  public void setWhereIn(String fieldName, Object fieldValue) {
    if (fieldName != null && fieldValue != null) {
      boolean haveField = false;
      for (Field field : entityField) {
        if (fieldName.equals(field.getFieldName()) && field.getWhereRule().equals(Field.RULE_IN)) {

          field.setFieldValue(fieldValue);

          haveField = true;
          break;
        }
      }

      if (!haveField)
        extendField.add(
            new Field(fieldName, fieldValue, 1000, Field.WHERE_BY_AND, Field.RULE_IN, false));
    }
  }
Exemplo n.º 3
0
  private void setWhereFor(
      String fieldName,
      Object fieldValue,
      int fieldType,
      String whereBy,
      String whereRule,
      boolean isPrimaryKey) {
    boolean haveField = false;

    for (Field field : entityField) {

      if (fieldName.equals(field.getFieldName())
          && field.getWhereRule().equals(Field.RULE_EQUAL)
          && fieldValue != null) {

        field.setFieldValue(fieldValue);
        field.setFieldType(fieldType);
        field.setWhereBy(whereBy);
        field.setWhereRule(whereRule);
        field.setPrimaryKey(isPrimaryKey);

        haveField = true;
        break;
      }
    }

    if (!haveField && fieldValue != null) {

      if (fieldValue.getClass().isAssignableFrom(String.class)) {
        String value = fieldValue.toString();

        if (!StringUtils.isNull(value)) {
          entityField.add(
              new Field(fieldName, fieldValue, fieldType, whereBy, whereRule, isPrimaryKey));
        }
      } else {
        entityField.add(
            new Field(fieldName, fieldValue, fieldType, whereBy, whereRule, isPrimaryKey));
      }
    }
  }
Exemplo n.º 4
0
  public String deleteSQL(Object entity) {
    entityFillField(entity);

    String sql = DELETE;

    sql += catalog + ".";

    sql += table;

    boolean isHead = true;

    for (Field field : entityField) {

      if (isHead) {
        isHead = false;
        sql += " WHERE ";
      } else {
        sql += field.getWhereBy();
      }

      sql += field.getFieldName() + field.getWhereRule();

      Object fieldValue = field.getFieldValue();

      if (field.getFieldType() == Types.TIMESTAMP) {
        sql += "'" + CalendarUtils.dtformat(((Date) fieldValue)) + "'";
      } else if (field.getFieldType() == Types.DATE) {
        sql += "'" + CalendarUtils.dformat(((Date) fieldValue)) + "'";
      } else {
        sql += StringUtils.fieldValue(fieldValue);
      }
    }

    // fill extend field
    sql += extendSQL(isHead);

    return sql;
  }
Exemplo n.º 5
0
  private String extendSQL(boolean isHead) {
    StringBuffer buffer = new StringBuffer();

    // fill extend field
    for (Field field : extendField) {

      Object fieldValue = field.getFieldValue();
      // Object choose
      if (fieldValue != null) {
        if (fieldValue.getClass().isAssignableFrom(Date.class)) {
          Date value = (Date) fieldValue;

          if (isHead) {
            isHead = false;
            buffer.append(" WHERE ");
          } else {
            buffer.append(field.getWhereBy());
          }

          buffer.append(field.getFieldName() + field.getWhereRule());

          if (field.getWhereRule().equals(Field.RULE_LIKE)) {
            if (field.getFieldType() == Types.TIMESTAMP) {
              buffer.append("'%" + CalendarUtils.dtformat(value) + "%'");
            } else if (field.getFieldType() == Types.DATE) {
              buffer.append("'%" + CalendarUtils.dformat(value) + "%'");
            }
          } else {
            if (field.getFieldType() == Types.TIMESTAMP) {
              buffer.append("'" + CalendarUtils.dtformat(value) + "'");
            } else if (field.getFieldType() == Types.DATE) {
              buffer.append("'" + CalendarUtils.dformat(value) + "'");
            }
          }
        } else if (fieldValue.getClass().isAssignableFrom(Integer.class)
            || fieldValue.getClass().isAssignableFrom(Long.class)
            || fieldValue.getClass().isAssignableFrom(Float.class)
            || fieldValue.getClass().isAssignableFrom(Double.class)) {

          if (isHead) {
            isHead = false;
            buffer.append(" WHERE ");
          } else {
            buffer.append(field.getWhereBy());
          }

          buffer.append(field.getFieldName() + field.getWhereRule() + fieldValue);

        } else if (fieldValue.getClass().isAssignableFrom(String.class)) {
          String value = (String) fieldValue;

          if (!value.equals("")) {
            if (isHead) {
              isHead = false;
              buffer.append(" WHERE ");
            } else {
              buffer.append(field.getWhereBy());
            }

            buffer.append(field.getFieldName() + field.getWhereRule());

            if (field.getWhereRule().equals(Field.RULE_LIKE)) {
              buffer.append("'%" + value + "%'");
            } else if (field.getWhereRule().equals(Field.RULE_IN)) {
              buffer.append(" (" + value + ") ");
            } else {
              buffer.append(" '" + value + "' ");
            }
          }
        }
      }
    }

    return buffer.toString();
  }