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