KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > queryexpression > orderbyclause > sortspecification


1 package com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
2     orderbyclause;
3
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.server.sql99.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
10 import com.daffodilwoods.database.resource.*;
11
12 /**
13  * sortspeciication may be simply a columnName,qualified name of column,
14  * any expression or number constant. order by clause is made of different
15  * sort specifications.
16  * <p>Title: </p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2004</p>
19  * <p>Company: </p>
20  * @author not attributable
21  * @version 1.0
22  */

23
24 public class sortspecification
25     implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,
26     TypeConstants, TableExpressionConstants, _sortspecificationAndselectSubList {
27   /**
28    * It represents optional orderspecification ,It will be either Asc and desc.
29    */

30   public orderingspecification _Optorderingspecification0;
31   public dummyrule _Optdummyrule1;
32
33   /**
34    * It represents expression on which data is ordered.
35    */

36   public sortkey _sortkey2;
37
38   /**
39    * It represents detail of column involved in sortspecification.
40    * e.g if a+b is specified,it gives 2 columndetails a,b
41    */

42   private ColumnDetails[] columnDetails;
43
44   /**
45    * It represents one column for each sortspecification
46    * e.g if a+b is specified, it gives one column ,which is functional on
47    * which data is ordered.
48    */

49   private ColumnDetails[] keyColumnDetails;
50
51   /**
52    * Note:-See documentation of following method in _Order by clause
53    * @param parent
54    * @return
55    * @throws DException
56    */

57   public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[]
58       checkSemantic(com.daffodilwoods.daffodildb.server.serversystem.
59
                    _ServerSession parent) throws DException {
60     return _sortkey2.checkSemantic(parent);
61   }
62
63   public sortspecification() {}
64
65   public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.
66
      DException {
67     return _sortkey2.run(object);
68   }
69
70   public void setDefaultValues(_VariableValueOperations variableValueOperation) throws
71       DException {
72   }
73
74   public _Reference[] getReferences(TableDetails[] tableDetails) throws
75       DException {
76     return _sortkey2.getReferences(tableDetails);
77   }
78
79   /**
80    * Returns all the columns involved in this sortspecification.
81    * @return array of columns
82    * @throws DException
83    */

84
85   public ColumnDetails[] getColumnDetails() throws DException {
86     if (columnDetails == null) {
87       columnDetails = modifyColumnDetails(_sortkey2.getColumnDetails());
88     }
89     return columnDetails;
90   }
91
92   /**
93    * Returns one column for this sortspecification. if any expresion is
94    * involved, then it is returned as one column with type equal to functional.
95    * @param columnDetails
96    * @return
97    * @throws DException
98    */

99
100   public ColumnDetails[] getKeyColumnDetails() throws DException {
101     return _sortkey2.getKeyColumnDetails();
102   }
103
104   private ColumnDetails[] modifyColumnDetails(ColumnDetails[] columnDetails) throws
105       DException {
106     int length = columnDetails.length;
107     if (length == 1) {
108       return columnDetails;
109     }
110     ArrayList aList = new ArrayList(5);
111     for (int i = 0; i < length; i++) {
112       if (columnDetails[i].getType() != CONSTANT) {
113         aList.add(columnDetails[i]);
114       }
115     }
116     return (ColumnDetails[]) aList.toArray(new ColumnDetails[aList.size()]);
117   }
118
119   /**
120    * Returns the orderspecification(asc/desc) for this sortspecification.
121    * @return
122    * @throws DException
123    */

124
125   public boolean[] getOrderOfColumns() throws DException {
126     boolean asc = true;
127     if (_Optorderingspecification0 != null) {
128       asc = _Optorderingspecification0.toString().equalsIgnoreCase("ASC");
129     }
130     return new boolean[] {
131         asc};
132   }
133
134   public String JavaDoc toString() {
135     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
136     sb.append(" ");
137     sb.append(_sortkey2);
138     sb.append(" ");
139     if (_Optdummyrule1 != null) {
140       sb.append(_Optdummyrule1);
141     }
142     sb.append(" ");
143     if (_Optorderingspecification0 != null) {
144       sb.append(_Optorderingspecification0);
145     }
146     return sb.toString();
147   }
148
149   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
150     sortspecification tempClass = new sortspecification();
151     if (_Optorderingspecification0 != null) {
152       tempClass._Optorderingspecification0 = (orderingspecification)
153           _Optorderingspecification0.clone();
154     }
155     if (_Optdummyrule1 != null) {
156       tempClass._Optdummyrule1 = (dummyrule) _Optdummyrule1.clone();
157     }
158     tempClass._sortkey2 = (sortkey) _sortkey2.clone();
159     return tempClass;
160   }
161
162   /**
163    * See documentation of this method in queryexpressionbody
164    * @param aList
165    * @throws DException
166    */

167   public void getColumnsIncluded(ArrayList aList) throws DException {
168     _sortkey2.getColumnsIncluded(aList);
169   }
170
171   /**
172    * For documentation of underlying methods, refer the documentation of
173    * _sortspecificationAndselectSubList
174    */

175
176   public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
177     return _sortkey2.getByteComparison(object);
178   }
179
180   public ColumnDetails[] getChildColumnDetails() throws DException {
181     return getColumnDetails();
182   }
183
184   /* Method written by Kaushik on 27/08/2004 to solve bug no. 11807 */
185   public ParameterInfo[] getParameterInfo() throws DException {
186     return _sortkey2.getParameterInfo();
187   }
188
189   public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
190     return _sortkey2.getParameters(object);
191   }
192 }
193
Popular Tags