| EhCacheProvider.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.dao.orm.hibernate;
16
17 import com.liferay.portal.kernel.exception.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 }