KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
2     orderbyclause;
3
4 import java.util.*;
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*;
7 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
8 import com.daffodilwoods.daffodildb.utils.field.*;
9 import com.daffodilwoods.database.resource.*;
10 import com.daffodilwoods.database.utility.P;
11
12 /**
13  * This represents expression on which result is sorted.
14  * <p>Title: </p>
15  * <p>Description: </p>
16  * <p>Copyright: Copyright (c) 2004</p>
17  * <p>Company: </p>
18  * @author not attributable
19  * @version 1.0
20  */

21 public class sortkey
22     implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,
23     TypeConstants, Datatypes, _sortspecificationAndselectSubList {
24   /**
25    * It is expression on which data sorted.
26    */

27   public valueexpressionwithoutboolean _sortkey0;
28
29   /**
30    * It represents detail of all column involved in sorkey expression
31    * e.g if order by a+b is specified, then columndetails of expression are a,b
32    * having length 2
33    */

34   protected ColumnDetails[] columnDetails;
35
36   /**
37    * It represents one columndetail for each sortkey.E.G if ORDER BY a+b is
38    * specified, then keycolumndetails length is 1.
39    */

40   private ColumnDetails[] keyColumnDetails;
41
42   public void setDefaultValues(_VariableValueOperations variableValueOperation) throws
43       DException {
44   }
45
46   /**
47    * Note:-see documentation of following method in _OrderByClause
48    * @param tableDetails
49    * @return
50    * @throws DException
51    */

52   public _Reference[] getReferences(TableDetails[] tableDetails) throws
53       DException {
54     return _sortkey0.getReferences(tableDetails);
55   }
56
57   public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[]
58       checkSemantic(com.daffodilwoods.daffodildb.server.serversystem.
59
                    _ServerSession parent) throws DException {
60     /*Done by Sandeep to solve the bug 12145 */
61
62     _Reference[] ref = _sortkey0.checkSemantic(parent);
63     if (_sortkey0.getCardinality() > 1)
64       throw new DException("DSE0",new Object JavaDoc[] {"Multi Column Predicate is not Supported in Order by List."});
65     return ref;
66   }
67
68   public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.
69
      DException {
70     return _sortkey0.run(object);
71   }
72
73   /**
74    * Returns one column for this sortkey. if any expresion is involved, then
75    * it is returned as one column with type equal to functional.
76    * @param columnDetails
77    * @return
78    * @throws DException
79    */

80
81   public ColumnDetails[] getKeyColumnDetails() throws DException {
82     if (keyColumnDetails == null) {
83       keyColumnDetails = modifyKeyColumnDetails(getColumnDetails());
84     }
85     return keyColumnDetails;
86   }
87
88   /**
89    * Returns one column for this sortkey. if any expresion is involved, then
90    * it is returned as one column with type equal to functional.
91    * @param columnDetails
92    * @return
93    * @throws DException
94    */

95
96   private ColumnDetails[] modifyKeyColumnDetails(ColumnDetails[] columnDetails) throws
97       DException {
98     int length = columnDetails.length;
99 /*Dst by Sandeep Kadiyan .If the column has negative sign then the type of columnDetail will be FUNCTIONL. */
100  if (length == 1 && !columnDetails[0].checkNegativeValueFlag()) { /*Dend on 17/02/2005*/
101       return columnDetails;
102     }
103     if (length == 0) {
104       throw new DException("DSE6009", null);
105     }
106
107     ColumnDetails columnDetail = new ColumnDetails();
108     columnDetail.setColumn(new String JavaDoc[] {toString()});
109     columnDetail.setType(FUNCTIONAL);
110     columnDetail.setObject(this);
111     return new ColumnDetails[] {
112         columnDetail};
113   }
114
115   /**
116    * Returns all the columns involved in this sortkey. Also if numeric
117    * constant is present, then this number is also stored in column.
118    * @return
119    * @throws DException
120    */

121
122   public ColumnDetails[] getColumnDetails() throws DException {
123     if (columnDetails == null) {
124       columnDetails = _sortkey0.getColumnDetails();
125
126       if (columnDetails.length == 1 && columnDetails[0].getType() == CONSTANT &&
127           ! (columnDetails[0].getTypeForSequence() == SEQUENCETYPE)) {
128         if (columnDetails[0].getQuestion() ||
129             columnDetails[0].getDatatype() == CHARACTER) {
130           columnDetails[0].setObject(this);
131         }
132         else {
133           FieldBase fBase = (FieldBase) _sortkey0.run(null);
134           columnDetails[0].setObject(fBase); // else for all Values Other Than Ordinal
135
}
136       }
137     }
138     return columnDetails;
139   }
140
141   /**
142    * Note:-see documentation of following method in queryexpresion body.
143    * @param aList
144    * @throws DException
145    */

146   public void getColumnsIncluded(ArrayList aList) throws DException {
147     _sortkey0.getColumnsIncluded(aList);
148   }
149
150   public void getTablesIncluded(ArrayList aList) throws DException {
151   }
152
153   public String JavaDoc toString() {
154     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
155     sb.append(" ");
156     sb.append(_sortkey0);
157     return sb.toString();
158   }
159
160   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
161     sortkey tempClass = new sortkey();
162     tempClass._sortkey0 = (valueexpressionwithoutboolean) _sortkey0.clone();
163     return tempClass;
164   }
165
166   /**
167    * For documentation of underlying methods, refer the documentation of
168    * _sortspecificationAndselectSubList
169    */

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