1 10 package mondrian.rolap; 11 12 import mondrian.rolap.cache.SmartCache; 13 import mondrian.rolap.cache.SoftSmartCache; 14 import mondrian.rolap.sql.SqlConstraint; 15 16 46 public class SmartMemberListCache <K, V> { 47 SmartCache<Key2<K, Object >, V> cache; 48 49 52 static class Key2 <T1, T2> { 53 T1 o1; 54 T2 o2; 55 56 public Key2(T1 o1, T2 o2) { 57 this.o1 = o1; 58 this.o2 = o2; 59 } 60 61 public boolean equals(Object obj) { 62 if (!(obj instanceof Key2)) { 63 return false; 64 } 65 Key2 that = (Key2) obj; 66 return equals(this.o1, that.o1) && equals(this.o2, that.o2); 67 } 68 69 private boolean equals(Object o1, Object o2) { 70 return o1 == null ? o2 == null : o1.equals(o2); 71 } 72 73 public int hashCode() { 74 int c = 1; 75 if (o1 != null) { 76 c = o1.hashCode(); 77 } 78 if (o2 != null) { 79 c = 31 * c + o2.hashCode(); 80 } 81 return c; 82 } 83 84 public String toString() { 85 return "key(" + o1 + "," + o2 + ")"; 86 } 87 } 88 89 public SmartMemberListCache() { 90 cache = new SoftSmartCache<Key2<K, Object >, V>(); 91 } 92 93 public Object put(K key, SqlConstraint constraint, V value) { 94 Object cacheKey = constraint.getCacheKey(); 95 if (cacheKey == null) { 96 return null; 97 } 98 Key2<K, Object > key2 = new Key2<K, Object >(key, cacheKey); 99 return cache.put(key2, value); 100 } 101 102 public V get(K key, SqlConstraint constraint) { 103 Key2<K, Object > key2 = new Key2<K, Object >(key, constraint.getCacheKey()); 104 return cache.get(key2); 105 } 106 107 public void clear() { 108 cache.clear(); 109 } 110 111 SmartCache getCache() { 112 return cache; 113 } 114 115 void setCache(SmartCache<Key2<K, Object >, V> cache) { 116 this.cache = cache; 117 } 118 } 119 120 | Popular Tags |