1 package org.jboss.ejb3.entity; 2 3 import java.util.Properties ; 4 5 import org.hibernate.cache.Cache; 6 import org.hibernate.cache.CacheException; 7 import org.jboss.cache.Version; 8 9 public abstract class TransactionalCacheFactory 10 { 11 12 22 public static TransactionalCacheFactory getFactory(Properties hibernateConfig) throws CacheException 23 { 24 String factoryClass = null; 25 short version = Version.getVersionShort(); 26 if (version >= Version.getVersionShort("2.0.0.GA") || version <= 0) 27 { 28 factoryClass = "org.jboss.ejb3.entity.JBCCacheFactory"; 29 } 30 else 31 { 32 throw new IllegalStateException ("Cannot create factory for JBC 1.x"); 36 } 37 38 try 39 { 40 Class clazz = Thread.currentThread().getContextClassLoader().loadClass(factoryClass); 41 TransactionalCacheFactory factory = (TransactionalCacheFactory) clazz.newInstance(); 42 factory.configure(hibernateConfig); 43 44 return factory; 45 } 46 catch (CacheException e) 47 { 48 throw e; 49 } 50 catch (Exception e) 51 { 52 throw new CacheException(e); 53 } 54 55 } 56 57 66 public abstract Cache buildCache(String regionName, Properties properties) throws CacheException; 67 68 74 protected abstract void configure(Properties hibernateConfig); 75 76 } 77 | Popular Tags |