org.sape.carbon.services.sqldataloader.mru
Class SqlBeanMapMRUDataLoader

java.lang.Object
  |
  +--org.sape.carbon.services.sqldataloader.mru.SqlBeanMapMRUDataLoader
All Implemented Interfaces:
Configurable, FunctionalInterface, MRUCacheDataLoader

public class SqlBeanMapMRUDataLoader
extends Object
implements MRUCacheDataLoader, Configurable

Class provides a generic lookup class to users with a mechanism to cache data retreived from a table. The map implementation and object containing the data and the query retreiving the data 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 loaded into a map 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  SqlBeanMapMRUDataLoaderConfiguration config
          Reference to configuration document
private  org.apache.commons.logging.Log log
          The handle to Apache-commons logger
 
Constructor Summary
SqlBeanMapMRUDataLoader()
           
 
Method Summary
 void configure(ComponentConfiguration configuration)
          Configure the component.
protected  Map getMapInstance()
          Returns an instance of configured map implementation.
 Object loadDatum(Object key)
          Loads the Object corresponding to the particular key supplied.
protected  ResultSet retrieveResult(Connection connection, Object key)
          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 SqlBeanMapMRUDataLoaderConfiguration config
Reference to configuration document

Constructor Detail

SqlBeanMapMRUDataLoader

public SqlBeanMapMRUDataLoader()
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,
                                   Object key)
                            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
key - represents key acting as a filter to retrieve data from db
Returns:
ResultSet of retrieved data
Throws:
SQLException - in case there is some error in loading the data

loadDatum

public Object loadDatum(Object key)
                 throws CacheLoadException

Loads the Object corresponding to the particular key supplied. Executes the configured SQL query, loads the data into configured map implementation and returns the loaded map

Reads data from database into configured java bean and stores the bean in the map implementation configured. This map is returned by the method as a value to the cache.

Specified by:
loadDatum in interface MRUCacheDataLoader
Parameters:
key - that identifies the returned object in the cache
Returns:
Object contains map of data
Throws:
CacheLoadException - in case there is some error in loading the data

getMapInstance

protected 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.

Returns:
Map instance


Copyright 1999-2003 Sapient Corporation. All Rights Reserved.