KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > entity > JBCCacheFactory


1 package org.jboss.ejb3.entity;
2
3 import java.util.Properties JavaDoc;
4
5 import javax.management.ObjectName JavaDoc;
6
7 import org.hibernate.cache.Cache;
8 import org.hibernate.cache.CacheException;
9 import org.jboss.cache.jmx.CacheJmxWrapperMBean;
10 import org.jboss.ejb3.tx.TxUtil;
11 import org.jboss.mx.util.MBeanProxyExt;
12 import org.jboss.mx.util.MBeanServerLocator;
13
14 class JBCCacheFactory extends TransactionalCacheFactory
15 {
16    private org.jboss.cache.Cache cache;
17    private boolean optimistic;
18    
19    JBCCacheFactory()
20    {
21        
22    }
23    
24    protected void configure(Properties JavaDoc hibernateConfig)
25    {
26        try
27        {
28           ObjectName JavaDoc mbeanObjectName = new ObjectName JavaDoc((String JavaDoc) hibernateConfig.get("hibernate.treecache.mbean.object_name"));
29           CacheJmxWrapperMBean mbean = (CacheJmxWrapperMBean) MBeanProxyExt.create(CacheJmxWrapperMBean.class, mbeanObjectName, MBeanServerLocator.locateJBoss());
30           cache = mbean.getCache();
31           optimistic = cache.getConfiguration().isNodeLockingOptimistic();
32        }
33        catch (Exception JavaDoc e)
34        {
35           throw new CacheException(e);
36        }
37    }
38    
39    public Cache buildCache(String JavaDoc regionName, Properties JavaDoc properties) throws CacheException
40    {
41 // if (optimistic)
42
// {
43
// return new OptimisticJBCCache(cache, regionName);
44
// }
45
// else
46
// {
47
return new JBCCache(cache, regionName, TxUtil.getTransactionManager());
48 // }
49
}
50
51 }
52
Popular Tags