Package rife.database
Class DbBeanFetcher<BeanType>
java.lang.Object
rife.database.DbRowProcessor
rife.database.DbBeanFetcher<BeanType>
- All Implemented Interfaces:
Cloneable
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 Summary
ConstructorDescriptionDbBeanFetcher
(Datasource datasource, Class<BeanType> beanClass) Create a new DbBeanFetcherDbBeanFetcher
(Datasource datasource, Class<BeanType> beanClass, boolean collectInstances) Create a new DbBeanFetcher -
Method Summary
Modifier and TypeMethodDescriptionGet the last processed bean instanceGet the collected bean instancesboolean
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 rife.database.DbRowProcessor
clone, wasSuccessful
-
Constructor Details
-
DbBeanFetcher
Create a new DbBeanFetcher- Parameters:
datasource
- the datasource to be usedbeanClass
- 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 usedbeanClass
- the type of bean that will be handledcollectInstances
-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
Process a ResultSet row into a bean. Call this method on aResultSet
and the resulting bean will be stored and be accessible viagetBeanInstance()
- Specified by:
processRow
in classDbRowProcessor
- Parameters:
resultSet
- theResultSet
from which to process the row- Returns:
true
if a bean instance was retrieved; orfalse
if otherwise- Throws:
SQLException
- thrown when there is a problem processing the row- See Also:
-
gotBeanInstance
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; orfalse
if the retrieval should stop after this bean- Since:
- 1.0
-
getBeanInstance
Get the last processed bean instance- Returns:
- the last processed bean instance
- Since:
- 1.0
-
getCollectedInstances
Get the collected bean instances- Returns:
- the collected bean instances
- Since:
- 1.0
-