Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / execute / DropIndexConstantAction.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/execute/DropIndexConstantAction.java
new file mode 100644 (file)
index 0000000..5e5f1bf
--- /dev/null
@@ -0,0 +1,176 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.execute.DropIndexConstantAction\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.iapi.services.sanity.SanityManager;\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+\r
+import org.apache.derby.iapi.sql.depend.Dependency;\r
+import org.apache.derby.iapi.sql.depend.Dependent;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.TableDescriptor;\r
+\r
+import org.apache.derby.iapi.sql.depend.DependencyManager;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+\r
+import org.apache.derby.iapi.sql.Activation;\r
+\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import java.util.Enumeration;\r
+\r
+\r
+/**\r
+ *     This class  describes actions that are ALWAYS performed for a\r
+ *     DROP INDEX Statement at Execution time.\r
+ *\r
+ */\r
+\r
+class DropIndexConstantAction extends IndexConstantAction\r
+{\r
+\r
+       private String                          fullIndexName;\r
+       private long                            tableConglomerateId;\r
+\r
+\r
+       // CONSTRUCTORS\r
+\r
+       /**\r
+        *      Make the ConstantAction for a DROP INDEX statement.\r
+        *\r
+        *\r
+        *      @param  fullIndexName           Fully qualified index name\r
+        *      @param  indexName                       Index name.\r
+        *      @param  tableName                       The table name\r
+        *      @param  schemaName                      Schema that index lives in.\r
+        *  @param  tableId                             UUID for table\r
+        *  @param  tableConglomerateId heap Conglomerate Id for table\r
+        *\r
+        */\r
+       DropIndexConstantAction(\r
+                                                               String                          fullIndexName,\r
+                                                               String                          indexName,\r
+                                                               String                          tableName,\r
+                                                               String                          schemaName,\r
+                                                               UUID                            tableId,\r
+                                                               long                            tableConglomerateId)\r
+       {\r
+               super(tableId, indexName, tableName, schemaName);\r
+               this.fullIndexName = fullIndexName;\r
+               this.tableConglomerateId = tableConglomerateId;\r
+       }\r
+\r
+       // OBJECT METHODS\r
+\r
+       public  String  toString()\r
+       {\r
+               // Do not put this under SanityManager.DEBUG - it is needed for\r
+               // error reporting.\r
+               return "DROP INDEX " + fullIndexName;\r
+       }\r
+\r
+       // INTERFACE METHODS\r
+\r
+\r
+       /**\r
+        *      This is the guts of the Execution-time logic for DROP INDEX.\r
+        *\r
+        *\r
+        * @exception StandardException         Thrown on failure\r
+        */\r
+       public void     executeConstantAction(Activation activation)\r
+                                               throws StandardException\r
+       {\r
+               TableDescriptor td;\r
+               ConglomerateDescriptor cd;\r
+\r
+               LanguageConnectionContext lcc = activation.getLanguageConnectionContext();\r
+               DataDictionary dd = lcc.getDataDictionary();\r
+               TransactionController tc = lcc.getTransactionExecute();\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
+               // need to lock heap in exclusive mode first.  Because we can't first\r
+               // shared lock the row in SYSCONGLOMERATES and later exclusively lock\r
+               // it, this is potential deadlock (track 879).  Also td need to be\r
+               // gotten after we get the lock, a concurrent thread could be modifying\r
+               // table shape (track 3804, 3825)\r
+\r
+               // older version (or target) has to get td first, potential deadlock\r
+               if (tableConglomerateId == 0)\r
+               {\r
+                       td = dd.getTableDescriptor(tableId);\r
+                       if (td == null)\r
+                       {\r
+                               throw StandardException.newException(\r
+                                       SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);\r
+                       }\r
+                       tableConglomerateId = td.getHeapConglomerateId();\r
+               }\r
+               lockTableForDDL(tc, tableConglomerateId, true);\r
+\r
+               td = dd.getTableDescriptor(tableId);\r
+               if (td == null)\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);\r
+               }\r
+\r
+               /*\r
+               ** If the schema descriptor is null, then\r
+               ** we must have just read ourselves in.  \r
+               ** So we will get the corresponding schema\r
+               ** descriptor from the data dictionary.\r
+               */\r
+               SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true) ;\r
+\r
+               /* Get the conglomerate descriptor for the index, along\r
+                * with an exclusive row lock on the row in sys.sysconglomerates\r
+                * in order to ensure that no one else compiles against the\r
+                * index.\r
+                */\r
+               cd = dd.getConglomerateDescriptor(indexName, sd, true);\r
+\r
+               if (cd == null)\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION, fullIndexName);\r
+               }\r
+\r
+               cd.drop(lcc, td);\r
+       }\r
+}\r