KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
2     queryspecification;
3
4 import java.util.*;
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import com.daffodilwoods.daffodildb.server.sql99.common.*; //import com.daffodilwoods.daffodildb.server.sql99.common.Properties;
7
import com.daffodilwoods.daffodildb.server.sql99.utils.*;
8 import com.daffodilwoods.database.resource.*;
9 import com.daffodilwoods.database.utility.P;
10
11 /**
12  * This class represents the selected columns whose values are to shown in the
13      * resultset. SelectList formed with different selectsublist seperated by comma.
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 selectlist
22     implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,
23     TypeConstants {
24   /**
25    * It represents list of selectsublist which forms complete selectlist.
26    */

27   public selectsublist[] _OptRepScomma94843605selectsublist0;
28   /**
29    * It represents columns involved in selectList
30    */

31   private ColumnDetails[] columnDetails;
32   /**
33        * Note:- documentation of following method are present in QueryExpressionBody
34    * @param tableDetails
35    * @return
36    * @throws DException
37    */

38   public _Reference[] getReferences(TableDetails[] tableDetails) throws
39       DException {
40     if (_OptRepScomma94843605selectsublist0 == null) {
41       return null;
42     }
43     int length = _OptRepScomma94843605selectsublist0.length;
44     _Reference[] ref = null;
45     for (int i = 0; i < length; i++) {
46       ref = GeneralPurposeStaticClass.getJointReferences(ref,
47           _OptRepScomma94843605selectsublist0[i].getReferences(tableDetails));
48     }
49     return ref;
50   }
51
52   public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
53      ArrayList result = new ArrayList();
54      if (_OptRepScomma94843605selectsublist0 == null) {
55       return null;
56       }
57      for (int i = 0; i < _OptRepScomma94843605selectsublist0.length; i++) {
58         Object JavaDoc[] param = _OptRepScomma94843605selectsublist0[i].getParameters(object);
59         if (param != null) {
60            result.addAll(Arrays.asList(param));
61         }
62      }
63      return result.size() == 0 ? null : result.toArray(new Object JavaDoc[0]);
64   }
65
66
67   public ColumnDetails[] getColumnDetails() throws DException {
68     if (columnDetails == null) {
69       ArrayList aList = new ArrayList(5);
70       for (int i = 0; i < _OptRepScomma94843605selectsublist0.length; i++) {
71         aList.addAll(Arrays.asList(_OptRepScomma94843605selectsublist0[i].
72                                    getColumnDetails()));
73       }
74       columnDetails = (ColumnDetails[]) aList.toArray(new ColumnDetails[0]);
75       for (int i = 0; i < columnDetails.length; i++) {
76         columnDetails[i].setAsSelectListColumn();
77       }
78     }
79     return columnDetails;
80   }
81
82   public ParameterInfo[] getParameterInfo() throws DException {
83     if (_OptRepScomma94843605selectsublist0 == null) {
84       return null;
85     }
86     /*done by vibha on 20-08-2004 to solve bug no 11462 */
87     int length = _OptRepScomma94843605selectsublist0.length;
88     ParameterInfo[] p1 = null;
89     ArrayList a1 = new ArrayList();
90     for (int i = 0; i < length; i++) {
91       p1 = _OptRepScomma94843605selectsublist0[i].getParameterInfo();
92       /*Done by vibha on 16-09-2004 to solve bug no 11830*/
93       if(p1 != null){
94         for (int j = 0; j < p1.length; j++) {
95           if (p1[j].getQuestionMark()) {
96             if (p1[j].getDataType() == -1)
97               p1[j].setDataType(Datatypes.VARCHAR);
98           }
99            a1.add(p1[j]);
100         }
101
102         }
103     }
104
105     return (ParameterInfo[]) a1.toArray(new ParameterInfo[0]);
106
107   }
108
109   public _Reference[] checkSemantic(_ServerSession parent) throws DException {
110     _Reference[] refArray = null;
111     for (int i = 0; i < _OptRepScomma94843605selectsublist0.length; i++) {
112       refArray = GeneralPurposeStaticClass.getJointReferences(refArray,
113           _OptRepScomma94843605selectsublist0[i].checkSemantic(parent));
114     }
115
116     /* Done by Kaushik on 20/08/2004 for Sequence releted work as told by Mr. Neeraj Khanna*/
117     if (refArray != null) {
118       ArrayList arr = new ArrayList();
119       for (int i = 0; i < refArray.length; i++) {
120         if (refArray[i].getReferenceType() != SimpleConstants.SEQUENCE) {
121           arr.add(refArray[i]);
122         }
123       }
124       return (_Reference[]) arr.toArray(new _Reference[0]);
125     }
126     return null;
127
128   }
129
130   public void getColumnsIncluded(ArrayList aList) throws DException {
131     for (int i = 0; i < _OptRepScomma94843605selectsublist0.length; i++) {
132       _OptRepScomma94843605selectsublist0[i].getColumnsIncluded(aList);
133     }
134   }
135
136   public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.
137
      DException {
138     ArrayList aList = new ArrayList();
139     for (int i = 0; i < _OptRepScomma94843605selectsublist0.length; i++) {
140       Object JavaDoc result = _OptRepScomma94843605selectsublist0[i].run(object);
141       if (result != null) {
142         if (result instanceof Object JavaDoc[]) {
143           aList.addAll(Arrays.asList( (Object JavaDoc[]) result));
144         }
145         else {
146           aList.add(result);
147         }
148       }
149     }
150     return (Object JavaDoc[]) aList.toArray(new Object JavaDoc[0]);
151   }
152
153   /**
154    * calculate the derived column from selectsublist. It also marks that column
155    * is included in select list.
156    * return array of columndetails
157    * @return
158    * @throws DException
159    */

