01: /*
02:
03: Derby - Class org.apache.derby.impl.sql.compile.OrderedColumn
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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.services.sanity.SanityManager;
25:
26: /**
27: * An ordered column has position. It is an
28: * abstract class for group by and order by
29: * columns.
30: *
31: * @author jamie
32: */
33: public abstract class OrderedColumn extends QueryTreeNode {
34: protected static final int UNMATCHEDPOSITION = -1;
35: protected int columnPosition = UNMATCHEDPOSITION;
36:
37: /**
38: * Indicate whether this column is ascending or not.
39: * By default assume that all ordered columns are
40: * necessarily ascending. If this class is inherited
41: * by someone that can be desceneded, they are expected
42: * to override this method.
43: *
44: * @return true
45: */
46: public boolean isAscending() {
47: return true;
48: }
49:
50: /**
51: * Convert this object to a String. See comments in QueryTreeNode.java
52: * for how this should be done for tree printing.
53: *
54: * @return This object as a String
55: */
56: public String toString() {
57: if (SanityManager.DEBUG) {
58: return "columnPosition: " + columnPosition + "\n"
59: + super .toString();
60: } else {
61: return "";
62: }
63: }
64:
65: /**
66: * Get the position of this column
67: *
68: * @return The position of this column
69: */
70: public int getColumnPosition() {
71: return columnPosition;
72: }
73:
74: /**
75: * Set the position of this column
76: */
77: public void setColumnPosition(int columnPosition) {
78: this .columnPosition = columnPosition;
79: if (SanityManager.DEBUG) {
80: SanityManager
81: .ASSERT(
82: columnPosition > 0,
83: "Column position is "
84: + columnPosition
85: + ". This is a problem since the code to generate "
86: + " ordering columns assumes it to be one based -- i.e. "
87: + " it subtracts one");
88:
89: }
90: }
91: }
|