org.jboss.cache.loader
Class JDBCCacheLoader

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

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

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)


Constructor Summary
JDBCCacheLoader()
           
 
Method Summary
 void commit(java.lang.Object tx)
          Commits a transaction.
 void create()
          create the service, do expensive operations etc
 void destroy()
          destroy the service, tear down
 boolean exists(Fqn (src)  name)
          Checks that there is a row for the fqn in the database.
 java.util.Map get(Fqn (src)  name)
          Returns a map representing a node.
 java.lang.Object get(Fqn (src)  name, java.lang.Object key)
          Loads an attribute from the database.
 java.util.Set getChildrenNames(Fqn (src)  fqn)
          Fetches child node names (not pathes).
 byte[] loadEntireState()
          Loads the entire state from the filesystem and returns it as a byte buffer.
 void prepare(java.lang.Object tx, java.util.List modifications, boolean one_phase)
          First phase in transaction commit process.
 void put(Fqn (src)  name, java.util.Map attributes)
          Adds attributes from the passed in map to the existing node.
 java.lang.Object put(Fqn (src)  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)
          Inserts all modifications to the backend store.
 void remove(Fqn (src)  name)
          Removes a node and all its children.
 java.lang.Object remove(Fqn (src)  name, java.lang.Object key)
          Removes attribute's value for a key.
 void removeData(Fqn (src)  name)
          Nullifies the node.
 void rollback(java.lang.Object tx)
          Rolls back a transaction.
 void setCache(TreeCache (src)  c)
          This method allows the CacheLoader to set the TreeCache, therefore allowing the CacheLoader to invoke methods of the TreeCache.
 void setConfig(java.util.Properties props)
          Sets the configuration.
 void start()
          start the service, create is already called
 void stop()
          stop the service
 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 (src)
Sets the configuration. Will be called before Service.create() and Service.start()

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)
Description copied from interface: CacheLoader (src)
This method allows the CacheLoader to set the TreeCache, therefore allowing the CacheLoader to invoke methods of the TreeCache. It can also use the TreeCache to fetch configuration information. Alternatively, the CacheLoader could maintain its own configuration
This method will be called directly after the CacheLoader instance has been created

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

getChildrenNames

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

Specified by:
getChildrenNames in interface CacheLoader (src)
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.lang.Object get(Fqn (src)  name,
                            java.lang.Object key)
                     throws java.lang.Exception
Loads an attribute from the database.

Specified by:
get in interface CacheLoader (src)
Parameters:
name - node's fqn
key - attribute's key
Returns:
attribute's value. Null is returned if
  • there is no value for the attribute key in the node
  • there is a row in the table for the fqn but the node column contains null
  • there is no row in table for the fqn (should this result in an exception?)
Throws:
java.lang.Exception

get

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

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

exists

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

Specified by:
exists in interface CacheLoader (src)
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 (src)  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 (src)
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 (src)  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 (src)
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 (src)
Inserts all modifications to the backend store. Overwrite whatever is already in the datastore.

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

remove

public java.lang.Object remove(Fqn (src)  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 (src)
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 (src)  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 (src)
Parameters:
name - node's fqn
Throws:
java.lang.Exception

removeData

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

Specified by:
removeData in interface CacheLoader (src)
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 (src)
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 (src)
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 (src)
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 (src)
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 (src)
Parameters:
state -
Throws:
java.lang.Exception

create

public void create()
            throws java.lang.Exception
Description copied from interface: Service (src)
create the service, do expensive operations etc

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

start

public void start()
           throws java.lang.Exception
Description copied from interface: Service (src)
start the service, create is already called

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

stop

public void stop()
Description copied from interface: Service (src)
stop the service

Specified by:
stop in interface Service (src)

destroy

public void destroy()
Description copied from interface: Service (src)
destroy the service, tear down

Specified by:
destroy in interface Service (src)