KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > BaseColumnNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.BaseColumnNode
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
25
26 import org.apache.derby.iapi.error.StandardException;
27 import org.apache.derby.iapi.reference.SQLState;
28
29 import org.apache.derby.iapi.types.DataTypeDescriptor;
30 import org.apache.derby.iapi.sql.Row;
31
32 import org.apache.derby.iapi.store.access.Qualifier;
33
34 import org.apache.derby.impl.sql.compile.ExpressionClassBuilder;
35
36 import org.apache.derby.iapi.services.compiler.MethodBuilder;
37 import org.apache.derby.iapi.services.sanity.SanityManager;
38
39 /**
40  * A BaseColumnNode represents a column in a base table. The parser generates a
41  * BaseColumnNode for each column reference. A column refercence could be a column in
42  * a base table, a column in a view (which could expand into a complex
43  * expression), or a column in a subquery in the FROM clause. By the time
44  * we get to code generation, all BaseColumnNodes should stand only for columns
45  * in base tables.
46  *
47  * @author Jeff Lichtman
48  */

49
50 public class BaseColumnNode extends ValueNode
51 {
52     private String JavaDoc columnName;
53
54     /*
55     ** This is the user-specified table name. It will be null if the
56     ** user specifies a column without a table name.
57     */

58     private TableName tableName;
59
60     /**
61      * Initializer for when you only have the column name.
62      *
63      * @param columnName The name of the column being referenced
64      * @param tableName The qualification for the column
65      * @param dts DataTypeServices for the column
66      */

67
68     public void init(
69                             Object JavaDoc columnName,
70                             Object JavaDoc tableName,
71                             Object JavaDoc dts) throws StandardException
72     {
73         this.columnName = (String JavaDoc) columnName;
74         this.tableName = (TableName) tableName;
75         setType((DataTypeDescriptor) dts);
76     }
77
78     /**
79      * Convert this object to a String. See comments in QueryTreeNode.java
80      * for how this should be done for tree printing.
81      *
82      * @return This object as a String
83      */

84
85     public String JavaDoc toString()
86     {
87         if (SanityManager.DEBUG)
88         {
89             return "columnName: " + columnName + "\n" +
90                 ( ( tableName != null) ?
91                         tableName.toString() :
92                         "tableName: null\n") +
93                 super.toString();
94         }
95         else
96         {
97             return "";
98         }
99     }
100
101     /**
102      * Get the name of this column
103      *
104      * @return The name of this column
105      */

106
107     public String JavaDoc getColumnName()
108     {
109         return columnName;
110     }
111
112     /**
113      * Get the user-supplied table name of this column. This will be null
114      * if the user did not supply a name (for example, select a from t).
115      * The method will return B for this example, select b.a from t as b
116      * The method will return T for this example, select t.a from t
117      *
118      * @return The user-supplied name of this column. Null if no user-
119      * supplied name.
120      */

121
122     public String JavaDoc getTableName()
123     {
124         return ( ( tableName != null) ? tableName.getTableName() : null );
125     }
126
127     /**
128      * Get the user-supplied schema name for this column's table. This will be null
129      * if the user did not supply a name (for example, select t.a from t).
130      * Another example for null return value (for example, select b.a from t as b).
131      * But for following query select app.t.a from t, this will return APP
132      *
133      * @return The schema name for this column's table
134      */

135     public String JavaDoc getSchemaName() throws StandardException
136     {
137         return ( ( tableName != null) ? tableName.getSchemaName() : null );
138     }
139
140     /**
141      * Do the code generation for this node. Should never be called.
142      *
143      * @param acb The ExpressionClassBuilder for the class being built
144      * @param mb The method the code to place the code
145      *
146      *
147      * @exception StandardException Thrown on error
148      */

149
150     public void generateExpression(ExpressionClassBuilder acb,
151                                             MethodBuilder mb)
152                             throws StandardException
153     {
154         throw StandardException.newException(SQLState.LANG_UNABLE_TO_GENERATE,
155             this.nodeHeader());
156     }
157
158     /**
159      * Return the variant type for the underlying expression.
160      * The variant type can be:
161      * VARIANT - variant within a scan
162      * (method calls and non-static field access)
163      * SCAN_INVARIANT - invariant within a scan
164      * (column references from outer tables)
165      * QUERY_INVARIANT - invariant within the life of a query
166      * (constant expressions)
167      *
168      * @return The variant type for the underlying expression.
169      */

170     protected int getOrderableVariantType()
171     {
172         return Qualifier.SCAN_INVARIANT;
173     }
174         
175     /**
176      * {@inheritDoc}
177      */

178     protected boolean isEquivalent(ValueNode o)
179     {
180         if (isSameNodeType(o))
181         {
182             BaseColumnNode other = (BaseColumnNode)o;
183             return other.tableName.equals(other.tableName)
184             && other.columnName.equals(columnName);
185         }
186         return false;
187     }
188 }
189
Popular Tags