com.uwyn.rife.database
Class DbBeanFetcher<BeanType>

java.lang.Object
  extended by com.uwyn.rife.database.DbRowProcessor
      extended by com.uwyn.rife.database.DbBeanFetcher<BeanType>
All Implemented Interfaces:
Cloneable

public class DbBeanFetcher<BeanType>
extends DbRowProcessor

This class allows a ResultSet to be easily processed into bean instance.

Multiple instances can be collected into a list when processing an entire ResultSet, or as a single bean instance can be retrieved for one row of a ResultSet. The default behavior is to not collect instances.

Since:
1.0
Version:
$Revision: 3701 $
Author:
JR Boyens (jboyens[remove] at uwyn dot com), Geert Bevin (gbevin[remove] at uwyn dot com)

Constructor Summary
DbBeanFetcher(Datasource datasource, Class<BeanType> beanClass)
          Create a new DbBeanFetcher
DbBeanFetcher(Datasource datasource, Class<BeanType> beanClass, boolean collectInstances)
          Create a new DbBeanFetcher
 
Method Summary
 BeanType getBeanInstance()
          Get the last processed bean instance
 List<BeanType> getCollectedInstances()
          Get the collected bean instances
 boolean gotBeanInstance(BeanType instance)
          Hook method that can be overloaded to receive new bean instances as they are retrieved, without relying on the internal collection into a list.
 boolean processRow(ResultSet resultSet)
          Process a ResultSet row into a bean.
 
Methods inherited from class com.uwyn.rife.database.DbRowProcessor
clone, wasSuccessful
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DbBeanFetcher

public DbBeanFetcher(Datasource datasource,
                     Class<BeanType> beanClass)
              throws BeanException
Create a new DbBeanFetcher

Parameters:
datasource - the datasource to be used
beanClass - the type of bean that will be handled
Throws:
BeanException - thrown if there is an error getting information about the bean via the beanClass
Since:
1.0

DbBeanFetcher

public DbBeanFetcher(Datasource datasource,
                     Class<BeanType> beanClass,
                     boolean collectInstances)
              throws BeanException
Create a new DbBeanFetcher

Parameters:
datasource - the datasource to be used
beanClass - the type of bean that will be handled
collectInstances - true if the fetcher should collected the bean instances; false if otherwise
Throws:
BeanException - thrown if there is an error getting information about the bean via the beanClass
Since:
1.0
Method Detail

processRow

public boolean processRow(ResultSet resultSet)
                   throws SQLException
Process a ResultSet row into a bean. Call this method on a ResultSet and the resulting bean will be stored and be accessible via getBeanInstance()

Specified by:
processRow in class DbRowProcessor
Parameters:
resultSet - the ResultSet from which to process the row
Returns:
true if a bean instance was retrieved; or

false if otherwise

Throws:
SQLException - thrown when there is a problem processing the row
See Also:
DbQueryManager.fetch(ResultSet, DbRowProcessor), DbRowProcessor.wasSuccessful()

gotBeanInstance

public boolean gotBeanInstance(BeanType instance)
Hook method that can be overloaded to receive new bean instances as they are retrieved, without relying on the internal collection into a list.

Parameters:
instance - the received bean instance
Returns:
true if the bean fetcher should continue to retrieve the next bean; or

false if the retrieval should stop after this bean

Since:
1.0

getBeanInstance

public BeanType getBeanInstance()
Get the last processed bean instance

Returns:
the last processed bean instance
Since:
1.0

getCollectedInstances

public List<BeanType> getCollectedInstances()
Get the collected bean instances

Returns:
the collected bean instances
Since:
1.0


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.