KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.GroupByColumn
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.error.StandardException;
25
26 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
27
28 import org.apache.derby.iapi.types.TypeId;
29
30 import org.apache.derby.iapi.reference.SQLState;
31
32 import org.apache.derby.iapi.services.sanity.SanityManager;
33
34 import java.util.Vector JavaDoc;
35
36 /**
37  * A GroupByColumn is a column in the GROUP BY clause.
38  *
39  * @author jerry
40  */

41 public class GroupByColumn extends OrderedColumn
42 {
43     private ValueNode columnExpression;
44     
45     /**
46      * Initializer.
47      *
48      * @param colRef The ColumnReference for the grouping column
49      */

50     public void init(Object JavaDoc colRef)
51     {
52         this.columnExpression = (ValueNode)colRef;
53     }
54
55     /**
56      * Convert this object to a String. See comments in QueryTreeNode.java
57      * for how this should be done for tree printing.
58      *
59      * @return This object as a String
60      */

61     public String JavaDoc toString()
62     {
63         if (SanityManager.DEBUG)
64         {
65             return "Column Expression: "+columnExpression+super.toString();
66         }
67         else
68         {
69             return "";
70         }
71     }
72
73     /**
74      * Prints the sub-nodes of this object. See QueryTreeNode.java for
75      * how tree printing is supposed to work.
76      *
77      * @param depth The depth of this node in the tree
78      */

79
80     public void printSubNodes(int depth)
81     {
82         if (SanityManager.DEBUG)
83         {
84             super.printSubNodes(depth);
85
86             if (columnExpression != null)
87             {
88                 printLabel(depth, "colRef: ");
89                 columnExpression.treePrint(depth + 1);
90             }
91         }
92     }
93
94     /**
95      * Get the name of this column
96      *
97      * @return The name of this column
98      */

99     public String JavaDoc getColumnName()
100     {
101         return columnExpression.getColumnName();
102     }
103
104     /**
105      * Bind this grouping column.
106      *
107      * @param fromList The FROM list to use for binding
108      * @param subqueryList The SubqueryList we are building as we hit
109      * SubqueryNodes.
110      * @param aggregateVector The aggregate vector we build as we hit
111      * AggregateNodes.
112      *
113      * @exception StandardException Thrown on error
114      */

115
116     public void bindExpression(
117             FromList fromList,
118             SubqueryList subqueryList,
119             Vector JavaDoc aggregateVector)
120                 throws StandardException
121     {
122         /* Bind the ColumnReference to the FromList */
123         columnExpression = (ValueNode) columnExpression.bindExpression(fromList,
124                               subqueryList,
125                               aggregateVector);
126
127         // Verify that we can group on the column
128
if (columnExpression.isParameterNode())
129         {
130             throw StandardException.newException(SQLState.LANG_INVALID_COL_REF_GROUPED_SELECT_LIST,
131                     columnExpression);
132         }
133         /*
134          * Do not check to see if we can map user types
135          * to built-in types. The ability to do so does
136          * not mean that ordering will work. In fact,
137          * as of version 2.0, ordering does not work on
138          * user types.
139          */

140         TypeId ctid = columnExpression.getTypeId();
141         if (! ctid.orderable(getClassFactory()))
142         {
143             throw StandardException.newException(SQLState.LANG_COLUMN_NOT_ORDERABLE_DURING_EXECUTION,
144                             ctid.getSQLTypeName());
145         }
146     }
147
148     public ValueNode getColumnExpression()
149     {
150         return columnExpression;
151     }
152
153     public void setColumnExpression(ValueNode cexpr)
154     {
155         this.columnExpression = cexpr;
156         
157     }
158 }
159
Popular Tags