--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.SetSchemaNode\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.reference.ClassName;\r
+import org.apache.derby.iapi.services.classfile.VMOpcode;\r
+\r
+import org.apache.derby.iapi.services.context.ContextManager;\r
+import org.apache.derby.iapi.services.compiler.MethodBuilder;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.execute.ConstantAction;\r
+import org.apache.derby.iapi.sql.Activation;\r
+import org.apache.derby.iapi.sql.ResultSet;\r
+import org.apache.derby.iapi.sql.StatementType;\r
+\r
+import org.apache.derby.impl.sql.compile.ActivationClassBuilder;\r
+\r
+import java.util.Vector;\r
+\r
+\r
+/**\r
+ * A SetSchemaNode is the root of a QueryTree that \r
+ * represents a SET SCHEMA statement. It isn't\r
+ * replicated, but it generates a ConstantAction\r
+ * because it is basically easier than generating\r
+ * the code from scratch.\r
+ *\r
+ */\r
+\r
+public class SetSchemaNode extends MiscellaneousStatementNode\r
+{\r
+ private String name;\r
+ private int type;\r
+ \r
+ /**\r
+ * Initializer for a SetSchemaNode\r
+ *\r
+ * @param schemaName The name of the new schema\r
+ * @param type Type of schema name could be USER or dynamic parameter\r
+ *\r
+ */\r
+ public void init(Object schemaName, Object type)\r
+ {\r
+ this.name = (String) schemaName;\r
+ if (type != null)\r
+ this.type = ((Integer)type).intValue();\r
+ }\r
+\r
+ /**\r
+ * Convert this object to a String. See comments in QueryTreeNode.java\r
+ * for how this should be done for tree printing.\r
+ *\r
+ * @return This object as a String\r
+ */\r
+\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ return super.toString() + \r
+ (type == StatementType.SET_SCHEMA_USER ? "schemaName: \nUSER\n" :\r
+ (type == StatementType.SET_SCHEMA_DYNAMIC ? "schemaName: \n?\n" : \r
+ "schemaName: " + "\n" + name + "\n"));\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+ }\r
+\r
+ public String statementToString()\r
+ {\r
+ return "SET SCHEMA";\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().getSetSchemaConstantAction(name, type); \r
+ }\r
+ /**\r
+ * Generate code, need to push parameters\r
+ *\r
+ * @param acb The ActivationClassBuilder for the class being built\r
+ * @param mb the method for the execute() method to be built\r
+ *\r
+ * @exception StandardException Thrown on error\r
+ */\r
+\r
+ public void generate(ActivationClassBuilder acb,\r
+ MethodBuilder mb)\r
+ throws StandardException\r
+ {\r
+ //generate the parameters for the DYNAMIC SET SCHEMA\r
+ if (type == StatementType.SET_SCHEMA_DYNAMIC)\r
+ generateParameterValueSet(acb);\r
+\r
+ // The generated java is the expression:\r
+ // return ResultSetFactory.getMiscResultSet(this )\r
+\r
+ acb.pushGetResultSetFactoryExpression(mb);\r
+\r
+ acb.pushThisAsActivation(mb); // first arg\r
+\r
+ mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getMiscResultSet",\r
+ ClassName.ResultSet, 1);\r
+ }\r
+ /**\r
+ * Generate the code to create the ParameterValueSet, if necessary,\r
+ * when constructing the activation. Also generate the code to call\r
+ * a method that will throw an exception if we try to execute without\r
+ * all the parameters being set.\r
+ * \r
+ * @param acb The ActivationClassBuilder for the class we're building\r
+ */\r
+\r
+ void generateParameterValueSet(ActivationClassBuilder acb)\r
+ throws StandardException\r
+ {\r
+ Vector parameterList = getCompilerContext().getParameterList();\r
+ // parameter list size should be 1\r
+ if (SanityManager.DEBUG)\r
+ SanityManager.ASSERT(parameterList != null && parameterList.size() == 1);\r
+ \r
+ ParameterNode.generateParameterValueSet ( acb, 1, parameterList);\r
+ }\r
+\r
+ /**\r
+ * Returns the type of activation this class\r
+ * generates.\r
+ * \r
+ * @return NEED_PARAM_ACTIVATION or\r
+ * NEED_NOTHING_ACTIVATION depending on params\r
+ *\r
+ */\r
+ int activationKind()\r
+ {\r
+ Vector parameterList = getCompilerContext().getParameterList();\r
+ /*\r
+ ** We need parameters \r
+ ** only for those that have parameters.\r
+ */\r
+ if (type == StatementType.SET_SCHEMA_DYNAMIC)\r
+ {\r
+ return StatementNode.NEED_PARAM_ACTIVATION;\r
+ }\r
+ else\r
+ {\r
+ return StatementNode.NEED_NOTHING_ACTIVATION;\r
+ }\r
+ }\r
+}\r