org.jboss.cache.loader.bdbje
Class BdbjeCacheLoader

java.lang.Object
  extended byorg.jboss.cache.loader.bdbje.BdbjeCacheLoader
All Implemented Interfaces:
CacheLoader (src) , Service (src)

public class BdbjeCacheLoader
extends java.lang.Object
implements CacheLoader (src)

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

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


Constructor Summary
BdbjeCacheLoader()
           
 
Method Summary
 void commit(java.lang.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.
 void destroy()
          Does nothing since stop() does all the work.
 boolean exists(Fqn (src)  name)
          Returns whether the given node exists.
 java.util.Map get(Fqn (src)  name)
          Returns a map containing all key-value pairs for the given FQN, or null if the node is not present.
 java.lang.Object get(Fqn (src)  name, java.lang.Object key)
          Returns the data object stored under the given FQN and key, or null if the FQN and key are not present.
 java.util.Set getChildrenNames(Fqn (src)  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.
 byte[] loadEntireState()
          Export the contents of the databases as a byte array.
 void prepare(java.lang.Object tx, java.util.List modifications, boolean onePhase)
          Begins a transaction and applies the given modifications.
 void put(Fqn (src)  name, java.util.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).
 java.lang.Object put(Fqn (src)  name, java.lang.Object key, java.lang.Object value)
          Stores a single FQN-key-value record.
 void put(java.util.List modifications)
          Applies the given modifications.
 void remove(Fqn (src)  name)
          Deletes the node for a given FQN and all its descendent nodes.
 java.lang.Object remove(Fqn (src)  name, java.lang.Object key)
          Deletes a single FQN-key-value record.
 void removeData(Fqn (src)  name)
          Clears the map for the given node, but does not remove the node.
 void rollback(java.lang.Object tx)
          Commits the given transaction, or throws IllegalArgumentException if the given key is not associated with an uncommited transaction.
 void setCache(TreeCache (src)  c)
          Sets the TreeCache owner of this cache loader.
 void setConfig(java.util.Properties props)
          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.
 void storeEntireState(byte[] state)
          Replace the contents of the databases with the given exported data.
 
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 java.lang.Exception
Does nothing since start() does all the work.

Specified by:
create in interface Service (src)
Throws:
java.lang.Exception

destroy

public void destroy()
Does nothing since stop() does all the work.

Specified by:
destroy in interface Service (src)

start

public void start()
           throws java.lang.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 Service (src)
Throws:
java.lang.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 Service (src)

setConfig

public void setConfig(java.util.Properties props)
Sets the configuration string for this cache loader.

Specified by:
setConfig in interface CacheLoader (src)
Parameters:
props - A list of properties, defined in the XML file

setCache

public void setCache(TreeCache (src)  c)
Sets the TreeCache owner of this cache loader.

Specified by:
setCache in interface CacheLoader (src)
Parameters:
c - The cache on which this loader works

getChildrenNames

public java.util.Set getChildrenNames(Fqn (src)  name)
                               throws java.lang.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.

Specified by:
getChildrenNames in interface CacheLoader (src)
Parameters:
name - The FQN of the parent
Returns:
Set. A list of children. Returns null if no children nodes are present, or the parent is not present
Throws:
java.lang.Exception

get

public java.util.Map get(Fqn (src)  name)
                  throws java.lang.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.

Specified by:
get in interface CacheLoader (src)
Parameters:
name -
Returns:
Map of keys and values for the given node. Returns null if the node was not found, or if the node has no attributes
Throws:
java.lang.Exception

get

public java.lang.Object get(Fqn (src)  name,
                            java.lang.Object key)
                     throws java.lang.Exception
Returns the data object stored under the given FQN and key, or null if the FQN and key are not present. This operation is always non-transactional, even in a transactional environment.

Specified by:
get in interface CacheLoader (src)
Parameters:
name -
Returns:
Throws:
java.lang.Exception

exists

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

Specified by:
exists in interface CacheLoader (src)
Parameters:
name -
Returns:
True if node exists, false otherwise
Throws:
java.lang.Exception

put

public java.lang.Object put(Fqn (src)  name,
                            java.lang.Object key,
                            java.lang.Object value)
                     throws java.lang.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.

Specified by:
put in interface CacheLoader (src)
Throws:
java.lang.Exception

put

public void put(Fqn (src)  name,
                java.util.Map values)
         throws java.lang.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.

Specified by:
put in interface CacheLoader (src)
Parameters:
name - The fully qualified name of the node
values - A Map of attributes. Can be null
Throws:
java.lang.Exception

put

public void put(java.util.List modifications)
         throws java.lang.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 (src)
Parameters:
modifications - A List of modifications
Throws:
java.lang.Exception

remove

public void remove(Fqn (src)  name)
            throws java.lang.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.

Specified by:
remove in interface CacheLoader (src)
Throws:
java.lang.Exception

remove

public java.lang.Object remove(Fqn (src)  name,
                               java.lang.Object key)
                        throws java.lang.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.

Specified by:
remove in interface CacheLoader (src)
Throws:
java.lang.Exception

removeData

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

Specified by:
removeData in interface CacheLoader (src)
Parameters:
name -
Throws:
java.lang.Exception

prepare

public void prepare(java.lang.Object tx,
                    java.util.List modifications,
                    boolean onePhase)
             throws java.lang.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 (src)
Parameters:
tx - The transaction, just used as a hashmap key
modifications - List, a list of all modifications within 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:
java.lang.Exception

commit

public void commit(java.lang.Object tx)
            throws java.lang.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 (src)
Parameters:
tx -
Throws:
java.lang.Exception

rollback

public void rollback(java.lang.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 (src)
Parameters:
tx -

loadEntireState

public byte[] loadEntireState()
                       throws java.lang.Exception
Export the contents of the databases as a byte array. If the databases are empty a zero-lenth array is returned. The export format is two consecutive DbDumps.

Specified by:
loadEntireState in interface CacheLoader (src)
Throws:
java.lang.Exception

storeEntireState

public void storeEntireState(byte[] state)
                      throws java.lang.Exception
Replace the contents of the databases with the given exported data. If state is null or zero-length, the databases will be cleared. The export format is two consecutive DbDumps.

Specified by:
storeEntireState in interface CacheLoader (src)
Throws:
java.lang.Exception