001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.util.dao.hibernate;
022:
023: import com.liferay.portal.kernel.cache.CacheRegistry;
024: import com.liferay.portal.kernel.cache.CacheRegistryItem;
025:
026: import java.util.Map;
027:
028: import org.hibernate.cache.Cache;
029: import org.hibernate.cache.CacheException;
030:
031: /**
032: * <a href="CacheWrapper.java.html"><b><i>View Source</i></b></a>
033: *
034: * @author Brian Wing Shun Chan
035: *
036: */
037: public class CacheWrapper implements Cache, CacheRegistryItem {
038:
039: public CacheWrapper(Cache cache) {
040: _cache = cache;
041:
042: CacheRegistry.register(this );
043: }
044:
045: public void clear() throws CacheException {
046: _cache.clear();
047: }
048:
049: public void destroy() throws CacheException {
050: _cache.destroy();
051: }
052:
053: public Object get(Object key) throws CacheException {
054: return _cache.get(key);
055: }
056:
057: public long getElementCountInMemory() {
058: return _cache.getElementCountInMemory();
059: }
060:
061: public long getElementCountOnDisk() {
062: return _cache.getElementCountOnDisk();
063: }
064:
065: public String getRegionName() {
066: return _cache.getRegionName();
067: }
068:
069: public long getSizeInMemory() {
070: return _cache.getSizeInMemory();
071: }
072:
073: public int getTimeout() {
074: return _cache.getTimeout();
075: }
076:
077: public void lock(Object key) throws CacheException {
078: _cache.lock(key);
079: }
080:
081: public long nextTimestamp() {
082: return _cache.nextTimestamp();
083: }
084:
085: public void put(Object key, Object value) throws CacheException {
086: if (CacheRegistry.isActive()) {
087: _cache.put(key, value);
088: }
089: }
090:
091: public Object read(Object key) throws CacheException {
092: return _cache.read(key);
093: }
094:
095: public void remove(Object key) throws CacheException {
096: _cache.remove(key);
097: }
098:
099: public Map toMap() {
100: return _cache.toMap();
101: }
102:
103: public void unlock(Object key) throws CacheException {
104: _cache.unlock(key);
105: }
106:
107: public void update(Object key, Object value) throws CacheException {
108: if (CacheRegistry.isActive()) {
109: _cache.update(key, value);
110: }
111: }
112:
113: public void invalidate() {
114: _cache.clear();
115: }
116:
117: private Cache _cache;
118:
119: }
|