Package rife.database

Class DbBeanFetcher<BeanType>

java.lang.Object
rife.database.DbRowProcessor
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
  • Constructor Details

    • 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 collect 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 Details

    • 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:
    • 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