--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.execute.DropTriggerConstantAction\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.sql.execute;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.sql.Activation;\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+import org.apache.derby.iapi.sql.depend.DependencyManager;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.SPSDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TriggerDescriptor;\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\r
+/**\r
+ * This class describes actions that are ALWAYS performed for a\r
+ * DROP TRIGGER Statement at Execution time.\r
+ *\r
+ */\r
+public class DropTriggerConstantAction extends DDLSingleTableConstantAction\r
+{\r
+\r
+ private final String triggerName;\r
+ private final SchemaDescriptor sd;\r
+\r
+ // CONSTRUCTORS\r
+\r
+ /**\r
+ * Make the ConstantAction for a DROP TRIGGER statement.\r
+ *\r
+ * @param sd Schema that stored prepared statement lives in.\r
+ * @param triggerName Name of the Trigger\r
+ * @param tableId The table upon which the trigger is defined\r
+ *\r
+ */\r
+ DropTriggerConstantAction\r
+ (\r
+ SchemaDescriptor sd,\r
+ String triggerName,\r
+ UUID tableId\r
+ )\r
+ {\r
+ super(tableId);\r
+ this.sd = sd;\r
+ this.triggerName = triggerName;\r
+\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ SanityManager.ASSERT(sd != null, "SchemaDescriptor is null");\r
+ }\r
+ }\r
+\r
+ /**\r
+ * This is the guts of the Execution-time logic for DROP STATEMENT.\r
+ *\r
+ * @see ConstantAction#executeConstantAction\r
+ *\r
+ * @exception StandardException Thrown on failure\r
+ */\r
+ public void executeConstantAction( Activation activation )\r
+ throws StandardException\r
+ {\r
+ TriggerDescriptor triggerd;\r
+\r
+ LanguageConnectionContext lcc = activation.getLanguageConnectionContext();\r
+ DataDictionary dd = lcc.getDataDictionary();\r
+\r
+ /*\r
+ ** Inform the data dictionary that we are about to write to it.\r
+ ** There are several calls to data dictionary "get" methods here\r
+ ** that might be done in "read" mode in the data dictionary, but\r
+ ** it seemed safer to do this whole operation in "write" mode.\r
+ **\r
+ ** We tell the data dictionary we're done writing at the end of\r
+ ** the transaction.\r
+ */\r
+ dd.startWriting(lcc);\r
+\r
+ TableDescriptor td = dd.getTableDescriptor(tableId);\r
+ if (td == null)\r
+ {\r
+ throw StandardException.newException(\r
+ SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,\r
+ tableId.toString());\r
+ }\r
+ TransactionController tc = lcc.getTransactionExecute();\r
+ lockTableForDDL(tc, td.getHeapConglomerateId(), true);\r
+ // get td again in case table shape is changed before lock is acquired\r
+ td = dd.getTableDescriptor(tableId);\r
+ if (td == null)\r
+ {\r
+ throw StandardException.newException(\r
+ SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,\r
+ tableId.toString());\r
+ }\r
+\r
+ /* \r
+ ** Get the trigger descriptor. We're responsible for raising\r
+ ** the error if it isn't found \r
+ */\r
+ triggerd = dd.getTriggerDescriptor(triggerName, sd);\r
+\r
+ if (triggerd == null)\r
+ {\r
+ throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION, "TRIGGER",\r
+ (sd.getSchemaName() + "." + triggerName));\r
+ }\r
+\r
+ /* \r
+ ** Prepare all dependents to invalidate. (This is there chance\r
+ ** to say that they can't be invalidated. For example, an open\r
+ ** cursor referencing a table/trigger that the user is attempting to\r
+ ** drop.) If no one objects, then invalidate any dependent objects.\r
+ */\r
+ triggerd.drop(lcc);\r
+ }\r
+\r
+ public String toString()\r
+ {\r
+ // Do not put this under SanityManager.DEBUG - it is needed for\r
+ // error reporting.\r
+ return "DROP TRIGGER "+triggerName;\r
+ }\r
+}\r