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 / DropAliasNode.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/DropAliasNode.java
new file mode 100644 (file)
index 0000000..ec5054c
--- /dev/null
@@ -0,0 +1,162 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.DropAliasNode\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.sql.compile.C_NodeTypes;\r
+\r
+import org.apache.derby.iapi.services.context.ContextManager;\r
+\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.monitor.Monitor;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;\r
+import org.apache.derby.iapi.sql.dictionary.DataDictionary;\r
+import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;\r
+\r
+import org.apache.derby.catalog.AliasInfo;\r
+\r
+/**\r
+ * A DropAliasNode  represents a DROP ALIAS statement.\r
+ *\r
+ */\r
+\r
+public class DropAliasNode extends DDLStatementNode\r
+{\r
+       private char aliasType;\r
+       private char nameSpace;\r
+\r
+       /**\r
+        * Initializer for a DropAliasNode\r
+        *\r
+        * @param dropAliasName The name of the method alias being dropped\r
+        * @param aliasType                             Alias type\r
+        *\r
+        * @exception StandardException\r
+        */\r
+       public void init(Object dropAliasName, Object aliasType)\r
+                               throws StandardException\r
+       {\r
+               TableName dropItem = (TableName) dropAliasName;\r
+               initAndCheck(dropItem);\r
+               this.aliasType = ((Character) aliasType).charValue();\r
+       \r
+               switch (this.aliasType)\r
+               {\r
+                       case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:\r
+                               nameSpace = AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR;\r
+                               break;\r
+\r
+                       case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:\r
+                               nameSpace = AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR;\r
+                               break;\r
+\r
+                       case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:\r
+                               nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR;\r
+                               break;\r
+\r
+                       default:\r
+                               if (SanityManager.DEBUG)\r
+                               {\r
+                                       SanityManager.THROWASSERT("bad type to DropAliasNode: "+this.aliasType);\r
+                               }\r
+               }\r
+       }\r
+\r
+       public  char    getAliasType() { return aliasType; }\r
+\r
+       public String statementToString()\r
+       {\r
+               return "DROP ".concat(aliasTypeName(aliasType));\r
+       }\r
+\r
+       /**\r
+        * Bind this DropMethodAliasNode.  \r
+        *\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+       public void bindStatement() throws StandardException\r
+       {\r
+               DataDictionary  dataDictionary = getDataDictionary();\r
+               String                  aliasName = getRelativeName();\r
+\r
+               AliasDescriptor ad = null;\r
+               SchemaDescriptor sd = getSchemaDescriptor();\r
+               \r
+               if (sd.getUUID() != null) {\r
+                       ad = dataDictionary.getAliasDescriptor\r
+                                                 (sd.getUUID().toString(), aliasName, nameSpace );\r
+               }\r
+               if ( ad == null )\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_OBJECT_DOES_NOT_EXIST, statementToString(), aliasName);\r
+               }\r
+\r
+               // User cannot drop a system alias\r
+               if (ad.getSystemAlias())\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_CANNOT_DROP_SYSTEM_ALIASES, aliasName);\r
+               }\r
+\r
+               // Statement is dependent on the AliasDescriptor\r
+               getCompilerContext().createDependency(ad);\r
+       }\r
+\r
+       // inherit generate() method from DDLStatementNode\r
+\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().getDropAliasConstantAction(getSchemaDescriptor(), getRelativeName(), nameSpace);\r
+       }\r
+\r
+       /* returns the alias type name given the alias char type */\r
+       private static String aliasTypeName( char actualType)\r
+       {\r
+               String  typeName = null;\r
+\r
+               switch ( actualType )\r
+               {\r
+                       case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:\r
+                               typeName = "PROCEDURE";\r
+                               break;\r
+                       case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:\r
+                               typeName = "FUNCTION";\r
+                               break;\r
+                       case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:\r
+                               typeName = "SYNONYM";\r
+                               break;\r
+               }\r
+               return typeName;\r
+       }\r
+}\r