com.interface21.jdbc.core
Class RowCountCallbackHandler

java.lang.Object
  |
  +--com.interface21.jdbc.core.RowCountCallbackHandler
All Implemented Interfaces:
RowCallbackHandler
Direct Known Subclasses:
ReflectionRowExtractor

public class RowCountCallbackHandler
extends java.lang.Object
implements RowCallbackHandler

Implementation of RowCallbackHandler. Convenient superclass for callback handlers. We can either use this on its own (for example, in a test case, to ensure that our result sets have valid dimensions), or use it as a superclass for callback handlers that actually do something, and will benefit from the dimension information it provides. Can only be used once

Since:
May 3, 2001
Version:
$Id: RowCountCallbackHandler.java,v 1.2 2003/04/08 11:23:52 isabellem Exp $
Author:
Rod Johnson

Constructor Summary
RowCountCallbackHandler()
           
 
Method Summary
 int getColumnCount()
          Return the number of columns in this result set.
 java.lang.String[] getColumnNames()
          Return the names of the columns.
 int[] getColumnTypes()
          Return the types of the columns as java.sql.Types constants Valid after processRow is invoked the first time.
 int getRowCount()
          Return the row count of this ResultSet Only valid after processing is complete
 void processRow(java.sql.ResultSet rs)
          Implementation of ResultSetCallbackHandler.
protected  void processRow(java.sql.ResultSet rs, int rowNum)
          Subclasses may override this to perform custom extraction or processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RowCountCallbackHandler

public RowCountCallbackHandler()
Method Detail

processRow

public final void processRow(java.sql.ResultSet rs)
                      throws java.sql.SQLException
Implementation of ResultSetCallbackHandler. Work out column size if this is the first row, otherwise just count rows.
Subclasses can perform custom extraction or processing by overriding the processRow(ResultSet, int) method.
Specified by:
processRow in interface RowCallbackHandler
Following copied from interface: com.interface21.jdbc.core.RowCallbackHandler
Parameters:
ResultSet -  
Throws:
java.sql.SQLException - if a SQLException is encountered getting column values (that is, there's no need to catch SQLException)

processRow

protected void processRow(java.sql.ResultSet rs,
                          int rowNum)
                   throws java.sql.SQLException
Subclasses may override this to perform custom extraction or processing. This class's implementation does nothing.
Parameters:
rs - ResultSet to extract data from. This method is invoked for each row
rowNum - number of the current row (starting from 0)

getColumnTypes

public final int[] getColumnTypes()
Return the types of the columns as java.sql.Types constants Valid after processRow is invoked the first time.
Returns:
the types of the columns as java.sql.Types constants. Indexed from 0 to n-1.

getColumnNames

public final java.lang.String[] getColumnNames()
Return the names of the columns. Valid after processRow is invoked the first time.
Returns:
the names of the columns. Indexed from 0 to n-1.

getRowCount

public final int getRowCount()
Return the row count of this ResultSet Only valid after processing is complete
Returns:
the number of rows in this ResultSet

getColumnCount

public final int getColumnCount()
Return the number of columns in this result set. Valid once we've seen the first row, so subclasses can use it during processing
Returns:
the number of columns in this result set


Rod Johnson and Spring contributors 2001-2003.