FileDocCategorySizeDatePackage
LightRowSet.javaAPI DocExample1767Mon Nov 24 10:08:52 GMT 2003com.oreilly.patterns.chapter7

LightRowSet

public class LightRowSet extends Object implements Serializable
Provide a lightweight wrapper for a set of rows. Preserve types as best as possible.

Fields Summary
ArrayList
rows
int
rowCount
int
colCount
String[]
colNames
Constructors Summary
public LightRowSet(ResultSet rs)


         
        rows = new ArrayList();

        if (rs == null) {
            throw new SQLException("No ResultSet Provided");
        }

        ResultSetMetaData rsmd = rs.getMetaData();
        colCount = rsmd.getColumnCount();
        colNames = new String[colCount];

        for (int i = 0; i < colCount; i++) {
            colNames[i] = rsmd.getColumnName(i + 1);
        }

        while (rs.next()) {
            Object[] row = new Object[colCount];

            for (int i = 0; i < colCount; i++)
                row[i] = rs.getObject(i + 1);

            rows.add(row);
        }

        rs.close();
    
Methods Summary
public java.lang.String[]getColumnNames()
Return the column names in this row set, in indexed order

        return colNames;
    
public java.lang.Object[]getRow(int index)
Return a particular row, indexed from 1..n. Return null if the row isn't found.

      try {
        return (Object[]) rows.get(index - 1);
      } catch (ArrayIndexOutOfBoundsException aioobe) {
        return null;
      }
    
public intgetRowCount()

        return rows.size();
    
public java.util.IteratorgetRows()
Return an iterator containing all of the rows

        return rows.iterator();