1 21 22 package org.apache.derby.impl.sql.catalog; 23 24 import org.apache.derby.iapi.services.cache.Cacheable; 25 import org.apache.derby.iapi.services.cache.CacheManager; 26 27 import org.apache.derby.iapi.services.stream.HeaderPrintWriter; 28 29 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 30 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor; 31 32 import org.apache.derby.iapi.error.StandardException; 33 34 import org.apache.derby.iapi.services.sanity.SanityManager; 35 36 50 class SPSNameCacheable implements Cacheable 51 { 52 private TableKey identity; 53 private SPSDescriptor spsd; 54 private final DataDictionaryImpl dd; 55 56 57 SPSNameCacheable(DataDictionaryImpl dd) { 58 this.dd = dd; 59 } 60 61 62 63 64 public void clearIdentity() 65 { 66 if (spsd != null) 67 { 68 dd.spsCacheEntryRemoved(spsd); 69 70 if (SanityManager.DEBUG) 71 { 72 if (SanityManager.DEBUG_ON("SPSNameCacheTrace")) 73 { 74 System.out.println("SPSCACHE: clearIdentity() on "+spsd.getName()); 75 } 76 } 77 spsd = null; 78 identity = null; 79 } 80 } 81 82 83 public Object getIdentity() 84 { 85 return identity; 86 } 87 88 89 public Cacheable createIdentity(Object key, Object createParameter) 90 { 91 if (SanityManager.DEBUG) 92 { 93 if (!(key instanceof TableKey)) 94 { 95 SanityManager.THROWASSERT("Key for a SPSNameCacheElement is a " + 96 key.getClass().getName() + 97 " instead of a TableKey"); 98 } 99 if (!(createParameter instanceof SPSDescriptor)) 100 { 101 SanityManager.THROWASSERT("Create parameter for a SPSNameCacheElement is a " + 102 createParameter.getClass().getName() + 103 "instead of a SPSDescriptorImpl"); 104 } 105 } 106 107 identity = (TableKey)key; 108 spsd = (SPSDescriptor) createParameter; 109 110 if (spsd != null) 111 { 112 if (SanityManager.DEBUG) 113 { 114 if (SanityManager.DEBUG_ON("SPSNameCacheTrace")) 115 { 116 System.out.println("SPSCACHE: createIdentity() on "+spsd.getName()); 117 } 118 } 119 120 dd.spsCacheEntryAdded(spsd); 121 try 122 { 123 spsd.loadGeneratedClass(); 124 } catch (StandardException e) 125 { 126 135 if (SanityManager.DEBUG) 136 { 137 System.out.println("Error loading class for "+spsd.getName()); 138 System.out.println(e); 139 e.printStackTrace(); 140 } 141 } 142 return this; 143 } 144 else 145 { 146 return null; 147 } 148 } 149 150 155 public Cacheable setIdentity(Object key) throws StandardException 156 { 157 if (SanityManager.DEBUG) 158 { 159 if (!(key instanceof TableKey)) 160 { 161 SanityManager.THROWASSERT("Key for a SPSNameCacheable Element is a " + 162 key.getClass().getName() + 163 " instead of a TableKey"); 164 } 165 } 166 167 168 identity = (TableKey)key ; 169 spsd = dd.getUncachedSPSDescriptor(identity); 170 if (spsd != null) 171 { 172 if (SanityManager.DEBUG) 173 { 174 if (SanityManager.DEBUG_ON("SPSNameCacheTrace")) 175 { 176 System.out.println("SPSCACHE: setIdentity() on "+spsd.getName()); 177 } 178 } 179 180 dd.spsCacheEntryAdded(spsd); 181 try 182 { 183 spsd.loadGeneratedClass(); 184 } catch (StandardException e) 185 { 186 195 if (SanityManager.DEBUG) 196 { 197 System.out.println("Error loading class for "+spsd.getName()); 198 System.out.println(e); 199 e.printStackTrace(); 200 } 201 } 202 return this; 203 } 204 else 205 { 206 return null; 207 } 208 } 209 210 211 212 213 public void clean(boolean forRemove) 214 { 215 return; 216 } 217 218 219 public boolean isDirty() 220 { 221 return false; 222 } 223 224 227 public SPSDescriptor getSPSDescriptor() 228 { 229 return spsd; 230 } 231 232 244 private boolean checkConsistency(SPSDescriptor uncachedSpsd, 245 Object identity, 246 HeaderPrintWriter reportInconsistent) 247 throws StandardException 248 { 249 boolean retval = true; 250 251 if (SanityManager.DEBUG) 252 { 253 if (uncachedSpsd == null) 254 { 255 reportInconsistent.println( 256 "Inconsistent SPSNameCacheable: identity = " + identity + 257 ", uncached table descriptor not found."); 258 retval = false; 259 } 260 else 261 { 262 if ( 263 (!uncachedSpsd.getText().equals(spsd.getText())) || 264 (!uncachedSpsd.getUsingText().equals(spsd.getUsingText())) || 265 (!uncachedSpsd.getQualifiedName().equals(spsd.getQualifiedName())) 266 ) 267 { 268 reportInconsistent.println( 269 "Inconsistent SPSNameCacheable: identity = " + identity + 270 ", cached SPS = " + 271 spsd + 272 ", uncached SPS = " + 273 uncachedSpsd); 274 275 retval = false; 276 } 277 } 278 } 279 280 return retval; 281 } 282 } 283 | Popular Tags |