org.apache.commons.dbutils
Class BasicRowProcessor

java.lang.Object
  extended byorg.apache.commons.dbutils.BasicRowProcessor
All Implemented Interfaces:
RowProcessor

public class BasicRowProcessor
extends java.lang.Object
implements RowProcessor

Basic implementation of the RowProcessor interface. This class is a thread-safe Singleton.

Author:
Henri Yandell, Juozas Baliuka, David Graham, Yoav Shapira
See Also:
RowProcessor

Constructor Summary
protected BasicRowProcessor()
          Protected constructor for BasicRowProcessor subclasses only.
 
Method Summary
static BasicRowProcessor instance()
          Returns the Singleton instance of this class.
 java.lang.Object[] toArray(java.sql.ResultSet rs)
          Convert a ResultSet row into an Object[].
 java.lang.Object toBean(java.sql.ResultSet rs, java.lang.Class type)
          Convert a ResultSet row into a JavaBean.
 java.util.List toBeanList(java.sql.ResultSet rs, java.lang.Class type)
          Convert a ResultSet into a List of JavaBeans.
 java.util.Map toMap(java.sql.ResultSet rs)
          Convert a ResultSet row into a Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicRowProcessor

protected BasicRowProcessor()
Protected constructor for BasicRowProcessor subclasses only.

Method Detail

instance

public static BasicRowProcessor instance()
Returns the Singleton instance of this class.

Returns:
The single instance of this class.

toArray

public java.lang.Object[] toArray(java.sql.ResultSet rs)
                           throws java.sql.SQLException
Convert a ResultSet row into an Object[]. This implementation copies column values into the array in the same order they're returned from the ResultSet. Array elements will be set to null if the column was SQL NULL.

Specified by:
toArray in interface RowProcessor
Throws:
java.sql.SQLException
See Also:
RowProcessor.toArray(java.sql.ResultSet)

toBean

public java.lang.Object toBean(java.sql.ResultSet rs,
                               java.lang.Class type)
                        throws java.sql.SQLException
Convert a ResultSet row into a JavaBean. This implementation uses reflection and BeanInfo classes to match column names to bean property names. Properties are matched to columns based on several factors:
  1. The class has a writable property with the same name as a column. The name comparison is case insensitive.
  2. The property's set method parameter type matches the column type. If the data types do not match, the setter will not be called.

Primitive bean properties are set to their defaults when SQL NULL is returned from the ResultSet. Numeric fields are set to 0 and booleans are set to false. Object bean properties are set to null when SQL NULL is returned. This is the same behavior as the ResultSet get* methods.

Specified by:
toBean in interface RowProcessor
Throws:
java.sql.SQLException
See Also:
RowProcessor.toBean(java.sql.ResultSet, java.lang.Class)

toBeanList

public java.util.List toBeanList(java.sql.ResultSet rs,
                                 java.lang.Class type)
                          throws java.sql.SQLException
Convert a ResultSet into a List of JavaBeans. This implementation uses reflection and BeanInfo classes to match column names to bean property names. Properties are matched to columns based on several factors:
  1. The class has a writable property with the same name as a column. The name comparison is case insensitive.
  2. The property's set method parameter type matches the column type. If the data types do not match, the setter will not be called.

Primitive bean properties are set to their defaults when SQL NULL is returned from the ResultSet. Numeric fields are set to 0 and booleans are set to false. Object bean properties are set to null when SQL NULL is returned. This is the same behavior as the ResultSet get* methods.

Specified by:
toBeanList in interface RowProcessor
Returns:
A List of beans with the given type in the order they were returned by the ResultSet.
Throws:
java.sql.SQLException
See Also:
RowProcessor.toBeanList(java.sql.ResultSet, java.lang.Class)

toMap

public java.util.Map toMap(java.sql.ResultSet rs)
                    throws java.sql.SQLException
Convert a ResultSet row into a Map. This implementation returns a Map with case insensitive column names as keys. Calls to map.get("COL") and map.get("col") return the same value.

Specified by:
toMap in interface RowProcessor
Throws:
java.sql.SQLException
See Also:
RowProcessor.toMap(java.sql.ResultSet)


Copyright © 2002-2003 Apache Software Foundation. All Rights Reserved.