1 21 22 package org.apache.derby.iapi.sql.dictionary; 23 24 import org.apache.derby.catalog.UUID; 25 26 import org.apache.derby.iapi.sql.depend.Dependent; 27 import org.apache.derby.iapi.sql.depend.Provider; 28 import org.apache.derby.iapi.sql.dictionary.GenericDescriptorList; 29 import org.apache.derby.iapi.error.StandardException; 30 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 31 import org.apache.derby.iapi.store.access.TransactionController; 32 import org.apache.derby.iapi.sql.depend.DependencyManager; 33 34 import org.apache.derby.iapi.services.context.ContextService; 35 36 import org.apache.derby.iapi.reference.SQLState; 37 import org.apache.derby.iapi.services.sanity.SanityManager; 38 import org.apache.derby.iapi.sql.StatementType; 39 import org.apache.derby.catalog.DependableFinder; 40 import org.apache.derby.catalog.Dependable; 41 import org.apache.derby.iapi.services.io.StoredFormatIds; 42 import org.apache.derby.impl.sql.execute.DropTriggerConstantAction; 43 44 59 60 public final class ViewDescriptor extends TupleDescriptor 61 implements UniqueTupleDescriptor, Dependent, Provider 62 { 63 private final int checkOption; 64 private String viewName; 65 private final String viewText; 66 private UUID uuid; 67 private final UUID compSchemaId; 68 69 public static final int NO_CHECK_OPTION = 0; 70 71 81 82 public ViewDescriptor(DataDictionary dataDictionary, UUID viewID, String viewName, String viewText, 83 int checkOption, UUID compSchemaId) 84 { 85 super( dataDictionary ); 86 87 uuid = viewID; 88 this.viewText = viewText; 89 this.viewName = viewName; 90 91 92 if (SanityManager.DEBUG) 93 { 94 if (checkOption != ViewDescriptor.NO_CHECK_OPTION) 95 { 96 SanityManager.THROWASSERT("checkOption (" + checkOption + 97 ") expected to be " + ViewDescriptor.NO_CHECK_OPTION); 98 } 99 } 100 this.checkOption = checkOption; 101 this.compSchemaId = compSchemaId; 102 } 103 104 108 113 public UUID getUUID() 114 { 115 return uuid; 116 } 117 118 123 public void setUUID(UUID uuid) 124 { 125 this.uuid = uuid; 126 } 127 128 134 public String getViewText() 135 { 136 return viewText; 137 } 138 139 144 public void setViewName(String name) 145 { 146 viewName = name; 147 } 148 149 156 public int getCheckOptionType() 157 { 158 return checkOption; 159 } 160 161 167 public UUID getCompSchemaId() 168 { 169 return compSchemaId; 170 } 171 172 173 177 182 public DependableFinder getDependableFinder() 183 { 184 return getDependableFinder(StoredFormatIds.VIEW_DESCRIPTOR_FINDER_V01_ID); 185 } 186 187 192 public String getObjectName() 193 { 194 return viewName; 195 } 196 197 202 public UUID getObjectID() 203 { 204 return uuid; 205 } 206 207 212 public String getClassType() 213 { 214 return Dependable.VIEW; 215 } 216 217 225 public boolean isValid() 226 { 227 return true; 228 } 229 230 239 public void prepareToInvalidate(Provider p, int action, 240 LanguageConnectionContext lcc) 241 throws StandardException 242 { 243 switch ( action ) 244 { 245 249 case DependencyManager.CREATE_INDEX: 250 case DependencyManager.DROP_INDEX: 251 case DependencyManager.CREATE_CONSTRAINT: 252 case DependencyManager.ALTER_TABLE: 253 case DependencyManager.CREATE_TRIGGER: 254 case DependencyManager.DROP_TRIGGER: 255 256 case DependencyManager.BULK_INSERT: 257 case DependencyManager.COMPRESS_TABLE: 258 case DependencyManager.RENAME_INDEX: 259 case DependencyManager.UPDATE_STATISTICS: 260 case DependencyManager.DROP_STATISTICS: 261 case DependencyManager.TRUNCATE_TABLE: 262 269 case DependencyManager.SET_CONSTRAINTS_ENABLE: 270 case DependencyManager.SET_TRIGGERS_ENABLE: 271 case DependencyManager.REVOKE_PRIVILEGE: 276 break; 277 278 default: 286 287 DependencyManager dm; 288 289 dm = getDataDictionary().getDependencyManager(); 290 throw StandardException.newException(SQLState.LANG_PROVIDER_HAS_DEPENDENT_VIEW, 291 dm.getActionString(action), 292 p.getObjectName(), viewName); 293 294 } } 296 297 305 public void makeInvalid(int action, LanguageConnectionContext lcc) 306 throws StandardException 307 { 308 switch ( action ) 309 { 310 313 case DependencyManager.CREATE_INDEX: 314 case DependencyManager.DROP_INDEX: 315 case DependencyManager.ALTER_TABLE: 316 case DependencyManager.CREATE_CONSTRAINT: 317 case DependencyManager.BULK_INSERT: 318 case DependencyManager.COMPRESS_TABLE: 319 case DependencyManager.SET_CONSTRAINTS_ENABLE: 320 case DependencyManager.SET_TRIGGERS_ENABLE: 321 case DependencyManager.CREATE_TRIGGER: 322 case DependencyManager.DROP_TRIGGER: 323 case DependencyManager.RENAME_INDEX: 324 case DependencyManager.UPDATE_STATISTICS: 325 case DependencyManager.DROP_STATISTICS: 326 case DependencyManager.TRUNCATE_TABLE: 327 break; 328 329 case DependencyManager.REVOKE_PRIVILEGE: 333 dropViewWork(getDataDictionary(), 334 getDataDictionary().getDependencyManager(), lcc, 335 lcc.getTransactionExecute(), 336 getDataDictionary().getTableDescriptor(uuid).getSchemaDescriptor(), 337 getDataDictionary().getTableDescriptor(uuid), false); 338 return; 339 340 default: 341 342 343 if (SanityManager.DEBUG) 344 { 345 SanityManager.THROWASSERT("did not expect to get called"); 346 } 347 break; 348 349 } 351 } 352 353 362 public void makeValid(LanguageConnectionContext lcc) 363 throws StandardException 364 { 365 } 366 367 371 376 public String toString() 377 { 378 if (SanityManager.DEBUG) 379 { 380 return "uuid: " + uuid + " viewName: " + viewName + "\n" + 381 "viewText: " + viewText + "\n" + 382 "checkOption: " + checkOption + "\n" + 383 "compSchemaId: " + compSchemaId + "\n"; 384 } 385 else 386 { 387 return ""; 388 } 389 } 390 391 public void dropViewWork(DataDictionary dd, DependencyManager dm, 392 LanguageConnectionContext lcc, TransactionController tc, 393 SchemaDescriptor sd, TableDescriptor td, boolean cascade) 394 throws StandardException 395 { 396 397 dd.dropAllColumnDescriptors(td.getUUID(), tc); 398 399 404 dm.invalidateFor(td, DependencyManager.DROP_VIEW, lcc); 405 406 407 dm.clearDependencies(lcc, this); 408 409 410 dd.dropViewDescriptor(this, tc); 411 412 413 dd.dropAllTableAndColPermDescriptors(td.getUUID(), tc); 414 415 416 dd.dropTableDescriptor(td, sd, tc); 417 } 418 419 420 } 421 | Popular Tags |