KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > queryexpression > queryspecification > derivedcolumn


1 package com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
2     queryspecification;
3
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*; //import com.daffodilwoods.daffodildb.server.sql99.common.Properties;
8
import com.daffodilwoods.daffodildb.server.sql99.dql.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.*;
11 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*;
12 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
13 import com.daffodilwoods.database.resource.*;
14 import com.daffodilwoods.database.utility.P;
15
16 /**
17  * This class represents selectsublist. It can either be column name or
18  * an expression.
19  * <p>Title: </p>
20  * <p>Description: </p>
21  * <p>Copyright: Copyright (c) 2004</p>
22  * <p>Company: </p>
23  * @author not attributable
24  * @version 1.0
25  */

26 public class derivedcolumn
27     implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,
28     selectsublist, Datatypes, _derivedcolumn {
29   /**
30    * It represents optional As clause used to specify alias name of expression
31    * e.g select a+b As sss from tablename.
32    */

33   public asclause _Optasclause0;
34   /**
35    * It represents an expression.
36    */

37   public valueexpression _valueexpression1;
38   /**
39    * It represents columns involved in selectsublist
40    */

41   public ColumnDetails[] columnDetails;
42   /**
43    * Note:- For Documentation of following method , refer to documentation
44    * of selectsublist
45    * @param tableDetails
46    * @return
47    * @throws DException
48    */

49   public _Reference[] getReferences(TableDetails[] tableDetails) throws
50       DException {
51     return _valueexpression1.getReferences(tableDetails);
52   }
53
54   /**
55    * Returns the result of valueexpression.
56    * @param object
57    * @return
58    * @throws com.daffodilwoods.database.resource.DException
59    */

60
61   public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.
62
      DException {
63
64     return _valueexpression1.run(object);
65   }
66
67   /**
68        * This function does the semantic checking for the derived column, it calls the
69    * semantic checkning for the value expression it returns unknown references
70    * from the value expression.
71    * subquery and multiple columns are not allowed in select list.
72    * @param parent
73    * @return _Reference[]
74    * @throws DException
75    */

76   public _Reference[] checkSemantic(_ServerSession parent) throws DException {
77     _Reference[] ref = _valueexpression1.checkSemantic(parent);
78     if (_valueexpression1.getCardinality() > 1) {
79       /* Done by Kaushik on 19/08/2004 to Solve Bug 11715*/
80       throw new DException("DSE0",
81           new Object JavaDoc[] {"Multi Column Predicate is not Supported in Select List."});
82     }
83
84
85     return ref;
86   }
87
88   /**
89    * Returns one column for the expression. If more than one columns are
90    * involved in the expression, then one column with type FUNCTIONAL is
91    * returned.
92    * @return
93    * @throws DException
94    */

95
96   public ColumnDetails[] getDerivedColumnDetails() throws DException {
97     /*Error is thrown in case selectList is used in select */
98     ColumnDetails[] cdt = getColumnDetails();
99
100 if(_valueexpression1.checkForSubQuery()){
101     ColumnDetails columnDetail = new ColumnDetails();
102     String JavaDoc str = _valueexpression1.toString();
103     columnDetail.setColumn(new String JavaDoc[] {str});
104     columnDetail.setType(SCALARSUBQUERY);
105     columnDetail.setObject(this);
106     columnDetail.setExpression(str);
107     if (_Optasclause0 != null) {
108       columnDetail.setAliasName( (String JavaDoc) _Optasclause0.run(null));
109      }
110      return new ColumnDetails[] { columnDetail };
111     }
112
113
114     if (columnDetails.length == 1) { // negativeflag check for -A, to make this col as functional
115

116       /*next 2 lines done by Kaushik on 23/07/2004 */
117       ColumnDetails columnDetail = getClonedCD(columnDetails[0]);
118
119       int type = columnDetail.getType();
120       if (type == SCALARFUNCTION || type == CONSTANT) {
121         columnDetail.setObject(this);
122
123       }
124       if (columnDetail.checkNegativeValueFlag()) {
125         if (type == REFERENCE || type == CONSTANT) {
126           columnDetail.setType(FUNCTIONAL);
127         }
128         columnDetail.setObject(this);
129       }
130       if (_Optasclause0 != null) {
131         columnDetail.setAliasName( (String JavaDoc) _Optasclause0.run(null));
132       }
133       columnDetail.setExpression(_valueexpression1.toString());
134       return new ColumnDetails[] {
135           columnDetail};
136     }
137
138     ColumnDetails columnDetail = new ColumnDetails();
139     String JavaDoc str = _valueexpression1.toString();
140     columnDetail.setColumn(new String JavaDoc[] {str});
141     columnDetail.setType(FUNCTIONAL);
142     columnDetail.setObject(this);
143     columnDetail.setExpression(str);
144     if (_Optasclause0 != null) {
145       columnDetail.setAliasName( (String JavaDoc) _Optasclause0.run(null));
146     }
147     ColumnDetails[] cdtoret = new ColumnDetails[] {
148         columnDetail};
149     /*Done by vibha to solve bug no 11663*/
150     if (cdtoret[0].getDatatype() == Datatypes.BOOLEAN)
151       cdtoret[0].setSize(Datatypes.BOOLEANSIZE);
152     return cdtoret;
153   }
154
155   /**
156    * Returns the clone of the column.
157    * @param cd
158    * @return
159    * @throws DException
160    */

161
162   private ColumnDetails getClonedCD(ColumnDetails cd) throws DException {
163     try {
164       return (ColumnDetails) cd.clone();
165     }
166     catch (CloneNotSupportedException JavaDoc ex) {
167       throw new DException("DSE0", new Object JavaDoc[] {"Clone Not Supported"});
168     }
169   }
170
171   public String JavaDoc toString() {
172     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
173     sb.append(" ");
174     sb.append(_valueexpression1);
175     sb.append(" ");
176     if (_Optasclause0 != null) {
177       sb.append(_Optasclause0);
178     }
179     return sb.toString();
180   }
181
182   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
183     derivedcolumn tempClass = new derivedcolumn();
184     if (_Optasclause0 != null) {
185       tempClass._Optasclause0 = (asclause) _Optasclause0.clone();
186     }
187     tempClass._valueexpression1 = (valueexpression) _valueexpression1.clone();
188     return tempClass;
189   }
190
191   /**
192    * Returns the Aggregate represented by this expression. It is needed when
193    * valueexpression is negative of any aggregate function. Then in this case
194    * _Aggregate is required from this class, which in turn delegate the call to
195    * generalsetfunction.
196    * @return
197    * @throws DException
198    */

