1 23 24 package org.continuent.sequoia.controller.cache.result.schema; 25 26 import java.util.ArrayList ; 27 import java.util.Hashtable ; 28 import java.util.Iterator ; 29 30 import org.continuent.sequoia.controller.cache.result.entries.AbstractResultCacheEntry; 31 import org.continuent.sequoia.controller.requests.RequestType; 32 import org.continuent.sequoia.controller.requests.SelectRequest; 33 34 44 public class CacheDatabaseColumn 45 { 46 private String name; 47 private ArrayList cacheEntries; 48 49 54 public CacheDatabaseColumn(String name) 55 { 56 this.name = name; 57 cacheEntries = new ArrayList (); 58 } 59 60 65 public String getName() 66 { 67 return name; 68 } 69 70 77 public boolean equals(Object other) 78 { 79 if (!(other instanceof CacheDatabaseColumn)) 80 return false; 81 82 return name.equals(((CacheDatabaseColumn) other).getName()); 83 } 84 85 91 public synchronized void addCacheEntry(AbstractResultCacheEntry ce) 92 { 93 cacheEntries.add(ce); 94 } 95 96 100 public synchronized void markDirtyAllNonUnique() 101 { 102 for (int i = 0; i < cacheEntries.size(); i++) 105 { 106 AbstractResultCacheEntry ce = (AbstractResultCacheEntry) cacheEntries 107 .get(i); 108 if ((ce.getRequest().getCacheAbility() != RequestType.UNIQUE_CACHEABLE) 109 && ce.isValid()) 110 ce.markDirty(); 111 } 112 } 113 114 117 public synchronized void invalidateAll() 118 { 119 for (Iterator i = cacheEntries.iterator(); i.hasNext();) 120 { 121 AbstractResultCacheEntry entry = (AbstractResultCacheEntry) i.next(); 122 entry.invalidate(); 123 } 124 cacheEntries.clear(); 125 } 126 127 131 public synchronized void invalidateAllNonUnique() 132 { 133 for (int i = 0; i < cacheEntries.size();) 136 { 137 AbstractResultCacheEntry ce = (AbstractResultCacheEntry) cacheEntries 138 .get(i); 139 if (ce.getRequest().getCacheAbility() != RequestType.UNIQUE_CACHEABLE) 140 { 141 ce.invalidate(); 142 cacheEntries.remove(i); 143 } 144 else 145 { 146 i++; 147 } 148 } 149 } 150 151 161 public synchronized void invalidateAllUniqueWithValuesAndAllNonUnique( 162 String val, ArrayList columns, ArrayList values) 163 { 164 for (int i = 0; i < cacheEntries.size();) 167 { 168 AbstractResultCacheEntry ce = (AbstractResultCacheEntry) cacheEntries 169 .get(i); 170 if (ce.getRequest().getCacheAbility() == RequestType.UNIQUE_CACHEABLE) 171 { 172 Hashtable queryValues; 173 String value, v; 174 SelectRequest query; 175 int size, j; 176 177 query = ce.getRequest(); 178 queryValues = query.getWhereValues(); 179 value = (String ) queryValues.get(this.name); 181 if (value.compareToIgnoreCase(val) == 0) 182 { 183 size = values.size(); 187 j = 0; 188 for (Iterator it = columns.iterator(); it.hasNext() && (j < size); j++) 189 { 190 CacheDatabaseColumn cdc = (CacheDatabaseColumn) it.next(); 191 if (!this.equals(cdc)) 192 { 193 v = (String ) values.get(j); 194 value = (String ) queryValues.get(cdc.getName()); 195 if (value.compareToIgnoreCase(v) != 0) 196 { 197 return; 200 } 201 } 202 } 203 ce.invalidate(); 206 cacheEntries.remove(i); 207 } 208 else 209 { 210 i++; 213 } 214 } 215 else 216 { 217 ce.invalidate(); 220 cacheEntries.remove(i); 221 } 222 } 223 } 224 225 229 public synchronized void invalidateAllNonUniqueAndMarkDirtyUnique() 230 { 231 for (int i = 0; i < cacheEntries.size(); i++) 234 { 235 AbstractResultCacheEntry ce = (AbstractResultCacheEntry) cacheEntries 236 .get(i); 237 if ((ce.getRequest().getCacheAbility() != RequestType.UNIQUE_CACHEABLE) 238 && ce.isValid()) 239 ce.markDirty(); 240 else 241 { 242 ce.invalidate(); 243 cacheEntries.remove(i); 244 } 245 } 246 } 247 248 253 public String getInformation() 254 { 255 return name; 256 } 257 } 258 | Popular Tags |