KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jboss.ejb3.entity;
2
3 import java.util.Properties JavaDoc;
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    /**
13     * Gets and configures a concrete TransactionalCacheFactory suitable for
14     * interoperation with the version of JBoss Cache visible on the classpath.
15     *
16     * @param hibernateConfig properties to use to {@link #configure(Properties) configure}
17     * the factory.
18     * @return the factory
19     *
20     * @throws CacheException
21     */

22    public static TransactionalCacheFactory getFactory(Properties JavaDoc hibernateConfig) throws CacheException
23    {
24       String JavaDoc 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          // TODO write a factory for the old hibernate stuff
33
// needs to be in a separate code tree from JBCCacheFactory as
34
// TreeCacheMBean is no longer available in 2.0
35
throw new IllegalStateException JavaDoc("Cannot create factory for JBC 1.x");
36       }
37       
38       try
39       {
40          Class JavaDoc 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 JavaDoc e)
51       {
52          throw new CacheException(e);
53       }
54       
55    }
56    
57    /**
58     * Construct and configure the Cache representation of a named cache region.
59     *
60     * @param regionName the name of the cache region
61     * @param properties configuration settings
62     * @return The Cache representation of the named cache region.
63     * @throws org.hibernate.cache.CacheException
64     * Indicates an error building the cache region.
65     */

66    public abstract Cache buildCache(String JavaDoc regionName, Properties JavaDoc properties) throws CacheException;
67    
68    /**
69     * Configures the factory using the Hibernate configuration properties.
70     * Called by {@link #getFactory(Properties)}.
71     *
72     * @param hibernateConfig the Hibernate configuration properties
73     */

74    protected abstract void configure(Properties JavaDoc hibernateConfig);
75    
76 }
77
Popular Tags