KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cache > JndiBoundTreeCacheProvider


1 // $Id: JndiBoundTreeCacheProvider.java,v 1.2 2005/03/16 06:01:16 oneovthafew Exp $
2
package org.hibernate.cache;
3
4 import java.util.Properties JavaDoc;
5
6 import javax.transaction.TransactionManager JavaDoc;
7
8 import org.hibernate.transaction.TransactionManagerLookup;
9 import org.hibernate.transaction.TransactionManagerLookupFactory;
10
11 /**
12  * Support for JBossCache (TreeCache), where the cache instance is available
13  * via JNDI lookup.
14  *
15  * @author Steve Ebersole
16  */

17 public class JndiBoundTreeCacheProvider extends AbstractJndiBoundCacheProvider {
18
19     private TransactionManager JavaDoc transactionManager;
20
21     /**
22      * Construct a Cache representing the "region" within in the underlying cache
23      * provider.
24      *
25      * @param regionName the name of the cache region
26      * @param properties configuration settings
27      *
28      * @throws CacheException
29      */

30     public Cache buildCache(String JavaDoc regionName, Properties JavaDoc properties) throws CacheException {
31         return new TreeCache( getTreeCacheInstance(), regionName, transactionManager );
32     }
33
34     public void prepare(Properties JavaDoc properties) throws CacheException {
35         TransactionManagerLookup transactionManagerLookup = TransactionManagerLookupFactory.getTransactionManagerLookup(properties);
36         if (transactionManagerLookup!=null) {
37             transactionManager = transactionManagerLookup.getTransactionManager(properties);
38         }
39     }
40     /**
41      * Generate a timestamp
42      */

43     public long nextTimestamp() {
44         return System.currentTimeMillis() / 100;
45     }
46
47     /**
48      * By default, should minimal-puts mode be enabled when using this cache.
49      * <p/>
50      * Since TreeCache is a clusterable cache and we are only getting a
51      * reference the instance from JNDI, safest to assume a clustered
52      * setup and return true here.
53      *
54      * @return True.
55      */

56     public boolean isMinimalPutsEnabledByDefault() {
57         return true;
58     }
59
60     public org.jboss.cache.TreeCache getTreeCacheInstance() {
61         return ( org.jboss.cache.TreeCache ) super.getCache();
62     }
63 }
64
Popular Tags