站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JBoss 4.0.1 sp1 Cache API Documentation 英文版文档

JDBCCacheLoader (JBossCache API) - JBoss 4.0.1 sp1 Cache API Documentation 英文版文档


org.jboss.cache.loader
Class JDBCCacheLoader

java.lang.Object
  extended byorg.jboss.cache.loader.JDBCCacheLoader
All Implemented Interfaces:
CacheLoader, org.jboss.system.Service

public class JDBCCacheLoader
extends 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.13 $
Author:
Alexey Loubyansky

Constructor Summary
JDBCCacheLoader()
           
 
Method Summary
 void commit(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.
 Map get(Fqn name)
          Returns a map representing a node.
 Object get(Fqn name, Object key)
          Loads an attribute from the database.
 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.
 void prepare(Object tx, List modifications, boolean one_phase)
          First phase in transaction commit process.
 void put(Fqn name, Map attributes)
          Adds attributes from the passed in map to the existing node.
 Object put(Fqn name, Object key, Object value)
          Adds/overrides a value in a node for a key.
 void put(List modifications)
          Inserts all modifications to the backend store.
 void remove(Fqn name)
          Removes a node and all its children.
 Object remove(Fqn name, Object key)
          Removes attribute's value for a key.
 void removeData(Fqn name)
          Nullifies the node.
 void rollback(Object tx)
          Rolls back a transaction.
 void setCache(TreeCache c)
          This method allows the CacheLoader to set the TreeCache, therefore allowing the CacheLoader to invoke methods of the TreeCache.
 void setConfig(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(Properties props)
Description copied from interface: CacheLoader
Sets the configuration. Will be called before Service.create() and Service.start()

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

setCache

public void setCache(TreeCache c)
Description copied from interface: CacheLoader
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
Parameters:
c - The cache on which this loader works

getChildrenNames

public Set getChildrenNames(Fqn fqn)
                     throws 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:
Exception

get

public Object get(Fqn name,
                  Object key)
           throws Exception
Loads an attribute from the database.

Specified by:
get in interface CacheLoader
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:
Exception

get

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

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

exists

public boolean exists(Fqn name)
               throws 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:
Exception

put

public Object put(Fqn name,
                  Object key,
                  Object value)
           throws 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:
Exception

put

public void put(Fqn name,
                Map attributes)
         throws 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:
Exception

put

public void put(List modifications)
         throws Exception
Description copied from interface: CacheLoader
Inserts all modifications to the backend store. Overwrite whatever is already in the datastore.

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

remove

public Object remove(Fqn name,
                     Object key)
              throws 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:
Exception

remove

public void remove(Fqn name)
            throws 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:
Exception

removeData

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

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

prepare

public void prepare(Object tx,
                    List modifications,
                    boolean one_phase)
             throws 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:
Exception

commit

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

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

rollback

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

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

loadEntireState

public byte[] loadEntireState()
                       throws 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:
Exception

storeEntireState

public void storeEntireState(byte[] state)
                      throws 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:
Exception

create

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

start

public void start()
           throws Exception
Specified by:
start in interface org.jboss.system.Service
Throws:
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


Copyright © 2002 JBoss Group, LLC. All Rights Reserved.