org.apache.commons.scaffold.sql
Class ResultSetUtils

java.lang.Object
  extended byorg.apache.commons.scaffold.sql.ResultSetUtils

public class ResultSetUtils
extends java.lang.Object

General purpose utility methods related to ResultSets

Version:
$Revision: 1.9 $ $Date: 2004/03/21 21:10:27 $

Constructor Summary
ResultSetUtils()
           
 
Method Summary
static java.util.Collection getCollection(java.lang.Object target, java.sql.ResultSet resultSet)
          Return a ArrayList of beans populated from a ResultSet.
static boolean getElement(java.lang.Object target, java.sql.ResultSet resultSet)
          Populate target bean with the first record from a ResultSet.
static java.util.Map getMap(java.sql.ResultSet resultSet)
          Returns next record of result set as a Map.
static java.util.Collection getMaps(java.sql.ResultSet resultSet)
          Return a Collection of Maps, each representing a row from the ResultSet.
static void putEntry(java.util.Map properties, java.sql.ResultSetMetaData metaData, java.sql.ResultSet resultSet, int i)
          Map JDBC objects to Java equivalents.
static void setProperties(java.lang.Object bean, java.util.Map properties)
          Deprecated. Use BeanUtils.CopyProperties instead.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResultSetUtils

public ResultSetUtils()
Method Detail

getMap

public static java.util.Map getMap(java.sql.ResultSet resultSet)
                            throws java.sql.SQLException
Returns next record of result set as a Map. The keys of the map are the column names, as returned by the metadata. The values are the columns as Objects.

Parameters:
resultSet - The ResultSet to process.
Throws:
java.sql.SQLException - if an error occurs.

getMaps

public static java.util.Collection getMaps(java.sql.ResultSet resultSet)
                                    throws java.sql.SQLException
Return a Collection of Maps, each representing a row from the ResultSet. The keys of the map are the column names, as returned by the metadata. The values are the columns as Objects.

Parameters:
resultSet - The ResultSet to process.
Throws:
java.sql.SQLException - if an error occurs.

setProperties

public static void setProperties(java.lang.Object bean,
                                 java.util.Map properties)
                          throws java.lang.IllegalAccessException,
                                 java.lang.reflect.InvocationTargetException
Deprecated. Use BeanUtils.CopyProperties instead.

Populate the JavaBean properties of the specified bean, based on the specified name/value pairs. This method uses Java reflection APIs to identify corresponding "property setter" method names. The type of the value in the Map must match the setter type. The setter must expect a single arguement (the one on the Map).

The particular setter method to be called for each property is determined using the usual JavaBeans introspection mechanisms. Thus, you may identify custom setter methods using a BeanInfo class that is associated with the class of the bean itself. If no such BeanInfo class is available, the standard method name conversion ("set" plus the capitalized name of the property in question) is used.

NOTE: It is contrary to the JavaBeans Specification to have more than one setter method (with different argument signatures) for the same property.

This method adopted from the Apache Commons BeanUtils.populate.

Parameters:
bean - JavaBean whose properties are being populated
properties - Map keyed by property name, with the corresponding value to be set
Throws:
java.lang.IllegalAccessException - if the caller does not have access to the property accessor method
java.lang.reflect.InvocationTargetException - if the property accessor method throws an exception

putEntry

public static void putEntry(java.util.Map properties,
                            java.sql.ResultSetMetaData metaData,
                            java.sql.ResultSet resultSet,
                            int i)
                     throws java.sql.SQLException
Map JDBC objects to Java equivalents. Used by getBean() and getBeans().

Some types not supported. Many not work with all drivers.

Makes binary conversions of BIGINT, DATE, DECIMAL, DOUBLE, FLOAT, INTEGER, REAL, SMALLINT, TIME, TIMESTAMP, TINYINT. Makes Sting conversions of CHAR, CLOB, VARCHAR, LONGVARCHAR, BLOB, LONGVARBINARY, VARBINARY.

DECIMAL, INTEGER, SMALLINT, TIMESTAMP, CHAR, VARCHAR tested with MySQL and Poolman. Others not guaranteed.

Throws:
java.sql.SQLException

getElement

public static boolean getElement(java.lang.Object target,
                                 java.sql.ResultSet resultSet)
                          throws java.sql.SQLException
Populate target bean with the first record from a ResultSet.

Parameters:
resultSet - The ResultSet whose parameters are to be used to populate bean properties
target - An instance of the bean to populate
Returns:
True if resultSet contained a next element
Throws:
java.sql.SQLException - if an exception is thrown while setting property values, populating the bean, or accessing the ResultSet

getCollection

public static java.util.Collection getCollection(java.lang.Object target,
                                                 java.sql.ResultSet resultSet)
                                          throws java.sql.SQLException
Return a ArrayList of beans populated from a ResultSet.

Parameters:
resultSet - The ResultSet whose parameters are to be used to populate bean properties
target - An instance of the bean to populate
Throws:
java.sql.SQLException - if an exception is thrown while setting property values, populating the bean, or accessing the ResultSet


Copyright © 2002-2005 The Apache Software Foundation. All Rights Reserved.