Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / sql / compile / DropIndexNode.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/DropIndexNode.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/DropIndexNode.java
new file mode 100644 (file)
index 0000000..285a8f8
--- /dev/null
@@ -0,0 +1,117 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.DropIndexNode\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.compile;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+import org.apache.derby.iapi.sql.compile.CompilerContext;\r
+import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;\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
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+\r
+/**\r
+ * A DropIndexNode is the root of a QueryTree that represents a DROP INDEX\r
+ * statement.\r
+ *\r
+ */\r
+\r
+public class DropIndexNode extends DDLStatementNode\r
+{\r
+       private ConglomerateDescriptor  cd;\r
+       private TableDescriptor                 td;\r
+\r
+       public String statementToString()\r
+       {\r
+               return "DROP INDEX";\r
+       }\r
+\r
+       /**\r
+        * Bind this DropIndexNode.  This means looking up the index,\r
+        * verifying it exists and getting the conglomerate number.\r
+        *\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       public void bindStatement() throws StandardException\r
+       {\r
+               CompilerContext                 cc = getCompilerContext();\r
+               DataDictionary                  dd = getDataDictionary();\r
+               SchemaDescriptor                sd;\r
+\r
+               sd = getSchemaDescriptor();\r
+\r
+               if (sd.getUUID() != null) \r
+                       cd = dd.getConglomerateDescriptor(getRelativeName(), sd, false);\r
+\r
+               if (cd == null)\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND, getFullName());\r
+               }\r
+\r
+               /* Get the table descriptor */\r
+               td = getTableDescriptor(cd.getTableID());\r
+\r
+               /* Drop index is not allowed on an index backing a constraint -\r
+                * user must drop the constraint, which will drop the index.\r
+                * Drop constraint drops the constraint before the index,\r
+                * so it's okay to drop a backing index if we can't find its\r
+                * ConstraintDescriptor.\r
+                */\r
+               if (cd.isConstraint())\r
+               {\r
+                       ConstraintDescriptor conDesc;\r
+                       String constraintName;\r
+\r
+                       conDesc = dd.getConstraintDescriptor(td, cd.getUUID());\r
+                       if (conDesc != null)\r
+                       {\r
+                               constraintName = conDesc.getConstraintName();\r
+                               throw StandardException.newException(SQLState.LANG_CANT_DROP_BACKING_INDEX, \r
+                                                                               getFullName(), constraintName);\r
+                       }\r
+               }\r
+\r
+               /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */\r
+               cc.createDependency(td);\r
+               cc.createDependency(cd);\r
+       }\r
+\r
+       // inherit generate() method from DDLStatementNode\r
+\r
+       /**\r
+        * Create the Constant information that will drive the guts of Execution.\r
+        *\r
+        * @exception StandardException         Thrown on failure\r
+        */\r
+       public ConstantAction   makeConstantAction() throws StandardException\r
+       {\r
+               return  getGenericConstantActionFactory().getDropIndexConstantAction( getFullName(),\r
+                                                                                        getRelativeName(),\r
+                                                                                        getRelativeName(),\r
+                                                                                        getSchemaDescriptor().getSchemaName(),\r
+                                                                                        td.getUUID(),\r
+                                                                                        td.getHeapConglomerateId());\r
+       }\r
+}\r