1 package org.hibernate.cache; 3 4 import java.util.Comparator ; 5 6 import org.apache.commons.logging.Log; 7 import org.apache.commons.logging.LogFactory; 8 9 17 public class TransactionalCache implements CacheConcurrencyStrategy { 18 19 private static final Log log = LogFactory.getLog(TransactionalCache.class); 20 21 private Cache cache; 22 23 public String getRegionName() { 24 return cache.getRegionName(); 25 } 26 27 public Object get(Object key, long txTimestamp) throws CacheException { 28 if ( log.isDebugEnabled() ) log.debug("cache lookup: " + key); 29 Object result = cache.read(key); 30 if ( log.isDebugEnabled() ) { 31 log.debug( result==null ? "cache miss" : "cache hit" ); 32 } 33 return result; 34 } 35 36 public boolean put( 37 Object key, 38 Object value, 39 long txTimestamp, 40 Object version, 41 Comparator versionComparator, 42 boolean minimalPut) 43 throws CacheException { 44 45 if ( minimalPut && cache.read(key)!=null ) { 46 if ( log.isDebugEnabled() ) log.debug("item already cached: " + key); 47 return false; 48 } 49 if ( log.isDebugEnabled() ) log.debug("caching: " + key); 50 cache.put(key, value); 51 return true; 52 } 53 54 57 public SoftLock lock(Object key, Object version) throws CacheException { 58 return null; 60 } 61 62 65 public void release(Object key, SoftLock clientLock) throws CacheException { 66 } 68 69 public boolean update(Object key, Object value) throws CacheException { 70 if ( log.isDebugEnabled() ) log.debug("updating: " + key); 71 cache.update(key, value); 72 return true; 73 } 74 75 public boolean insert(Object key, Object value) throws CacheException { 76 if ( log.isDebugEnabled() ) log.debug("inserting: " + key); 77 cache.update(key, value); 78 return true; 79 } 80 81 public void evict(Object key) throws CacheException { 82 cache.remove(key); 83 } 84 85 public void remove(Object key) throws CacheException { 86 if ( log.isDebugEnabled() ) log.debug("removing: " + key); 87 cache.remove(key); 88 } 89 90 public void clear() throws CacheException { 91 log.debug("clearing"); 92 cache.clear(); 93 } 94 95 public void destroy() { 96 try { 97 cache.destroy(); 98 } 99 catch (Exception e) { 100 log.warn("could not destroy cache", e); 101 } 102 } 103 104 public void setCache(Cache cache) { 105 this.cache = cache; 106 } 107 108 public Cache getCache() { 109 return cache; 110 } 111 112 115 public boolean afterInsert(Object key, Object value, Object version) 116 throws CacheException { 117 return false; 118 } 119 120 123 public boolean afterUpdate(Object key, Object value, Object version, SoftLock clientLock) 124 throws CacheException { 125 return false; 126 } 127 128 public String toString() { 129 return cache + "(transactional)"; 130 } 131 132 } 133 | Popular Tags |