1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import org.apache.derby.iapi.services.sanity.SanityManager; 25 26 import org.apache.derby.iapi.error.StandardException; 27 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 28 29 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator; 30 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 31 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 32 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 33 import org.apache.derby.iapi.sql.dictionary.SPSDescriptor; 34 import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor; 35 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 36 37 import org.apache.derby.iapi.sql.depend.DependencyManager; 38 39 import org.apache.derby.iapi.reference.SQLState; 40 41 import org.apache.derby.iapi.sql.execute.ConstantAction; 42 43 import org.apache.derby.iapi.sql.Activation; 44 45 import org.apache.derby.iapi.store.access.TransactionController; 46 47 import org.apache.derby.catalog.UUID; 48 49 55 public class DropTriggerConstantAction extends DDLSingleTableConstantAction 56 { 57 58 private final String triggerName; 59 private final SchemaDescriptor sd; 60 61 63 71 DropTriggerConstantAction 72 ( 73 SchemaDescriptor sd, 74 String triggerName, 75 UUID tableId 76 ) 77 { 78 super(tableId); 79 this.sd = sd; 80 this.triggerName = triggerName; 81 82 if (SanityManager.DEBUG) 83 { 84 SanityManager.ASSERT(sd != null, "SchemaDescriptor is null"); 85 } 86 } 87 88 95 public void executeConstantAction( Activation activation ) 96 throws StandardException 97 { 98 TriggerDescriptor triggerd; 99 100 LanguageConnectionContext lcc = activation.getLanguageConnectionContext(); 101 DataDictionary dd = lcc.getDataDictionary(); 102 DependencyManager dm = dd.getDependencyManager(); 103 104 105 114 dd.startWriting(lcc); 115 116 TableDescriptor td = dd.getTableDescriptor(tableId); 117 if (td == null) 118 { 119 throw StandardException.newException( 120 SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, 121 tableId.toString()); 122 } 123 TransactionController tc = lcc.getTransactionExecute(); 124 lockTableForDDL(tc, td.getHeapConglomerateId(), true); 125 td = dd.getTableDescriptor(tableId); 127 if (td == null) 128 { 129 throw StandardException.newException( 130 SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, 131 tableId.toString()); 132 } 133 134 138 triggerd = dd.getTriggerDescriptor(triggerName, sd); 139 140 if (triggerd == null) 141 { 142 throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION, "TRIGGER", 143 (sd.getSchemaName() + "." + triggerName)); 144 } 145 146 152 dropTriggerDescriptor(lcc, dm, dd, tc, triggerd, activation); 153 } 154 155 public static void dropTriggerDescriptor 156 ( 157 LanguageConnectionContext lcc, 158 DependencyManager dm, 159 DataDictionary dd, 160 TransactionController tc, 161 TriggerDescriptor triggerd, 162 Activation activation 163 ) throws StandardException 164 { 165 if (SanityManager.DEBUG) 166 { 167 SanityManager.ASSERT(triggerd!=null, "trigger descriptor is null"); 168 } 169 170 dm.invalidateFor(triggerd, DependencyManager.DROP_TRIGGER, lcc); 171 172 dd.dropTriggerDescriptor(triggerd, tc); 174 175 dm.clearDependencies(lcc, triggerd); 177 178 SPSDescriptor spsd = dd.getSPSDescriptor(triggerd.getActionId()); 180 181 dm.invalidateFor(spsd, DependencyManager.DROP_TRIGGER, lcc); 184 dm.clearDependencies(lcc, spsd); 185 dd.dropSPSDescriptor(spsd, tc); 186 187 if (triggerd.getWhenClauseId() != null) 188 { 189 spsd = dd.getSPSDescriptor(triggerd.getWhenClauseId()); 190 dm.invalidateFor(spsd, DependencyManager.DROP_TRIGGER, lcc); 191 dm.clearDependencies(lcc, spsd); 192 dd.dropSPSDescriptor(spsd, tc); 193 } 194 } 195 196 public String toString() 197 { 198 return "DROP TRIGGER "+triggerName; 201 } 202 } 203 | Popular Tags |