atg.cortex
Class ResultSetProcessor

java.lang.Object
  extended by atg.cortex.PropertyList
      extended by atg.cortex.ResultSetProcessor
Direct Known Subclasses:
Query

public class ResultSetProcessor
extends PropertyList

This subclass of PropertyList is able to process ResultSets into Java Objects. The processor must be prepared with a set of Property objects that correspond to the columns expected from the ResultSet. Null Properties represent ResultSet elements that are to be ignored.


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Constructor Summary
ResultSetProcessor()
          Constructs a new ResultSetProcessor
 
Method Summary
 java.lang.Object[] processResultSet(java.sql.ResultSet pResultSet)
          Processes the specified ResultSet and returns an array of the resulting objects.
 java.lang.Object[] processResultSet(java.sql.ResultSet pResultSet, int pFirstRow, int pMaxRows)
          Processes the specified ResultSet and returns an array of the resulting objects.
 java.lang.Object processResultSetRow(java.sql.ResultSet pResultSet)
          Processes one ResultSet row.
 java.lang.Object processResultSetRow(java.sql.ResultSet pResultSet, java.lang.Object pObject)
          Processes one ResultSet row by filling in the values of the specified object, as opposed to creating a new object to hold the values.
 java.lang.Object[] processResultSetRow(java.sql.ResultSet pResultSet, java.lang.Object[] pObject)
          Processes one ResultSet row by filling in the values of the specified objects, as opposed to creating new objects to hold the values.
 
Methods inherited from class atg.cortex.PropertyList
addProperties, addProperty, getBeanClass, getBeanClasses, getClassProperties, getProperties, getProperty, getPropertyCount, getPropertyToClassTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

ResultSetProcessor

public ResultSetProcessor()
Constructs a new ResultSetProcessor

Method Detail

processResultSet

public java.lang.Object[] processResultSet(java.sql.ResultSet pResultSet)
                                    throws java.sql.SQLException
Processes the specified ResultSet and returns an array of the resulting objects. Each object is obtained by calling processResultSetRow.

Parameters:
pResultSet - the ResultSet to process
Returns:
an array of the objects read from the rows of the ResultSet. The return value type is Object[], and should not be expected to be castable to a subclass of Object[]. For example, even if the expected objects are of class "Person", the resulting value is still of type Object[], not Person[]. Each member of the array must be cast to "Person" indiviudally.
Throws:
java.sql.SQLException - if an error occurred during processing
See Also:
processResultSetRow(java.sql.ResultSet)

processResultSet

public java.lang.Object[] processResultSet(java.sql.ResultSet pResultSet,
                                           int pFirstRow,
                                           int pMaxRows)
                                    throws java.sql.SQLException
Processes the specified ResultSet and returns an array of the resulting objects. Each object is obtained by calling processResultSetRow. A range of rows may be specified. Rows are skipped until the FirstRow is reached (where 0 is the first row). For example, if FirstRow is 4, then rows 0,1,2,3 are skipped. MaxRows specifies the maximum number of rows to be returned.

Parameters:
pResultSet - the ResultSet to process
pFirstRow - the first row to skip to, where 0 is the first row
pMaxRows - the maximum number of rows to return. All subsequent rows are discarded. If -1, then there is no maximum.
Returns:
an array of the objects read from the rows of the ResultSet. The return value type is Object[], and should not be expected to be castable to a subclass of Object[]. For example, even if the expected objects are of class "Person", the resulting value is still of type Object[], not Person[]. Each member of the array must be cast to "Person" indiviudally.
Throws:
java.sql.SQLException - if an error occurred during processing
See Also:
processResultSetRow(java.sql.ResultSet)

processResultSetRow

public java.lang.Object processResultSetRow(java.sql.ResultSet pResultSet)
                                     throws java.sql.SQLException
Processes one ResultSet row. This will examine the ResultSet columns to see how many different classes are specified by those columns. This will then create one object per class, put those objects into an array, assign the values from the result set into the objects, then return the array. The objects will be ordered in the array by the order in which their classes first appear in the column list, which is the order returned by getBeanClasses().

For example, if columns 1-3 were associated with the Person class, and columns 4-5 were associated with the Payscale class, then two objects would be created, one Person and one Payscale. The appropriate result set values would be assigned to the two objects. A 2-element object array would then be created, with element 0 containing the Person and element 1 containing the Payscale. The array is then returned.

If only one class is used by all the columns, then an array of objects is not created. Instead, the object of the appropriate class is created and returned, thereby avoiding the degenerate case of having a bunch of 1-element object arrays.

Parameters:
pResultSet - the ResultSet from which one row should be processed.
Returns:
the object or array of objects created from the result set
Throws:
java.sql.SQLException - if an error occurred during processing
See Also:
processResultSet(java.sql.ResultSet)

processResultSetRow

public java.lang.Object processResultSetRow(java.sql.ResultSet pResultSet,
                                            java.lang.Object pObject)
                                     throws java.sql.SQLException
Processes one ResultSet row by filling in the values of the specified object, as opposed to creating a new object to hold the values. The object is returned. This should only be called for cases where all of the columns correspond to the properties of a single object.

Parameters:
pResultSet - the ResultSet from which one row should be processed.
pObject - the object whose values are to be filled in from the row
Returns:
pObject
Throws:
java.sql.SQLException - if an error occurred during processing
See Also:
processResultSet(java.sql.ResultSet)

processResultSetRow

public java.lang.Object[] processResultSetRow(java.sql.ResultSet pResultSet,
                                              java.lang.Object[] pObject)
                                       throws java.sql.SQLException
Processes one ResultSet row by filling in the values of the specified objects, as opposed to creating new objects to hold the values. The array of objects is returned. The array of objects passed in should correspond to the different classes referred to by the columns. The number and order of these classes can be obtained by calling getBeanClasses ().

Parameters:
pResultSet - the ResultSet from which one row should be processed.
pObject - the array of objects whose values are to be filled in from the row
Returns:
pObject
Throws:
java.sql.SQLException - if an error occurred during processing
See Also:
processResultSet(java.sql.ResultSet)