org.apache.commons.dbutils.handlers
Class BeanHandler

java.lang.Object
  extended by org.apache.commons.dbutils.handlers.BeanHandler
All Implemented Interfaces:
ResultSetHandler

public class BeanHandler
extends java.lang.Object
implements ResultSetHandler

ResultSetHandler implementation that converts the first ResultSet row into a JavaBean. This class is thread safe.

Author:
Juozas Baliuka, David Graham
See Also:
ResultSetHandler

Field Summary
private  RowProcessor convert
          The RowProcessor implementation to use when converting rows into beans.
private  java.lang.Class type
          The Class of beans produced by this handler.
 
Constructor Summary
BeanHandler(java.lang.Class type)
          Creates a new instance of BeanHandler.
BeanHandler(java.lang.Class type, RowProcessor convert)
          Creates a new instance of BeanHandler.
 
Method Summary
 java.lang.Object handle(java.sql.ResultSet rs)
          Convert the first row of the ResultSet into a bean with the Class given in the constructor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

type

private java.lang.Class type
The Class of beans produced by this handler.


convert

private RowProcessor convert
The RowProcessor implementation to use when converting rows into beans.

Constructor Detail

BeanHandler

public BeanHandler(java.lang.Class type)
Creates a new instance of BeanHandler.

Parameters:
type - The Class that objects returned from handle() are created from.

BeanHandler

public BeanHandler(java.lang.Class type,
                   RowProcessor convert)
Creates a new instance of BeanHandler.

Parameters:
type - The Class that objects returned from handle() are created from.
convert - The RowProcessor implementation to use when converting rows into beans.
Method Detail

handle

public java.lang.Object handle(java.sql.ResultSet rs)
                        throws java.sql.SQLException
Convert the first row of the ResultSet into a bean with the Class given in the constructor.

Specified by:
handle in interface ResultSetHandler
Parameters:
rs - The ResultSet to handle. It has not been touched before being passed to this method.
Returns:
An initialized JavaBean or null if there were no rows in the ResultSet.
Throws:
java.sql.SQLException
See Also:
ResultSetHandler.handle(java.sql.ResultSet)