001
014
015 package com.liferay.portal.dao.orm.hibernate;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryItem;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.log.Log;
020 import com.liferay.portal.kernel.log.LogFactoryUtil;
021
022 import java.util.Map;
023
024 import org.hibernate.cache.Cache;
025 import org.hibernate.cache.CacheException;
026
027
031 public class CacheWrapper implements Cache, CacheRegistryItem {
032
033 public CacheWrapper(Cache cache) {
034 _cache = cache;
035 _registryName = cache.getRegionName();
036
037 if (_log.isDebugEnabled()) {
038 _log.debug("Creating cache for " + _registryName);
039 }
040
041 CacheRegistryUtil.register(this);
042 }
043
044 public void clear() throws CacheException {
045 _cache.clear();
046 }
047
048 public void destroy() throws CacheException {
049 _cache.destroy();
050 }
051
052 public Object get(Object key) throws CacheException {
053 return _cache.get(key);
054 }
055
056 public long getElementCountInMemory() {
057 return _cache.getElementCountInMemory();
058 }
059
060 public long getElementCountOnDisk() {
061 return _cache.getElementCountOnDisk();
062 }
063
064 public String getRegionName() {
065 return _cache.getRegionName();
066 }
067
068 public String getRegistryName() {
069 return _registryName;
070 }
071
072 public long getSizeInMemory() {
073 return _cache.getSizeInMemory();
074 }
075
076 public int getTimeout() {
077 return _cache.getTimeout();
078 }
079
080 public void lock(Object key) throws CacheException {
081 _cache.lock(key);
082 }
083
084 public long nextTimestamp() {
085 return _cache.nextTimestamp();
086 }
087
088 public void put(Object key, Object value) throws CacheException {
089 if (CacheRegistryUtil.isActive()) {
090 _cache.put(key, value);
091 }
092 }
093
094 public Object read(Object key) throws CacheException {
095 return _cache.read(key);
096 }
097
098 public void remove(Object key) throws CacheException {
099 _cache.remove(key);
100 }
101
102 public Map<?, ?> toMap() {
103 return _cache.toMap();
104 }
105
106 public void unlock(Object key) throws CacheException {
107 _cache.unlock(key);
108 }
109
110 public void update(Object key, Object value) throws CacheException {
111 if (CacheRegistryUtil.isActive()) {
112 _cache.update(key, value);
113 }
114 }
115
116 public void invalidate() {
117 if (_log.isDebugEnabled()) {
118 _log.debug("Invalidating cache for " + _registryName);
119 }
120
121 _cache.clear();
122 }
123
124 private static Log _log = LogFactoryUtil.getLog(CacheWrapper.class);
125
126 private Cache _cache;
127 private String _registryName;
128
129 }