199
200   public _Aggregate getExecutable() throws DException {
201     return ( (setfunctionspecification) columnDetails[0].getObject()).
202         getExecutable();
203   }
204
205   /**
206    * For documentation of underlying methods, refer the documentation of
207    * selectsublist
208    * @param object
209    * @return
210    * @throws DException
211    */

212
213   public ColumnDetails[] getColumnDetails() throws DException {
214     columnDetails = columnDetails != null ? columnDetails :
215         _valueexpression1.getColumnDetails();
216     return columnDetails;
217   }
218
219   public ParameterInfo[] getParameterInfo() throws DException {
220     return _valueexpression1.getParameterInfo();
221   }
222
223   public void getColumnsIncluded(ArrayList parm1) throws com.daffodilwoods.
224
      database.resource.DException {
225     _valueexpression1.getColumnsIncluded(parm1);
226   }
227
228   /**
229    * For documentation of underlying methods, refer to documentation of
230    * _sortspecificationAndselectSubList
231    */

232
233   public ByteComparison getByteComparison(Object JavaDoc object) throws DException {
234     return _valueexpression1.getByteComparison(object);
235   }
236
237   public ColumnDetails[] getChildColumnDetails() throws DException {
238     return getColumnDetails();
239   }
240    public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
241      return _valueexpression1.getParameters(object);
242    }
243
244 }
245
Popular Tags