1 21 22 package org.apache.derbyTesting.unitTests.services; 23 24 import org.apache.derby.iapi.services.cache.*; 25 26 import org.apache.derby.iapi.error.StandardException; 27 28 31 public abstract class T_Cacheable implements Cacheable { 32 33 protected boolean isDirty; 34 35 protected Thread owner; 36 37 public T_Cacheable() { 38 } 39 40 43 44 public Cacheable setIdentity(Object key) throws StandardException { 45 if (!(key instanceof T_Key)) { 47 throw T_CacheException.invalidKey(); 48 } 49 50 owner = null; 51 52 return null; } 54 55 56 57 public Cacheable createIdentity(Object key, Object createParameter) throws StandardException { 58 59 if (!(key instanceof T_Key)) { 61 throw T_CacheException.invalidKey(); 62 } 63 64 owner = (Thread ) createParameter; 65 66 return null; } 68 69 75 public boolean isDirty() { 76 synchronized (this) { 77 return isDirty; 78 } 79 } 80 81 82 83 public void clean(boolean forRemove) throws StandardException { 84 synchronized (this) { 85 isDirty = false; 86 } 87 } 88 89 92 93 protected Cacheable getCorrectObject(Object keyValue) throws StandardException { 94 95 Cacheable correctType; 96 97 if (keyValue instanceof Integer ) { 98 99 correctType = new T_CachedInteger(); 100 } else { 103 104 throw T_CacheException.invalidKey(); 105 } 106 107 return correctType; 108 } 109 110 protected boolean dummySet(T_Key tkey) throws StandardException { 111 112 if (tkey.getWait() != 0) { 114 synchronized (this) { 115 116 try { 117 wait(tkey.getWait()); 118 } catch (InterruptedException ie) { 119 } 121 } 122 } 123 124 if (!tkey.canFind()) 125 return false; 126 127 if (tkey.raiseException()) 128 throw T_CacheException.identityFail(); 129 130 return true; 131 } 132 133 public void setDirty() { 134 synchronized (this) { 135 isDirty = true; 136 } 137 } 138 139 public boolean canRemove() { 140 141 synchronized (this) { 142 if (owner == null) 143 owner = Thread.currentThread(); 144 145 if (owner == Thread.currentThread()) 146 return true; 147 return false; 148 } 149 } 150 } 151 152 | Popular Tags |