1 24 25 package org.objectweb.cjdbc.controller.cache.result.entries; 26 27 import org.objectweb.cjdbc.common.sql.SelectRequest; 28 import org.objectweb.cjdbc.common.stream.CJDBCStream; 29 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet; 30 31 46 public abstract class AbstractResultCacheEntry 47 { 48 protected SelectRequest request; 49 protected ControllerResultSet result; 50 protected int state; 51 52 private AbstractResultCacheEntry next; 54 private AbstractResultCacheEntry prev; 55 56 57 public static final int NO_DEADLINE = -1; 58 59 public static final int CACHE_VALID = 0; 60 61 public static final int CACHE_DIRTY = 1; 62 63 public static final int CACHE_INVALID = 2; 64 65 71 public AbstractResultCacheEntry(SelectRequest request, 72 ControllerResultSet result) 73 { 74 this.request = request; 75 this.result = result; 76 state = CACHE_VALID; 77 next = null; 78 prev = null; 79 } 80 81 86 public abstract String getType(); 87 88 93 public String getState() 94 { 95 if (isValid()) 96 return "Valid"; 97 if (isDirty()) 98 return "Dirty"; 99 else 100 return "Invalid"; 101 } 102 103 109 public boolean isValid() 110 { 111 return state == CACHE_VALID; 112 } 113 114 120 public boolean isDirty() 121 { 122 return state == CACHE_DIRTY; 123 } 124 125 130 public SelectRequest getRequest() 131 { 132 return request; 133 } 134 135 140 public ControllerResultSet getResult() 141 { 142 return result; 143 } 144 145 153 public void setResult(ControllerResultSet result) 154 { 155 this.result = result; 156 state = CACHE_VALID; 157 } 158 159 163 public abstract void invalidate(); 164 165 170 public void markDirty() 171 { 172 state = CACHE_DIRTY; 173 } 174 175 178 public void setValid() 179 { 180 state = CACHE_VALID; 181 } 182 183 188 public AbstractResultCacheEntry getNext() 189 { 190 return next; 191 } 192 193 198 public void setNext(AbstractResultCacheEntry next) 199 { 200 this.next = next; 201 } 202 203 208 public AbstractResultCacheEntry getPrev() 209 { 210 return prev; 211 } 212 213 218 public void setPrev(AbstractResultCacheEntry prev) 219 { 220 this.prev = prev; 221 } 222 223 228 public abstract String [] toStringTable(); 229 230 235 public int getSizeOfResult() 236 { 237 try 238 { 239 return CJDBCStream.countBytes(result); 240 } 241 catch (Exception e) 242 { 243 return -1; 244 } 245 } 246 247 } | Popular Tags |