The Carbon Java Framework  

The Sql Bean Dataloader Module

Sql Bean Dataloader Usage

Author: Jordan Reed (jreed at sapient.com)
Version: $Revision: 1.1 $($Author: jdreed $ / $Date: 2003/10/29 18:32:46 $)
Created: October 2003

Overview

This module provides implementations for cache service dataloaders that can be used to cache information from jdbc queries into simple java bean objects.

Setup

Using the sql bean dataloader requires the following steps:

  1. Create a Java bean to store the data in cache
  2. Create a configuration file

Create a Java bean to store the data in cache

This java bean is the representation of the database information that will be stored in memory. The dataloader will load information from the database into instances of this object and store them int the cache.

Example of a Sql Dataloader Java Bean

public class TwoColumnBeanTest {
    public TwoColumnBeanTest() {
    }

    private BigDecimal key;
    private String value;

    public BigDecimal getKey() {
        return this.key;
    }

    public void setKey(BigDecimal key) {
        this.key = key;
    }

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}

Create a configuration file

The configuration file for the dataloader is used to describe what information is to be loaded from the database and where to put that inside the java bean.

<Configuration
  ConfigurationInterface="org.sape.carbon.services.cache.total.TotalCacheConfiguration">

    <FunctionalImplementationClass>org.sape.carbon.services.cache.total.ReadOnlyCache</FunctionalImplementationClass>
    <FunctionalInterface>org.sape.carbon.services.cache.Cache</FunctionalInterface>

    <DataLoader ConfigurationInterface="org.sape.carbon.services.cache.total.dataloader.SqlBeanDataLoaderConfiguration">

         <FunctionalInterface>org.sape.carbon.services.cache.total.dataloader.ConfigurableMapTypeCacheDataLoader</FunctionalInterface>
         <FunctionalImplementationClass>org.sape.carbon.services.cache.total.dataloader.SqlBeanDataLoader</FunctionalImplementationClass>

          <!-- MANDATORY. Refer to the connection factory component configuration here -->
         <ConnectionFactory>ref:///sql/connection/test/StandaloneConnectionFactory</ConnectionFactory>

          <!-- OPTIONAL. Configure the map implmentation to be used. if not provided, it is defaulted to java.util.HashMap-->
         <MapType>java.util.TreeMap</MapType>

          <!-- OPTIONAL. Configure the comparator implementation you want to use with the
         respective map implementation. Please note that the map implementation should have constructor available
         for using comparator, otherwise this will throw an InvalidConfigurationException.--> 
         <Comparator>org.sape.carbon.services.cache.total.dataloader.test.Comparatortest</Comparator>

          <!-- MANDATORY. Define your SQL query in the tag. The order of columns selected
         does not matter. The sequence of results is maintained if appropriate map implementation is chosen. --> 
         <DataLoadQuery>Select KEY_COLUMN, VALUE_COLUMN from EJFW_BEAN_DATA order by KEY_COLUMN</DataLoadQuery>

          <!-- MANDATORY. Defines the bean that will be returned as a value from the map.
         You need to create a java bean with appropriate accessors and mutators for atributes defined in
         BeanAttribute.
         mapping --> 
         <BeanClass>org.sape.carbon.services.cache.total.dataloader.test.TwoColumnBeanTest</BeanClass>

          <!-- MANDATORY. Defines the column name of the table that provides the key for the
         map. Please note that this is case sensitive. So, should be written in CAPS --> 
         <KeyColumn>KEY_COLUMN</KeyColumn>

          <!-- MANDATORY. Defines the mapping between the column name and bean property.--> 
         <BeanAttributeMap>
             <BeanAttribute Key="KEY_COLUMN">key</BeanAttribute>
             <BeanAttribute Key="VALUE_COLUMN">value</BeanAttribute>
         </BeanAttributeMap>

    </DataLoader>

</Configuration>

Copyright © 2001-2003, Sapient Corporation