org.apache.beehive.controls.system.jdbc
Class RowMapper

Object
  extended by RowMapper
Direct Known Subclasses:
RowToHashMapMapper, RowToMapMapper, RowToObjectMapper, RowToXmlObjectMapper

public abstract class RowMapper
extends Object

Abstract base class for all row mappers. RowMappers are used to map the contents of a row in a ResultSet to the return type of an annotated method. Supported RowMapper types include: HashMap, Map, Object, XmlObject. When a ResultSetMapper is ready to map a ResultSet row to an object, it requests a RowMapper for the return type of the method from the RowMapperFactory.


Field Summary
protected  Calendar _cal
          Calendar instance for date/time mappings.
protected  ResultSet _resultSet
          ResultSet to map.
protected  Class<?> _returnTypeClass
          Class to map ResultSet Rows to.
protected static Pattern _setterRegex
           
protected static TypeMappingsFactory _tmf
           
 
Constructor Summary
protected RowMapper(ResultSet resultSet, Class<?> returnTypeClass, Calendar cal)
          Create a new RowMapper for the specified ResultSet and return type Class.
 
Method Summary
protected  Object extractColumnValue(int index, int resultType)
          Extract a column value from the ResultSet and return it as resultType.
protected  String[] getKeysFromResultSet()
          Build a String array of column names from the ResultSet.
protected  boolean isSetterMethod(Method method)
          Determine if the given method is a java bean setter method.
abstract  Object mapRowToReturnType()
          Map a ResultSet row to the return type class
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tmf

protected static final TypeMappingsFactory _tmf

_setterRegex

protected static final Pattern _setterRegex

_resultSet

protected final ResultSet _resultSet
ResultSet to map.


_cal

protected final Calendar _cal
Calendar instance for date/time mappings.


_returnTypeClass

protected final Class<?> _returnTypeClass
Class to map ResultSet Rows to.

Constructor Detail

RowMapper

protected RowMapper(ResultSet resultSet,
                    Class<?> returnTypeClass,
                    Calendar cal)
Create a new RowMapper for the specified ResultSet and return type Class.

Parameters:
resultSet - ResultSet to map
returnTypeClass - Class to map ResultSet rows to.
cal - Calendar instance for date/time values.
Method Detail

mapRowToReturnType

public abstract Object mapRowToReturnType()
Map a ResultSet row to the return type class

Returns:
An instance of class.

getKeysFromResultSet

protected String[] getKeysFromResultSet()
                                 throws SQLException
Build a String array of column names from the ResultSet.

Returns:
A String array containing the column names contained within the ResultSet.
Throws:
SQLException - on error

isSetterMethod

protected boolean isSetterMethod(Method method)
Determine if the given method is a java bean setter method.

Parameters:
method - Method to check
Returns:
True if the method is a setter method.

extractColumnValue

protected Object extractColumnValue(int index,
                                    int resultType)
                             throws SQLException
Extract a column value from the ResultSet and return it as resultType.

Parameters:
index - The column index of the value to extract from the ResultSet.
resultType - The return type. Defined in TypeMappingsFactory.
Returns:
The extracted value
Throws:
SQLException - on error.