org.sape.carbon.services.sqldataloader.total
Class SqlBeanDataLoader

java.lang.Object
  |
  +--org.sape.carbon.services.sqldataloader.total.SqlBeanDataLoader
All Implemented Interfaces:
Configurable, ConfigurableMapTypeCacheDataLoader, FunctionalInterface, TotalCacheDataLoader

public class SqlBeanDataLoader
extends Object
implements ConfigurableMapTypeCacheDataLoader, Configurable

Class provides a generic lookup class to users with a mechanism to cache data retreived from a table. The object containing the data, query retreiving the data and the key for the cache are all configurable propertied read from the component configuration file.

It reads the data from database using the configured query and loads it into Javabean objects which are then stored in cache.

Since:
carbon 2.1
Version:
$Revision: 1.1 $($Author: ghinkl $ / $Date: 2003/09/30 02:08:19 $)
Author:
Akash Tayal, May 2003
See Also:
Copyright 2003 Sapient

Field Summary
protected  SqlBeanDataLoaderConfiguration config
          Reference to configuration document
private  org.apache.commons.logging.Log log
          The handle to Apache-commons logger
 
Constructor Summary
SqlBeanDataLoader()
           
 
Method Summary
 void configure(ComponentConfiguration configuration)
          Configure the component.
 Map getMapInstance()
          Returns an instance of configured map implementation.
 Map loadAllData()
          Loads the cache with data elements.
protected  ResultSet retrieveResult(Connection connection)
          Creates and executes the PreparedStatement to retrieve data from database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private org.apache.commons.logging.Log log
The handle to Apache-commons logger


config

protected SqlBeanDataLoaderConfiguration config
Reference to configuration document

Constructor Detail

SqlBeanDataLoader

public SqlBeanDataLoader()
Method Detail

configure

public void configure(ComponentConfiguration configuration)
Configure the component. This is preceded and followed by the suspend and resume operations if they are available on the component.

Specified by:
configure in interface Configurable
Parameters:
configuration - A GenericTotalCacheDataLoaderConfiguration

retrieveResult

protected ResultSet retrieveResult(Connection connection)
                            throws SQLException

Creates and executes the PreparedStatement to retrieve data from database. This method abstracts out the creation and execution of SQL statement.

You can extend this class and provide implementation for this method in case you want to retrieve data using callable statement.

Parameters:
connection - Connection to the database
Returns:
ResultSet of retrieved data
Throws:
CacheLoadException - in case there is some error in loading the data
SQLException

loadAllData

public Map loadAllData()
                throws CacheLoadException

Loads the cache with data elements. Executes the configured SQL query and loads the data into configured bean.

Reads the configuration to retrieve a map of db columns and bean attributes. Reads the value for each column from database and populates it into the mapping bean attributes.

Specified by:
loadAllData in interface TotalCacheDataLoader
Returns:
Map of cached data
Throws:
CacheLoadException - in case there is some error in loading the data

getMapInstance

public Map getMapInstance()

Returns an instance of configured map implementation. This method just returns a new and blank instance. In case comparator is defined for the map, the appropriate constructor of the map implementation is used to create the new instance.

Please note that the new map instance is not synchronized in this method. As required the synchronization takes place in the WritableCache

Specified by:
getMapInstance in interface ConfigurableMapTypeCacheDataLoader
Returns:
Map instance


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.