/** */ /** * Create on Feb 7, 2007 */ package com.jinfonet.loganalyzer.ui.viewers; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; /** */ /** * @author gengwei.zheng * */ public class CachingDataTableModel extends DataTableModel ... { /** *//** * serialVersionUID = 2576405109640476616L */ private static final long serialVersionUID = 2576405109640476616L; protected Vector dataVector; protected Vector columnNames; public CachingDataTableModel(ResultSet aResultSet) ...{ super(aResultSet); try ...{ dataVector = new Vector(); columnNames = new Vector(); int cols = getColumnCount(); ResultSet rs = getResultSet(); while (rs.next()) ...{ Object[] row = new Object[cols]; row[0] = new Boolean(false); for (int i = 1; i < row.length; i++) ...{ row[i] = rs.getObject(i); } dataVector.add(row); } for (int j = 1; j < cols; j++) ...{ columnNames.add(j - 1, rs.getMetaData().getColumnName(j)); } } catch (SQLException e) ...{ e.printStackTrace(); }catch(Exception e)...{ e.printStackTrace(); } } public int getRowCount() ...{ return dataVector.size(); } public Object getValueAt(int rowIndex, int columnIndex) ...{ if (rowIndex < dataVector.size()) ...{ return ((Object[])dataVector.get(rowIndex))[columnIndex]; } else ...{ return null; } } public void setValueAt(Object aValue, int rowIndex, int columnIndex) ...{ ((Object[])dataVector.get(rowIndex))[0] = aValue; } protected void refetchData(ResultSet newResultSet) ...{ super.refetchData(newResultSet); try ...{ if (dataVector != null) dataVector.clear(); if (columnNames != null) columnNames.clear(); int cols = getColumnCount(); ResultSet rs = getResultSet(); while (rs.next()) ...{ Object[] row = new Object[cols]; row[0] = new Boolean(false); for (int i = 1; i < row.length; i++) ...{ row[i] = rs.getObject(i); } dataVector.add(row); } for (int j = 1; j < cols; j++) ...{ columnNames.add(j - 1, rs.getMetaData().getColumnName(j)); } } catch (SQLException e) ...{ e.printStackTrace(); } }}