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 / CreateSchemaConstantAction.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/execute/CreateSchemaConstantAction.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/execute/CreateSchemaConstantAction.java
new file mode 100644 (file)
index 0000000..6cab41e
--- /dev/null
@@ -0,0 +1,146 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.execute.CreateSchemaConstantAction\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.sql.execute.ConstantAction;\r
+\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\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.conn.LanguageConnectionContext;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.sql.Activation;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+/**\r
+ *     This class describes actions that are ALWAYS performed for a\r
+ *     CREATE SCHEMA Statement at Execution time.\r
+ *\r
+ */\r
+\r
+class CreateSchemaConstantAction extends DDLConstantAction\r
+{\r
+\r
+       private final String                                    aid;    // authorization id\r
+       private final String                                    schemaName;\r
+       \r
+\r
+       // CONSTRUCTORS\r
+\r
+       /**\r
+        * Make the ConstantAction for a CREATE SCHEMA statement.\r
+        * When executed, will set the default schema to the\r
+        * new schema if the setToDefault parameter is set to\r
+        * true.\r
+        *\r
+        *  @param schemaName   Name of table.\r
+        *  @param aid                  Authorizaton id\r
+        */\r
+       CreateSchemaConstantAction(\r
+                                                               String                  schemaName,\r
+                                                               String                  aid)\r
+       {\r
+               this.schemaName = schemaName;\r
+               this.aid = aid;\r
+       }\r
+\r
+       ///////////////////////////////////////////////\r
+       //\r
+       // OBJECT SHADOWS\r
+       //\r
+       ///////////////////////////////////////////////\r
+\r
+       public  String  toString()\r
+       {\r
+               // Do not put this under SanityManager.DEBUG - it is needed for\r
+               // error reporting.\r
+               return "CREATE SCHEMA " + schemaName;\r
+       }\r
+\r
+       // INTERFACE METHODS\r
+\r
+\r
+       /**\r
+        *      This is the guts of the Execution-time logic for CREATE SCHEMA.\r
+        *\r
+        *      @see ConstantAction#executeConstantAction\r
+        *\r
+        * @exception StandardException         Thrown on failure\r
+        */\r
+       public void     executeConstantAction( Activation activation )\r
+                                               throws StandardException\r
+       {\r
+               LanguageConnectionContext lcc = activation.getLanguageConnectionContext();\r
+               DataDictionary dd = lcc.getDataDictionary();\r
+               TransactionController tc = lcc.getTransactionExecute();\r
+               DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();\r
+\r
+               SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, lcc.getTransactionExecute(), false);\r
+\r
+               //if the schema descriptor is an in-memory schema, we donot throw schema already exists exception for it.\r
+               //This is to handle in-memory SESSION schema for temp tables\r
+               if ((sd != null) && (sd.getUUID() != null))\r
+               {\r
+                       throw StandardException.newException(SQLState.LANG_OBJECT_ALREADY_EXISTS, "Schema" , schemaName);\r
+               }\r
+\r
+               UUID tmpSchemaId = dd.getUUIDFactory().createUUID();\r
+\r
+               /*\r
+               ** AID defaults to connection authorization if not \r
+               ** specified in CREATE SCHEMA (if we had module\r
+               ** authorizations, that would be the first check\r
+               ** for default, then session aid).\r
+               */\r
+               String thisAid = aid;\r
+               if (thisAid == null)\r
+               {\r
+                       thisAid = lcc.getAuthorizationId();\r
+               }\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
+               sd = ddg.newSchemaDescriptor(schemaName,\r
+                                                                       thisAid,\r
+                                                                       tmpSchemaId);\r
+\r
+               dd.addDescriptor(sd, null, DataDictionary.SYSSCHEMAS_CATALOG_NUM, false, tc);\r
+       }\r
+}\r