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