org.hibernate.cache
public class: OptimisticTreeCacheProvider [javadoc |
source]
java.lang.Object
org.hibernate.cache.OptimisticTreeCacheProvider
All Implemented Interfaces:
CacheProvider
Support for a standalone JBossCache TreeCache instance utilizing TreeCache's
optimistic locking capabilities. This capability was added in JBossCache
version 1.3.0; as such this provider will only work with that version or
higher.
The TreeCache instance is configured via a local config resource. The
resource to be used for configuration can be controlled by specifying a value
for the
#CONFIG_RESOURCE config property.
| Field Summary |
|---|
| public static final String | CONFIG_RESOURCE | |
| public static final String | DEFAULT_CONFIG | |
| Method from org.hibernate.cache.OptimisticTreeCacheProvider Detail: |
public Cache buildCache(String regionName,
Properties properties) throws CacheException {
return new OptimisticTreeCache( cache, regionName );
}
Construct and configure the Cache representation of a named cache region. |
public TreeCache getUnderlyingCache() {
return cache;
}
|
public boolean isMinimalPutsEnabledByDefault() {
return true;
}
|
public long nextTimestamp() {
return System.currentTimeMillis() / 100;
}
|
public void start(Properties properties) {
String resource = properties.getProperty( Environment.CACHE_PROVIDER_CONFIG );
if (resource == null) {
resource = properties.getProperty( CONFIG_RESOURCE );
}
if ( resource == null ) {
resource = DEFAULT_CONFIG;
}
log.debug( "Configuring TreeCache from resource [" + resource + "]" );
try {
cache = new org.jboss.cache.TreeCache();
PropertyConfigurator config = new PropertyConfigurator();
config.configure( cache, resource );
TransactionManagerLookup transactionManagerLookup =
TransactionManagerLookupFactory.getTransactionManagerLookup( properties );
if ( transactionManagerLookup == null ) {
throw new CacheException(
"JBossCache only supports optimisitc locking with a configured " +
"TransactionManagerLookup (" + Environment.TRANSACTION_MANAGER_STRATEGY + ")"
);
}
cache.setTransactionManagerLookup(
new TransactionManagerLookupAdaptor(
transactionManagerLookup,
properties
)
);
if ( ! NODE_LOCKING_SCHEME.equalsIgnoreCase( cache.getNodeLockingScheme() ) ) {
log.info( "Overriding node-locking-scheme to : " + NODE_LOCKING_SCHEME );
cache.setNodeLockingScheme( NODE_LOCKING_SCHEME );
}
cache.start();
}
catch ( Exception e ) {
throw new CacheException( e );
}
}
Prepare the underlying JBossCache TreeCache instance. |
public void stop() {
if ( cache != null ) {
cache.stop();
cache.destroy();
cache = null;
}
}
|