Пример #1
0
 /**
  * @param idx
  * @return com.zt.db.RecordMetaData
  * @roseuid 3E5D800400FF
  */
 public RecordMetaData getMetaData(int idx) {
   Collection cl = metadata.values();
   for (Iterator it = cl.iterator(); it.hasNext(); ) {
     RecordMetaData rmd = (RecordMetaData) it.next();
     if (rmd.getSeqno() == idx) return rmd;
   }
   return null;
 }
Пример #2
0
  /**
   * @param columnIdx
   * @return String
   * @roseuid 3E5D88F000F9
   */
  public String getString(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return null;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) return "";

    if ((rmd.getType() == MetaDataTypes.CALENDAR_TP)
        || (rmd.getType() == MetaDataTypes.TIMESTAMP_TP)) {
      String[] DateStr = value.toString().trim().split("\\.");
      return DateStr[0];
    }
    return value.toString().trim();
  }
Пример #3
0
  /**
   * 只有String和Boolean类型进行转换,其他类型均返回false
   *
   * @param columnIdx
   * @return boolean
   * @roseuid 3E5D883200BA
   */
  public boolean getBoolean(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return false;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);

    if (rmd.getType() == MetaDataTypes.STRING_TP) {
      Record record = (Record) records.get(currentNo);
      String value = (String) record.get(columnIdx);
      if (value == null || value.equals("0")) return false;
      return true;
    }
    if (rmd.getType() == MetaDataTypes.BOOLEAN_TP) {
      Record record = (Record) records.get(currentNo);
      Boolean value = (Boolean) record.get(columnIdx);
      return value.booleanValue();
    } else {
      return false;
    }
  }
Пример #4
0
  /**
   * @param columnIdx
   * @return double
   * @roseuid 3E5D88C701AE
   */
  public double getDouble(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return 0;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) return 0;

    switch (rmd.getType()) {
      case MetaDataTypes.BIGDECIMAL_TP:
        return ((BigDecimal) value).doubleValue();
      case MetaDataTypes.BIGINTEGER_TP:
        return ((BigInteger) value).doubleValue();
      case MetaDataTypes.BOOLEAN_TP:
        Boolean b = (Boolean) value;
        if (b.booleanValue()) return 1;
        else return 0;
      case MetaDataTypes.DOUBLE_TP:
        return ((Double) value).doubleValue();
      case MetaDataTypes.FLOAT_TP:
        return ((Float) value).doubleValue();
      case MetaDataTypes.INTEGER_TP:
        return ((Integer) value).doubleValue();
      case MetaDataTypes.LONG_TP:
        return ((Long) value).doubleValue();
      case MetaDataTypes.SHORT_TP:
        return ((Short) value).doubleValue();
      case MetaDataTypes.STRING_TP:
        try {
          return Double.parseDouble((String) value);
        } catch (Exception e) {
          return 0;
        }
      default:
        return 0;
    } // switch
  }
Пример #5
0
  /**
   * @param columnIdx
   * @return java.util.Calendar
   * @roseuid 3E5D8903036D
   */
  public java.util.Date getCalendar(int columnIdx) {
    if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount)
      return null;

    String name = (String) fieldNames.get(columnIdx);
    RecordMetaData rmd = (RecordMetaData) metadata.get(name);
    Record record = (Record) records.get(currentNo);
    Object value = record.get(columnIdx);
    if (value == null) {
      return null;
    } else {
    }

    if ((rmd.getType() == MetaDataTypes.CALENDAR_TP)
        || (rmd.getType() == MetaDataTypes.TIMESTAMP_TP)) {
      java.util.Date d = (java.util.Date) value;

      // Calendar c=Calendar.getInstance();
      // c.set(1900+d.getYear(),d.getMonth(),d.getDate());
      return d;
    } else {
      return null;
    }
  }
 /** performs a deep copy of all the attributes of the field */
 public FieldMetaData deepCopy() {
   FieldMetaData fieldCopy = new ElementaryFieldMetaData(new String(myName), myRecord.getName());
   fieldCopy.setIsFieldRedefine(isRedefine);
   fieldCopy.setDecimalPosition(decimalPosition);
   fieldCopy.setArraySize(myArraySize);
   fieldCopy.setSize(mySize);
   fieldCopy.setOffset(myOffset);
   fieldCopy.setType(myType);
   if (isFieldRedefine()) {
     fieldCopy.setFieldRedefined(myFieldRedefined.deepCopy());
   }
   fieldCopy.setDependentFieldName(new String(myDependentFieldName));
   fieldCopy.setIsSigned(isSigned);
   return fieldCopy;
 }
Пример #7
0
  private void init(ResultSet rs, int resultNo) {
    if (rs == null) return;

    try {
      ResultSetMetaData rsmd = rs.getMetaData();
      int count = rsmd.getColumnCount();
      for (int i = 1; i <= count; i++) {
        String name = rsmd.getColumnName(i);
        if (name != null) name = name.toLowerCase();
        String typeName = rsmd.getColumnClassName(i);
        String caption = rsmd.getColumnLabel(i);
        RecordMetaData rmd = new RecordMetaData(name, typeName, caption, i);
        metadata.put(name, rmd);
        fieldNames.add(name);
      }
      fieldCount = count;

      while (rs.next()) {
        ArrayList record = new ArrayList();

        for (int i = 1; i <= count; i++) {
          String name = (String) fieldNames.get(i - 1);
          RecordMetaData rmd = (RecordMetaData) metadata.get(name);

          // System.out.println(rmd.getType());

          switch (rmd.getType()) {
            case MetaDataTypes.BIGDECIMAL_TP:
            case MetaDataTypes.BIGINTEGER_TP:
              record.add(rs.getBigDecimal(i));
              break;
            case MetaDataTypes.BOOLEAN_TP:
              record.add(new Boolean(rs.getBoolean(i)));
              break;
            case MetaDataTypes.BYTE_TP:
              record.add(new Byte(rs.getByte(i)));
              break;
            case MetaDataTypes.CALENDAR_TP:
              java.sql.Date d = rs.getDate(i);
              //                            Calendar calendar = GregorianCalendar.getInstance();
              //                            System.out.println("aaaaaaaa"+d);
              //                            calendar.set(d.getYear()+1900,d.getMonth(),d.getDay());
              record.add(d);
              break;
            case MetaDataTypes.CHARACTER_TP:
              break;
            case MetaDataTypes.DOUBLE_TP:
              record.add(new Double(rs.getDouble(i)));
              break;
            case MetaDataTypes.FLOAT_TP:
              record.add(new Float(rs.getFloat(i)));
              break;
            case MetaDataTypes.INTEGER_TP:
              record.add(new Integer(rs.getInt(i)));
              break;
            case MetaDataTypes.LONG_TP:
              record.add(new Long(rs.getLong(i)));
              break;
            case MetaDataTypes.SHORT_TP:
              record.add(new Short(rs.getShort(i)));
              break;
            case MetaDataTypes.STRING_TP:
              record.add(DBUtil.fromDB(rs.getString(i)));
              break;
            default:
              InputStream is = rs.getBinaryStream(i);
              record.add(is);
          } // switch
        } // for

        records.add(new Record(record));
        recordCount++;
        if (recordCount == resultNo) {
          break;
        }
      } // while
    } catch (SQLException sqle) {
      sqle.printStackTrace();
    }
  }
Пример #8
0
 /**
  * 返回制定栏位的序号
  *
  * @param name
  * @return int
  * @roseuid 3E5D8A2B00D4
  */
 public int findColumn(String name) {
   RecordMetaData rmd = (RecordMetaData) metadata.get(name);
   return rmd.getSeqno();
 }