/** * @param columnIdx * @param obj * @roseuid 3E5D8981013E */ public void setObject(int columnIdx, Object obj) { if (columnIdx < 0 || columnIdx > fieldCount || currentNo < 0 || currentNo > recordCount) return; String name = (String) fieldNames.get(columnIdx); RecordMetaData rmd = (RecordMetaData) metadata.get(name); Record record = (Record) records.get(currentNo); record.set(columnIdx, obj); }
/** * @param columnIdx * @return Object * @roseuid 3E5D894200B1 */ public Object getObject(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); return value; }
public String getTimeString(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; return value.toString().trim().split("\\.")[0]; }
/** * @param list * @roseuid 3E5D7DA30384 */ public void merge(java.util.List list) { if (list == null) return; for (Iterator it = list.iterator(); it.hasNext(); ) { Object obj = it.next(); if (obj instanceof Record) records.add(obj); } }
/** * @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(); }
/** * 只有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; } }
/** * @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 }
/** * @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; } }
/** * If the value of the column is null, String returned is set with ""; * * @param columnName * @return */ public String getStringSmart(String columnName) { if (columnName == null) { return ""; } int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); String columnValue = null; if (getString(columnIdx) != null) { columnValue = getString(columnIdx).trim(); } else { columnValue = ""; } return columnValue; }
/** * @param columnName * @return java.util.Calendar * @roseuid 3E5D8B310121 */ public java.util.Date getCalendar(String columnName) { if (columnName == null) return null; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getCalendar(columnIdx); }
/** * @param columnName * @return char * @roseuid 3E5D8B110053 */ public char getChar(String columnName) throws Exception { if (columnName == null) return 0; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getChar(columnIdx); }
public String getTimeString(String columnName) { if (columnName == null) return ""; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getTimeString(columnIdx); }
/** * @param columnName * @return double * @roseuid 3E5D8B0300C1 */ public double getDouble(String columnName) { if (columnName == null) return 0; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getDouble(columnIdx); }
/** * @param record * @roseuid 3E5D7D89030F */ public void delete(Record record) { records.remove(record); }
/** @roseuid 3E5EABDE02D3 */ public void close() { records.clear(); metadata.clear(); records = null; metadata = null; }
public String getFieldName(int columnIdx) { String name = (String) fieldNames.get(columnIdx); return name; }
/** * @param columnName * @return Object * @roseuid 3E5D8B4601A3 */ public Object getObject(String columnName) { if (columnName == null) return null; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getObject(columnIdx); }
/** * @param columnName * @param type * @return Object * @roseuid 3E5D8B55035D */ public Object getObject(String columnName, String type) throws Exception { if (columnName == null) return null; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getObject(columnIdx, type); }
/** * @param columnName * @return boolean * @roseuid 3E5D8A760186 */ public boolean getBoolean(String columnName) { if (columnName == null) return false; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getBoolean(columnIdx); }
/** * @param columnIdx * @param obj * @roseuid 3E5D8981013E */ public void setObject(String columnName, Object obj) { if (columnName == null) return; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); setObject(columnIdx, obj); }
/** * @param columnName * @return float * @roseuid 3E5D8AF00286 */ public float getFloat(String columnName) { if (columnName == null) return 0; int columnIdx = fieldNames.indexOf(columnName.toLowerCase()); return getFloat(columnIdx); }
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(); } }
/** * @param record * @roseuid 3E5D7CDF033C */ public void add(Record record) { records.add(record); }