Ejemplo n.º 1
0
  public String searchSQL(Object entity) {
    entityFillField(entity);

    String sql = SEARCH;

    sql += catalog + ".";

    sql += table;

    boolean isHead = true;

    for (Field field : entityField) {

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

      sql += field.getFieldName() + "=";
      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);

    // make group by field
    sql += groupBy();

    // make order by field
    sql += orderBy();

    if (offsetRecord > -1 && maxRecords > 0) {
      sql += OFFSET_PAGE + offsetRecord + "," + maxRecords;
    }

    return sql;
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  public String updateSQL(Object entity) {
    entityFillField(entity);

    String sql = UPDATE;

    sql += " " + catalog + ".";

    sql += table;

    Object fieldValue;
    boolean isHead = true;

    for (Field field : entityField) {

      if (!field.isPrimaryKey()) {

        if (isHead) {
          isHead = false;
          sql += " SET ";
        } else {
          sql += ",";
        }

        fieldValue = field.getFieldValue();

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

        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);
        }
      }
    }

    isHead = true;
    for (Field field : entityField) {

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

        fieldValue = field.getFieldValue();

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

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

    return sql;
  }
Ejemplo n.º 4
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();
  }