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 / BaseColumnNode.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/BaseColumnNode.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/sql/compile/BaseColumnNode.java
new file mode 100644 (file)
index 0000000..f23da80
--- /dev/null
@@ -0,0 +1,187 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.sql.compile.BaseColumnNode\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.dictionary.DataDictionary;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.reference.SQLState;\r
+\r
+import org.apache.derby.iapi.types.DataTypeDescriptor;\r
+import org.apache.derby.iapi.sql.Row;\r
+\r
+import org.apache.derby.iapi.store.access.Qualifier;\r
+\r
+import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;\r
+\r
+import org.apache.derby.iapi.services.compiler.MethodBuilder;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+/**\r
+ * A BaseColumnNode represents a column in a base table.  The parser generates a\r
+ * BaseColumnNode for each column reference.  A column refercence could be a column in\r
+ * a base table, a column in a view (which could expand into a complex\r
+ * expression), or a column in a subquery in the FROM clause.  By the time\r
+ * we get to code generation, all BaseColumnNodes should stand only for columns\r
+ * in base tables.\r
+ *\r
+ */\r
+\r
+public class BaseColumnNode extends ValueNode\r
+{\r
+       private String  columnName;\r
+\r
+       /*\r
+       ** This is the user-specified table name.  It will be null if the\r
+       ** user specifies a column without a table name.  \r
+       */\r
+       private TableName       tableName;\r
+\r
+       /**\r
+        * Initializer for when you only have the column name.\r
+        *\r
+        * @param columnName    The name of the column being referenced\r
+        * @param tableName             The qualification for the column\r
+        * @param dts                   DataTypeServices for the column\r
+        */\r
+\r
+       public void init(\r
+                                                       Object columnName,\r
+                                                       Object tableName,\r
+                                                       Object dts) throws StandardException\r
+       {\r
+               this.columnName = (String) columnName;\r
+               this.tableName = (TableName) tableName;\r
+               setType((DataTypeDescriptor) dts);\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 "columnName: " + columnName + "\n" +\r
+                               ( ( tableName != null) ?\r
+                                               tableName.toString() :\r
+                                               "tableName: null\n") +\r
+                               super.toString();\r
+               }\r
+               else\r
+               {\r
+                       return "";\r
+               }\r
+       }\r
+\r
+       /**\r
+        * Get the name of this column\r
+        *\r
+        * @return      The name of this column\r
+        */\r
+\r
+       public String getColumnName()\r
+       {\r
+               return columnName;\r
+       }\r
+\r
+       /**\r
+        * Get the user-supplied table name of this column.  This will be null\r
+        * if the user did not supply a name (for example, select a from t).\r
+        * The method will return B for this example, select b.a from t as b\r
+        * The method will return T for this example, select t.a from t\r
+        *\r
+        * @return      The user-supplied name of this column.  Null if no user-\r
+        *              supplied name.\r
+        */\r
+\r
+       public String getTableName()\r
+       {\r
+               return ( ( tableName != null) ? tableName.getTableName() : null );\r
+       }\r
+\r
+       /**\r
+        * Get the user-supplied schema name for this column's table. This will be null\r
+        * if the user did not supply a name (for example, select t.a from t).\r
+        * Another example for null return value (for example, select b.a from t as b).\r
+        * But for following query select app.t.a from t, this will return APP\r
+        *\r
+        * @return      The schema name for this column's table\r
+        */\r
+       public String getSchemaName() throws StandardException\r
+       {\r
+               return ( ( tableName != null) ? tableName.getSchemaName() : null );\r
+       }\r
+\r
+       /**\r
+        * Do the code generation for this node. Should never be called.\r
+        *\r
+        * @param acb   The ExpressionClassBuilder for the class being built\r
+        * @param mb    The method the code to place the code\r
+        *\r
+        *\r
+        * @exception StandardException         Thrown on error\r
+        */\r
+\r
+       public void generateExpression(ExpressionClassBuilder acb,\r
+                                                                                       MethodBuilder mb)\r
+                                                       throws StandardException\r
+       {\r
+               throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE,\r
+                       this.nodeHeader());\r
+       }\r
+\r
+       /**\r
+        * Return the variant type for the underlying expression.\r
+        * The variant type can be:\r
+        *              VARIANT                         - variant within a scan\r
+        *                                                        (method calls and non-static field access)\r
+        *              SCAN_INVARIANT          - invariant within a scan\r
+        *                                                        (column references from outer tables)\r
+        *              QUERY_INVARIANT         - invariant within the life of a query\r
+        *                                                        (constant expressions)\r
+        *\r
+        * @return      The variant type for the underlying expression.\r
+        */\r
+       protected int getOrderableVariantType()\r
+       {\r
+               return Qualifier.SCAN_INVARIANT;\r
+       }\r
+        \r
+    /**\r
+     * {@inheritDoc}\r
+     */\r
+       protected boolean isEquivalent(ValueNode o)\r
+       {\r
+               if (isSameNodeType(o)) \r
+               {\r
+                       BaseColumnNode other = (BaseColumnNode)o;\r
+                       return other.tableName.equals(other.tableName) \r
+                       && other.columnName.equals(columnName);\r
+               } \r
+               return false;\r
+       }\r
+}\r