| 1 5 package com.whirlycott.cache.hibernate; 6 7 import net.sf.hibernate.cache.Timestamper; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 12 import com.whirlycott.cache.Cache; 13 import com.whirlycott.cache.CacheException; 14 import com.whirlycott.cache.CacheManager; 15 import com.whirlycott.cache.Messages; 16 17 21 public class WhirlycachePlugin implements net.sf.hibernate.cache.Cache { 22 23 26 private static final Log log = LogFactory.getLog(WhirlycachePlugin.class); 27 28 31 private static final int MS_PER_MINUTE = 60000; 32 33 36 private Cache cache; 37 38 41 private final String cacheName; 42 43 47 public WhirlycachePlugin(final String _name) 48 throws net.sf.hibernate.cache.CacheException { 49 super(); 50 51 if (_name == null) 53 throw new IllegalArgumentException (Messages.getString("WhirlycachePlugin.cannot_lookup_cache_with_null_name")); 55 cacheName = _name; 57 58 try { 59 cache = CacheManager.getInstance().getCache(_name); 60 } catch (final CacheException e) { 61 throw new net.sf.hibernate.cache.CacheException(e.getMessage()); 63 } 64 } 65 66 71 public void clear() throws net.sf.hibernate.cache.CacheException { 72 cache.clear(); 73 } 74 75 80 public void destroy() throws net.sf.hibernate.cache.CacheException { 81 try { 82 CacheManager.getInstance().destroy(cacheName); 83 } catch (final CacheException e) { 84 log.error(e.getMessage(), e); 85 } 86 } 87 88 93 public Object get(final Object _key) throws net.sf.hibernate.cache.CacheException { 94 return cache.retrieve(_key); 95 } 96 97 102 public int getTimeout() { 103 return Timestamper.ONE_MS * MS_PER_MINUTE; 104 } 105 106 111 public void lock(final Object arg0) throws net.sf.hibernate.cache.CacheException { 112 return; 113 } 114 115 120 public long nextTimestamp() { 121 return Timestamper.next(); 122 } 123 124 129 public void put(final Object _key, final Object _val) throws net.sf.hibernate.cache.CacheException { 130 cache.store(_key, _val); 131 } 132 133 138 public void remove(final Object _key) throws net.sf.hibernate.cache.CacheException { 139 cache.remove(_key); 140 } 141 142 147 public void unlock(final Object arg0) throws net.sf.hibernate.cache.CacheException { 148 return; 149 } 150 151 } 152 153 | Popular Tags |