org.hdpagination.dataaccess.support.jdbc
Class BeanPropertyRowMapper

java.lang.Object
  extended by org.hdpagination.dataaccess.support.jdbc.BeanPropertyRowMapper
All Implemented Interfaces:
java.io.Serializable, RowMapper

public class BeanPropertyRowMapper
extends java.lang.Object
implements RowMapper

RowMapper implementation that converts a row into a new instance of the specified mapped target class. The mapped target class must be a top-level class and it must have a default or no-arg constructor. Column values are mapped based on matching the column name as obtained from result set metadata to public setters for the corresponding properties. The names are matched either directly or by transforming a name separating the parts with underscores to the same name using "camel" case. Mapping is provided for fields in the target class for many common types, e.g.: String, boolean, Boolean, byte, Byte, short, Short, int, Integer, long, Long, float, Float, double, Double, BigDecimal, java.util.Date, etc. To facilitate mapping between columns and fields that don't have matching names, try using column aliases in the SQL statement like "select fname as first_name from customer. Please note that this class is designed to provide convenience rather than high performance. For best performance consider using a custom RowMapper.

Also very importantly, this class internally uses some classes available only since Spring framework 2.5.2. So this class can only be used if Spring framework 2.5.2 or later version is used.

Since:
1.3.1
Author:
Liangfeng Ren
See Also:
Serialized Form

Method Summary
protected  void initialize(java.lang.Class mappedClass)
          Initialize the mapping metadata for the given class.
static BeanPropertyRowMapper newInstance(java.lang.Class mappedClass)
           
 java.lang.Object processRow(java.sql.ResultSet rs)
          Implementations must implement this method to map each row of data in the ResultSet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static BeanPropertyRowMapper newInstance(java.lang.Class mappedClass)

initialize

protected void initialize(java.lang.Class mappedClass)
Initialize the mapping metadata for the given class.

Parameters:
mappedClass - the mapped class.

processRow

public java.lang.Object processRow(java.sql.ResultSet rs)
                            throws java.sql.SQLException
Description copied from interface: RowMapper
Implementations must implement this method to map each row of data in the ResultSet. This method should not call next() on the ResultSet; it is only supposed to map values of the current row.

Specified by:
processRow in interface RowMapper
Parameters:
rs - the ResultSet to map (pre-initialized for the current row)
Returns:
the result object for the current row
Throws:
java.sql.SQLException - - if a SQLException is encountered getting column values (that is, there's no need to catch SQLException)


Copyright © 2008 HDPagination All Rights Reserved.