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