Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / MyDerby-10.3 / java / engine / org / apache / derby / impl / sql / execute / SetSchemaConstantAction.java
diff --git a/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/execute/SetSchemaConstantAction.java b/JMCR-Stable/real-world application/MyDerby-10.3/java/engine/org/apache/derby/impl/sql/execute/SetSchemaConstantAction.java
new file mode 100644 (file)
index 0000000..6daef5a
--- /dev/null
@@ -0,0 +1,125 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.execute.SetSchemaConstantAction\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
+\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+\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
+import org.apache.derby.iapi.sql.ParameterValueSet;\r
+import org.apache.derby.iapi.sql.StatementType;\r
+\r
+import org.apache.derby.iapi.types.DataValueDescriptor;\r
+\r
+import org.apache.derby.iapi.reference.Limits;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.sql.Activation;\r
+\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+/**\r
+ *     This class describes actions that are ALWAYS performed for a\r
+ *     SET SCHEMA Statement at Execution time.\r
+ *\r
+ */\r
+\r
+class SetSchemaConstantAction implements ConstantAction\r
+{\r
+\r
+       private final String                                    schemaName;\r
+       private final int                                               type;   \r
+       \r
+       // CONSTRUCTORS\r
+\r
+       /**\r
+        * Make the ConstantAction for a SET SCHEMA statement.\r
+        *\r
+        *  @param schemaName   Name of schema.\r
+        *  @param type         type of set schema (e.g. SET_SCHEMA_DYNAMIC, SET_SCHEMA_USER)\r
+        */\r
+       SetSchemaConstantAction(String schemaName, int type)\r
+       {\r
+               this.schemaName = schemaName;\r
+               this.type = type;\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
+               // if the error happens after we have figured out the schema name for\r
+               // dynamic we want to use it rather than ?\r
+               return "SET SCHEMA " + ((type == StatementType.SET_SCHEMA_USER) ? "USER" : \r
+                               ((type == StatementType.SET_SCHEMA_DYNAMIC && schemaName == null) ? "?" : 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;\r
+               DataDictionary                          dd;\r
+\r
+               // find the language context.\r
+               lcc = activation.getLanguageConnectionContext();\r
+\r
+               dd = lcc.getDataDictionary();\r
+               String thisSchemaName = schemaName;\r
+               if (type == StatementType.SET_SCHEMA_DYNAMIC)\r
+               {\r
+                       ParameterValueSet pvs = activation.getParameterValueSet();\r
+                       DataValueDescriptor dvs = pvs.getParameter(0);\r
+                       thisSchemaName = dvs.getString();\r
+                       //null parameter is not allowed\r
+                       if (thisSchemaName == null || thisSchemaName.length() > Limits.MAX_IDENTIFIER_LENGTH)\r
+                               throw StandardException.newException(SQLState.LANG_DB2_REPLACEMENT_ERROR, "CURRENT SCHEMA");\r
+               }\r
+               else if (type == StatementType.SET_SCHEMA_USER)\r
+               {\r
+                       thisSchemaName = lcc.getAuthorizationId();\r
+               }\r
+               // if schemaName is null, sd will be null and default schema will be used\r
+               SchemaDescriptor sd = dd.getSchemaDescriptor(thisSchemaName, null, true);\r
+               lcc.setDefaultSchema(sd);\r
+       }\r
+}\r