1 package org.hibernate.cache; 3 4 import net.sf.swarmcache.ObjectCache; 5 6 import java.io.Serializable ; 7 import java.util.Map ; 8 9 12 public class SwarmCache implements Cache { 13 14 private final ObjectCache cache; 15 private final String regionName; 16 17 public SwarmCache(ObjectCache cache, String regionName) { 18 this.cache = cache; 19 this.regionName = regionName; 20 } 21 22 28 public Object get(Object key) throws CacheException { 29 if (key instanceof Serializable ) { 30 return cache.get( (Serializable ) key ); 31 } 32 else { 33 throw new CacheException("Keys must implement Serializable"); 34 } 35 } 36 37 public Object read(Object key) throws CacheException { 38 return get(key); 39 } 40 41 47 public void update(Object key, Object value) throws CacheException { 48 put(key, value); 49 } 50 51 57 public void put(Object key, Object value) throws CacheException { 58 if (key instanceof Serializable ) { 59 cache.put( (Serializable ) key, value ); 60 } 61 else { 62 throw new CacheException("Keys must implement Serializable"); 63 } 64 } 65 66 69 public void remove(Object key) throws CacheException { 70 if (key instanceof Serializable ) { 71 cache.clear( (Serializable ) key ); 72 } 73 else { 74 throw new CacheException("Keys must implement Serializable"); 75 } 76 } 77 78 81 public void clear() throws CacheException { 82 cache.clearAll(); 83 } 84 85 88 public void destroy() throws CacheException { 89 cache.clearAll(); 90 } 91 92 95 public void lock(Object key) throws CacheException { 96 throw new UnsupportedOperationException ("SwarmCache does not support locking (use nonstrict-read-write)"); 97 } 98 99 102 public void unlock(Object key) throws CacheException { 103 throw new UnsupportedOperationException ("SwarmCache does not support locking (use nonstrict-read-write)"); 104 } 105 106 109 public long nextTimestamp() { 110 return System.currentTimeMillis() / 100; 111 } 112 113 116 public int getTimeout() { 117 return 600; 118 } 119 120 public String getRegionName() { 121 return regionName; 122 } 123 124 public long getSizeInMemory() { 125 return -1; 126 } 127 128 public long getElementCountInMemory() { 129 return -1; 130 } 131 132 public long getElementCountOnDisk() { 133 return -1; 134 } 135 136 public Map toMap() { 137 throw new UnsupportedOperationException (); 138 } 139 140 public String toString() { 141 return "SwarmCache(" + regionName + ')'; 142 } 143 144 } 145 | Popular Tags |