org.jboss.cache.loader.bdbje
Class BdbjeCacheLoader

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

@ThreadSafe
public class BdbjeCacheLoader
extends AbstractCacheLoader

A persistent CacheLoader based on Berkeley DB Java Edition.

The configuration string format is:

environmentDirectoryName[#databaseName]

where databaseName, if omitted, defaults to the ClusterName property of the Cache.

A je.properties file may optionally be placed in the JE environment directory and used to customize the default JE configuration.

Version:
$Id: BdbjeCacheLoader.java 7218 2008-11-27 17:45:46Z manik.surtani@jboss.com $
Author:
Mark Hayes May 16, 2004, Bela Ban

Field Summary
 
Fields inherited from class org.jboss.cache.loader.AbstractCacheLoader
buddyFqnTransformer, cache, regionManager, transactions
 
Constructor Summary
BdbjeCacheLoader()
           
 
Method Summary
 void commit(Object tx)
          Commits the given transaction, or throws IllegalArgumentException if the given key is not associated with an uncommited transaction.
 void create()
          Does nothing since start() does all the work.
 boolean exists(Fqn name)
          Returns whether the given node exists.
 Map<Object,Object> get(Fqn name)
          Returns a map containing all key-value pairs for the given FQN, or null if the node is not present.
 Set<String> getChildrenNames(Fqn name)
          Returns an unmodifiable set of relative children names (strings), or returns null if the parent node is not found or if no children are found.
 CacheLoaderConfig.IndividualCacheLoaderConfig getConfig()
          Gets the configuration.
 void prepare(Object tx, List<Modification> modifications, boolean onePhase)
          Begins a transaction and applies the given modifications.
 void put(Fqn name, Map values)
          Stores a map of key-values for a given FQN, but does not delete existing key-value pairs (that is, it does not erase).
 Object put(Fqn name, Object key, Object value)
          Stores a single FQN-key-value record.
 void put(List<Modification> modifications)
          Applies the given modifications.
 void remove(Fqn name)
          Deletes the node for a given FQN and all its descendent nodes.
 Object remove(Fqn name, Object key)
          Deletes a single FQN-key-value record.
 void removeData(Fqn name)
          Clears the map for the given node, but does not remove the node.
 void rollback(Object tx)
          Commits the given transaction, or throws IllegalArgumentException if the given key is not associated with an uncommited transaction.
 void setCache(CacheSPI c)
          Sets the CacheImpl owner of this cache loader.
 void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
          Sets the configuration string for this cache loader.
 void start()
          Opens the JE environment and the database specified by the configuration string.
 void stop()
          Closes the JE databases and environment, and nulls references to them.
protected  void storeStateHelper(Fqn subtree, List nodeData, boolean moveToBuddy)
           
 
Methods inherited from class org.jboss.cache.loader.AbstractCacheLoader
destroy, doMarshall, doUnmarshall, getMarshaller, getNodeDataList, loadEntireState, loadState, loadStateHelper, move, put, regionAwareMarshall, regionAwareUnmarshall, setRegionManager, storeEntireState, storeState
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BdbjeCacheLoader

public BdbjeCacheLoader()
Method Detail

create

public void create()
            throws Exception
Does nothing since start() does all the work.

Specified by:
create in interface Lifecycle
Overrides:
create in class AbstractCacheLoader
Throws:
Exception

storeStateHelper

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

start

public void start()
           throws Exception
Opens the JE environment and the database specified by the configuration string. The environment and databases are created if necessary.

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

stop

public void stop()
Closes the JE databases and environment, and nulls references to them. The environment and databases are not removed from the file system. Exceptions during close are ignored.

Specified by:
stop in interface Lifecycle
Overrides:
stop in class AbstractCacheLoader

setConfig

public void setConfig(CacheLoaderConfig.IndividualCacheLoaderConfig base)
Sets the configuration string for this cache loader.

Parameters:
base - May be an instance of the CacheLoaderConfig.IndividualCacheLoaderConfig base class, in which case the cache loader should use the PluggableConfigurationComponent.getProperties() method to find configuration information. Alternatively, may be a type-specific subclass of CacheLoaderConfig.IndividualCacheLoaderConfig, if there is one.

getConfig

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

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

setCache

public void setCache(CacheSPI c)
Sets the CacheImpl owner of this cache loader.

Specified by:
setCache in interface CacheLoader
Overrides:
setCache in class AbstractCacheLoader
Parameters:
c - The cache on which this loader works

getChildrenNames

public Set<String> getChildrenNames(Fqn name)
                             throws Exception
Returns an unmodifiable set of relative children names (strings), or returns null if the parent node is not found or if no children are found. This is a fairly expensive operation, and is assumed to be performed by browser applications. Calling this method as part of a run-time transaction is not recommended.

Parameters:
name - The Fqn of the parent
Returns:
Set a set of children. Returns null if no children nodes are present, or the parent is not present
Throws:
Exception

get

public Map<Object,Object> get(Fqn name)
                       throws Exception
Returns a map containing all key-value pairs for the given FQN, or null if the node is not present. This operation is always non-transactional, even in a transactional environment.

Parameters:
name - the Fqn to search for.
Returns:
Map keys and values for the given node. Returns null if the node is not found. If the node is found but has no attributes, this method returns an empty Map.
Throws:
Exception

exists

public boolean exists(Fqn name)
               throws Exception
Returns whether the given node exists.

Returns:
true if node exists, false otherwise
Throws:
Exception

put

public Object put(Fqn name,
                  Object key,
                  Object value)
           throws Exception
Stores a single FQN-key-value record. Intended to be used in a non-transactional environment, but will use auto-commit in a transactional environment.

Throws:
Exception

put

public void put(Fqn name,
                Map values)
         throws Exception
Stores a map of key-values for a given FQN, but does not delete existing key-value pairs (that is, it does not erase). Intended to be used in a non-transactional environment, but will use auto-commit in a transactional environment.

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

put

public void put(List<Modification> modifications)
         throws Exception
Applies the given modifications. Intended to be used in a non-transactional environment, but will use auto-commit in a transactional environment.

Specified by:
put in interface CacheLoader
Overrides:
put in class AbstractCacheLoader
Parameters:
modifications - A List of modifications
Throws:
Exception

remove

public void remove(Fqn name)
            throws Exception
Deletes the node for a given FQN and all its descendent nodes. Intended to be used in a non-transactional environment, but will use auto-commit in a transactional environment.

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

remove

public Object remove(Fqn name,
                     Object key)
              throws Exception
Deletes a single FQN-key-value record. Intended to be used in a non-transactional environment, but will use auto-commit in a transactional environment.

Throws:
Exception

removeData

public void removeData(Fqn name)
                throws Exception
Clears the map for the given node, but does not remove the node.

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

prepare

public void prepare(Object tx,
                    List<Modification> modifications,
                    boolean onePhase)
             throws Exception
Begins a transaction and applies the given modifications.

If onePhase is true, commits the transaction; otherwise, associates the txn value with the transaction and expects commit() or rollback() to be called later with the same tx value. Performs retries if necessary to resolve deadlocks.

Specified by:
prepare in interface CacheLoader
Overrides:
prepare in class AbstractCacheLoader
Parameters:
tx - The transaction, indended to be used by implementations as an identifier of the transaction (and not necessarily a JTA Transaction object)
modifications - A List containing Modifications, for the given transaction
onePhase - Persist immediately and (for example) commit the local JDBC transaction as well. When true, we won't get a CacheLoader.commit(Object) or CacheLoader.rollback(Object) method call later
Throws:
Exception

commit

public void commit(Object tx)
            throws Exception
Commits the given transaction, or throws IllegalArgumentException if the given key is not associated with an uncommited transaction.

Specified by:
commit in interface CacheLoader
Overrides:
commit in class AbstractCacheLoader
Parameters:
tx - transaction to commit
Throws:
Exception

rollback

public void rollback(Object tx)
Commits the given transaction, or throws IllegalArgumentException if the given key is not associated with an uncommited transaction.

Specified by:
rollback in interface CacheLoader
Overrides:
rollback in class AbstractCacheLoader
Parameters:
tx - transaction to roll back


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