1
22
23 package com.liferay.portal.dao.orm.hibernate;
24
25 import com.liferay.portal.kernel.cache.CacheRegistry;
26 import com.liferay.portal.kernel.cache.CacheRegistryItem;
27 import com.liferay.portal.kernel.log.Log;
28 import com.liferay.portal.kernel.log.LogFactoryUtil;
29
30 import java.util.Map;
31
32 import org.hibernate.cache.Cache;
33 import org.hibernate.cache.CacheException;
34
35
41 public class CacheWrapper implements Cache, CacheRegistryItem {
42
43 public CacheWrapper(Cache cache) {
44 _cache = cache;
45 _registryName = cache.getRegionName();
46
47 if (_log.isDebugEnabled()) {
48 _log.debug("Creating cache for " + _registryName);
49 }
50
51 CacheRegistry.register(this);
52 }
53
54 public void clear() throws CacheException {
55 _cache.clear();
56 }
57
58 public void destroy() throws CacheException {
59 _cache.destroy();
60 }
61
62 public Object get(Object key) throws CacheException {
63 return _cache.get(key);
64 }
65
66 public long getElementCountInMemory() {
67 return _cache.getElementCountInMemory();
68 }
69
70 public long getElementCountOnDisk() {
71 return _cache.getElementCountOnDisk();
72 }
73
74 public String getRegionName() {
75 return _cache.getRegionName();
76 }
77
78 public String getRegistryName() {
79 return _registryName;
80 }
81
82 public long getSizeInMemory() {
83 return _cache.getSizeInMemory();
84 }
85
86 public int getTimeout() {
87 return _cache.getTimeout();
88 }
89
90 public void lock(Object key) throws CacheException {
91 _cache.lock(key);
92 }
93
94 public long nextTimestamp() {
95 return _cache.nextTimestamp();
96 }
97
98 public void put(Object key, Object value) throws CacheException {
99 if (CacheRegistry.isActive()) {
100 _cache.put(key, value);
101 }
102 }
103
104 public Object read(Object key) throws CacheException {
105 return _cache.read(key);
106 }
107
108 public void remove(Object key) throws CacheException {
109 _cache.remove(key);
110 }
111
112 public Map toMap() {
113 return _cache.toMap();
114 }
115
116 public void unlock(Object key) throws CacheException {
117 _cache.unlock(key);
118 }
119
120 public void update(Object key, Object value) throws CacheException {
121 if (CacheRegistry.isActive()) {
122 _cache.update(key, value);
123 }
124 }
125
126 public void invalidate() {
127 if (_log.isDebugEnabled()) {
128 _log.debug("Invalidating cache for " + _registryName);
129 }
130
131 _cache.clear();
132 }
133
134 private static Log _log = LogFactoryUtil.getLog(CacheWrapper.class);
135
136 private Cache _cache;
137 private String _registryName;
138
139 }