160
161   public ColumnDetails[] getDerivedColumnDetails() throws DException {
162     int length = _OptRepScomma94843605selectsublist0.length;
163     ArrayList list = new ArrayList();
164     for (int i = 0; i < length; i++) {
165       ColumnDetails[] cd = null;
166       try {
167         cd = _OptRepScomma94843605selectsublist0[i].getDerivedColumnDetails();
168       }
169       catch (DException ex) {
170         if (ex.getDseCode().equalsIgnoreCase("DSE3574")) {
171           continue;
172         }
173         else {
174           throw ex;
175         }
176       }
177       for (int j = 0; j < cd.length; j++) {
178         if (cd[j].getQuestion()) {
179           cd[j].setDatatype(Datatypes.VARCHAR);
180           cd[j].setSize(256);//Done to solve 12423, 12397,12401
181
}
182         cd[j].setAsSelectListColumn();
183         list.add(cd[j]);
184       }
185     }
186     return (ColumnDetails[]) list.toArray(new ColumnDetails[list.size()]);
187   }
188
189   public String JavaDoc toString() {
190     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
191     sb.append(" ");
192     sb.append(_OptRepScomma94843605selectsublist0[0]);
193     for (int i = 1; i < _OptRepScomma94843605selectsublist0.length; i++) {
194       sb.append(",").append(_OptRepScomma94843605selectsublist0[i]);
195     }
196     return sb.toString();
197   }
198
199   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
200     selectlist tempClass = new selectlist();
201     if (_OptRepScomma94843605selectsublist0 != null) {
202       selectsublist[] temp_OptRepScomma94843605selectsublist0 = new
203           selectsublist[_OptRepScomma94843605selectsublist0.length];
204       for (int i = 0; i < _OptRepScomma94843605selectsublist0.length; i++) {
205         temp_OptRepScomma94843605selectsublist0[i] = (selectsublist)
206             _OptRepScomma94843605selectsublist0[i].clone();
207       }
208       tempClass._OptRepScomma94843605selectsublist0 =
209           temp_OptRepScomma94843605selectsublist0;
210     }
211     return tempClass;
212   }
213
214 }
215
Popular Tags