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