예제 #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;
  }
예제 #2
0
  public String addSQL(Object entity) {
    entityFillField(entity);

    String sql = ADD;

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

    sql += table;

    sql += " (";

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

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

      sql += field.getFieldName();
    }

    sql += ") VALUES(";

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

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

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

    sql += ")";

    return sql;
  }
예제 #3
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;
  }
예제 #4
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;
  }