org.jboss.cache.loader
Class JDBCCacheLoader

java.lang.Object
  extended by org.jboss.cache.loader.JDBCCacheLoader
All Implemented Interfaces:
CacheLoader, org.jboss.system.Service
Direct Known Subclasses:
JDBCExtendedCacheLoader

public class JDBCCacheLoader
extends java.lang.Object
implements CacheLoader

JDBC CacheLoader implementation.

This implementation uses one table. The table consists of three columns:

The configuration options are:

Table configuration

DataSource configuration

JDBC driver configuration (used when DataSource is not configured)

Version:
$Revision: 1.11 $
Author:
Alexey Loubyansky, Hany Mesha

Constructor Summary
JDBCCacheLoader()
           
 
Method Summary
 void commit(java.lang.Object tx)
          Commits a transaction.
 void create()
           
 void destroy()
           
 boolean exists(Fqn name)
          Checks that there is a row for the fqn in the database.
 java.util.Map get(Fqn name)
          Returns a map representing a node.
 java.util.Set getChildrenNames(Fqn fqn)
          Fetches child node names (not pathes).
 byte[] loadEntireState()
          Loads the entire state from the filesystem and returns it as a byte buffer.
protected  void loadState(Fqn fqn, java.io.ObjectOutputStream out)
          Do a preorder traversal: visit the node first, then the node's children
 void prepare(java.lang.Object tx, java.util.List modifications, boolean one_phase)
          First phase in transaction commit process.
 void put(Fqn name, java.util.Map attributes)
          Adds attributes from the passed in map to the existing node.
 java.lang.Object put(Fqn name, java.lang.Object key, java.lang.Object value)
          Adds/overrides a value in a node for a key.
 void put(java.util.List modifications)
          Applies all modifications to the backend store.
 void remove(Fqn name)
          Removes a node and all its children.
 java.lang.Object remove(Fqn name, java.lang.Object key)
          Removes attribute's value for a key.
 void removeData(Fqn name)
          Nullifies the node.
 void rollback(java.lang.Object tx)
          Rolls back a transaction.
 void setCache(TreeCache c)
          Sets the TreeCache that is maintaining this CacheLoader.
 void setConfig(java.util.Properties props)
          Sets the configuration.
 void start()
           
 void stop()
           
 void storeEntireState(byte[] state)
          Store the state given as a byte buffer to the database.
 
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

setConfig

public void setConfig(java.util.Properties props)
Description copied from interface: CacheLoader
Sets the configuration. This is called before Service.create() and Service.start().

Specified by:
setConfig in interface CacheLoader
Parameters:
props - a collection of configuration properties

setCache

public void setCache(TreeCache c)
Description copied from interface: CacheLoader
Sets the TreeCache that is maintaining this CacheLoader. This method allows this CacheLoader to invoke methods on TreeCache, including fetching additional configuration information. This method is called be called after the CacheLoader instance has been constructed.

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

getChildrenNames

public java.util.Set getChildrenNames(Fqn fqn)
                               throws java.lang.Exception
Fetches child node names (not pathes).

Specified by:
getChildrenNames in interface CacheLoader
Parameters:
fqn - parent fqn
Returns:
a set of child node names or null if there are not children found for the fqn
Throws:
java.lang.Exception

get

public java.util.Map get(Fqn name)
                  throws java.lang.Exception
Returns a map representing a node.

Specified by:
get in interface CacheLoader
Parameters:
name - node's fqn
Returns:
node
Throws:
java.lang.Exception

exists

public boolean exists(Fqn name)
               throws java.lang.Exception
Checks that there is a row for the fqn in the database.

Specified by:
exists in interface CacheLoader
Parameters:
name - node's fqn
Returns:
true if there is a row in the database for the given fqn even if the node column is null.
Throws:
java.lang.Exception

put

public java.lang.Object put(Fqn name,
                            java.lang.Object key,
                            java.lang.Object value)
                     throws java.lang.Exception
