1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portal.dao.orm.hibernate;
16  
17  import com.liferay.portal.SystemException;
18  
19  import java.lang.reflect.Field;
20  
21  import net.sf.ehcache.CacheManager;
22  
23  import org.hibernate.cache.CacheProvider;
24  
25  /**
26   * <a href="EhCacheProvider.java.html"><b><i>View Source</i></b></a>
27   *
28   * @author Brian Wing Shun Chan
29   * @author Shuyang Zhou
30   */
31  @SuppressWarnings("deprecation")
32  public class EhCacheProvider extends CacheProviderWrapper {
33  
34      public static CacheManager getCacheManager() throws SystemException {
35          try {
36              Class<?> clazz = Class.forName(
37                  "net.sf.ehcache.hibernate.EhCacheProvider");
38  
39              Field field = clazz.getDeclaredField("manager");
40  
41              field.setAccessible(true);
42  
43              CacheManager cacheManager = (CacheManager)field.get(
44                  _cacheProvider);
45  
46              if (cacheManager == null) {
47                  throw new SystemException("CacheManager has been initialized");
48              }
49  
50              return cacheManager;
51          }
52          catch (Exception e) {
53              throw new SystemException(e);
54          }
55      }
56  
57      public EhCacheProvider() {
58          super("net.sf.ehcache.hibernate.EhCacheProvider");
59  
60          _cacheProvider = cacheProvider;
61      }
62  
63      private static CacheProvider _cacheProvider;
64  
65  }