org.jboss.cache.loader
Class JDBCCacheLoader

java.lang.Object
  extended by org.jboss.cache.loader.AbstractCacheLoader
      extended by org.jboss.cache.loader.AdjListJDBCCacheLoader
          extended by org.jboss.cache.loader.JDBCCacheLoader
All Implemented Interfaces:
Lifecycle, CacheLoader

@ThreadSafe
public class JDBCCacheLoader
extends AdjListJDBCCacheLoader

JDBC implementation of AdjListJDBCCacheLoader. Represents a faster alternative than JDBCCacheLoaderOld and relies on the same database structrure. It is backward compatible with data created by existing JDBCCacheLoaderOld implemetation. All configuration elements described there JDBCCacheLoaderOld also apply for this implementation.

Additional configuration info:

Version:
1.0
Author:
Mircea.Markus@iquestint.com, Galder Zamarreno

Field Summary
 
Fields inherited from class org.jboss.cache.loader.AdjListJDBCCacheLoader
cf, driverName, lock, NULL_NODE_IN_ROW
 
Fields inherited from class org.jboss.cache.loader.AbstractCacheLoader
buddyFqnTransformer, cache, regionManager, transactions
 
Constructor Summary
JDBCCacheLoader()
           
 
Method Summary
 CacheLoaderConfig.IndividualCacheLoaderConfig getConfig()
          Gets the configuration.
protected  org.apache.commons.logging.Log getLogger()
           
 int getNodeCount()
          Returns a number representing the count of persisted children.
protected  void getNodeDataList(Fqn fqn, List<NodeData> list)
          Subscribes to contract.
protected  AdjListJDBCCacheLoaderConfig processConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
          Builds a AdjListJDBCCacheLoaderConfig based on the supplied base config.
 void put(Fqn name, Map attributes)
          As per interface's contract.
 Object put(Fqn name, Object key, Object value)
          As per interface's contract.
 void remove(Fqn fqn)
          As per interface's contrect.
 void start()
          Start is overwritten for the sake of backward compatibility only.
 void storeState(Fqn subtree, ObjectInputStream in)
          Stores the given portion of the cache tree's state in secondary storage.
protected  void storeStateHelper(Fqn subtree, List nodeData, boolean moveToBuddy)
           
 
Methods inherited from class org.jboss.cache.loader.AdjListJDBCCacheLoader
commit, exists, get, getChildrenNames, getDriverName, insertNode, loadNode, marshall, populatePreparedStatementForInsert, prepare, prepareAndLogStatement, remove, removeData, reportAndRethrowError, rollback, safeClose, safeClose, safeClose, setConfig, stop, tableExists, unmarshall, updateNode
 
Methods inherited from class org.jboss.cache.loader.AbstractCacheLoader
create, destroy, doMarshall, doUnmarshall, getMarshaller, loadEntireState, loadState, loadStateHelper, move, put, put, regionAwareMarshall, regionAwareUnmarshall, setCache, setRegionManager, storeEntireState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JDBCCacheLoader

public JDBCCacheLoader()
Method Detail

processConfig

protected AdjListJDBCCacheLoaderConfig processConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
Builds a AdjListJDBCCacheLoaderConfig based on the supplied base config.

Specified by:
processConfig in class AdjListJDBCCacheLoader

put

public Object put(Fqn name,
                  Object key,
                  Object value)
           throws Exception
As per interface's contract. Performance Note: Optimised O(nodeDepth) db calls.

Throws:
Exception

put

public void put(Fqn name,
                Map attributes)
         throws Exception
As per interface's contract. Performance Note: Optimised O(nodeDepth) db calls.

Parameters:
name - The fully qualified name of the node
attributes - A Map of attributes. Can be null
Throws:
Exception

storeStateHelper

protected void storeStateHelper(Fqn subtree,
                                List nodeData,
                                boolean moveToBuddy)
                         throws Exception
Overrides:
storeStateHelper in class AbstractCacheLoader
Throws:
Exception

remove

public void remove(Fqn fqn)
            throws Exception
As per interface's contrect. Performance Note: O(1) db calls.

Parameters:
fqn - the Fqn of the node
Throws:
Exception

getNodeDataList

protected void getNodeDataList(Fqn fqn,
                               List<NodeData> list)
                        throws Exception
Subscribes to contract. Performance Note: O(2) db calls.

Overrides:
getNodeDataList in class AbstractCacheLoader
Throws:
Exception

getLogger

protected org.apache.commons.logging.Log getLogger()
Specified by:
getLogger in class AdjListJDBCCacheLoader

start

public void start()
           throws Exception
Start is overwritten for the sake of backward compatibility only. Here is the issue: old implementation does not create a Fqn.ROOT if not specifically told so. As per put's contract, when calling put('/a/b/c', 'key', 'value') all parent nodes should be created up to root. Root is not created, though. The compatibility problem comes in the case of loade ENTIRE state. The implementation checks node's existence firstly, and based on that continues or not. As root is not persisted nothing is loaded etc.

Specified by:
start in interface Lifecycle
Overrides:
start in class AdjListJDBCCacheLoader
Throws:
Exception

getNodeCount

public int getNodeCount()
                 throws Exception
Returns a number representing the count of persisted children.

Throws:
Exception

storeState

public void storeState(Fqn subtree,
                       ObjectInputStream in)
                throws Exception
Description copied from interface: CacheLoader
Stores the given portion of the cache tree's state in secondary storage. Overwrite whatever is currently in secondary storage. If the transferred state has Fqns equal to or children of parameter subtree, then no special behavior is required. Otherwise, ensure that the state is integrated under the given subtree. Typically in the latter case subtree would be the Fqn of the buddy backup region for a buddy group; e.g.

If the the transferred state had Fqns starting with "/a" and subtree was "/_BUDDY_BACKUP_/192.168.1.2:5555" then the state should be stored in the local persistent store under "/_BUDDY_BACKUP_/192.168.1.2:5555/a"

Implementations of this method should not catch any exception or close the given ObjectInputStream parameter. In order to ensure cacheloader interoperability contents of the cache are read from the ObjectInputStream as a sequence of NodeData objects.

Default implementation is provided by AbstractCacheLoader and ensures cacheloader interoperability. Implementors are encouraged to consider extending AbstractCacheLoader prior to implementing completely custom cacheloader.

Specified by:
storeState in interface CacheLoader
Overrides:
storeState in class AbstractCacheLoader
Parameters:
subtree - Fqn naming the root (i.e. highest level parent) node of the subtree included in state. If the Fqns of the data included in state are not already children of subtree, then their Fqns should be altered to make them children of subtree before they are persisted.
in - ObjectInputStream to read state
Throws:
Exception
See Also:
AbstractCacheLoader.storeState(Fqn,ObjectInputStream), NodeData

getConfig

public CacheLoaderConfig.IndividualCacheLoaderConfig getConfig()
Description copied from interface: CacheLoader
Gets the configuration.

Returns:
the configuration, represented by a CacheLoaderConfig.IndividualCacheLoaderConfig object.


Copyright © 2009 JBoss, a division of Red Hat. All Rights Reserved.