Adds/overrides a value in a node for a key. If the node does not exist yet, the node will be created. If parent nodes do not exist for the node, empty parent nodes will be created.

Specified by:
put in interface CacheLoader
Parameters:
name - node's fqn
key - attribute's key
value - attribute's value
Returns:
old value associated with the attribute's key or null if there was no value previously associated with the attribute's key
Throws:
java.lang.Exception

put

public void put(Fqn name,
                java.util.Map attributes)
         throws java.lang.Exception
Adds attributes from the passed in map to the existing node. If there is no node for the fqn, a new node will be created.

Specified by:
put in interface CacheLoader
Parameters:
name - node's fqn
attributes - attributes
Throws:
java.lang.Exception

put

public void put(java.util.List modifications)
         throws java.lang.Exception
Description copied from interface: CacheLoader
Applies all modifications to the backend store. Changes may be applied in a single operation.

Specified by:
put in interface CacheLoader
Parameters:
modifications - A List of modifications
Throws:
java.lang.Exception

remove

public java.lang.Object remove(Fqn name,
                               java.lang.Object key)
                        throws java.lang.Exception
Removes attribute's value for a key. If after removal the node contains no attributes, the node is nullified.

Specified by:
remove in interface CacheLoader
Parameters:
name - node's name
key - attribute's key
Returns:
removed value or null if there was no value for the passed in key
Throws:
java.lang.Exception

remove

public void remove(Fqn name)
            throws java.lang.Exception
Removes a node and all its children. Uses the same connection for all the db work.

Specified by:
remove in interface CacheLoader
Parameters:
name - node's fqn
Throws:
java.lang.Exception

removeData

public void removeData(Fqn name)
                throws java.lang.Exception
Nullifies the node.

Specified by:
removeData in interface CacheLoader
Parameters:
name - node's fqn
Throws:
java.lang.Exception

prepare

public void prepare(java.lang.Object tx,
                    java.util.List modifications,
                    boolean one_phase)
             throws java.lang.Exception
First phase in transaction commit process. The changes are committed if only one phase if requested. All the modifications are committed using the same connection.

Specified by:
prepare in interface CacheLoader
Parameters:
tx - something representing transaction
modifications - a list of modifications
one_phase - indicates whether it's one or two phase commit transaction
Throws:
java.lang.Exception

commit

public void commit(java.lang.Object tx)
            throws java.lang.Exception
Commits a transaction.

Specified by:
commit in interface CacheLoader
Parameters:
tx - the tx to commit
Throws:
java.lang.Exception

rollback

public void rollback(java.lang.Object tx)
Rolls back a transaction.

Specified by:
rollback in interface CacheLoader
Parameters:
tx - the tx to rollback

loadEntireState

public byte[] loadEntireState()
                       throws java.lang.Exception
Loads the entire state from the filesystem and returns it as a byte buffer. The format of the byte buffer must be a list of NodeData elements

Specified by:
loadEntireState in interface CacheLoader
Returns:
Throws:
java.lang.Exception

storeEntireState

public void storeEntireState(byte[] state)
                      throws java.lang.Exception
Store the state given as a byte buffer to the database. The byte buffer contains a list of zero or more NodeData elements

Specified by:
storeEntireState in interface CacheLoader
Parameters:
state -
Throws:
java.lang.Exception

create

public void create()
            throws java.lang.Exception
Specified by:
create in interface org.jboss.system.Service
Throws:
java.lang.Exception

start

public void start()
           throws java.lang.Exception
Specified by:
start in interface org.jboss.system.Service
Throws:
java.lang.Exception

stop

public void stop()
Specified by:
stop in interface org.jboss.system.Service

destroy

public void destroy()
Specified by:
destroy in interface org.jboss.system.Service

loadState

protected void loadState(Fqn fqn,
                         java.io.ObjectOutputStream out)
                  throws java.lang.Exception
Do a preorder traversal: visit the node first, then the node's children

Parameters:
fqn - Start node
out -
Throws:
java.lang.Exception


Copyright 1998-2005 JBoss Inc . All Rights Reserved.