KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > tableexpression > groupbyclause


1 package com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.groupbyclause;
2
3 import java.util.*;
4 import com.daffodilwoods.daffodildb.server.sql99.common.*;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.semanticchecker.*;
7 import com.daffodilwoods.daffodildb.server.sql99.token.*;
8 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
9 import com.daffodilwoods.database.resource.*;
10 import com.daffodilwoods.database.sqlinitiator.*;
11
12 /**
13  * This class represents optional group by clause in selectquery.which provides
14  * fuctionality of grouping record on particular column speciifed in group by clause.
15  * e.g group by a
16  * <p>Title: </p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2004</p>
19  * <p>Company: </p>
20  * @author unascribed
21  * @version 1.0
22  */

23 public class groupbyclause implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, TypeConstants, TableExpressionConstants {
24
25     /**
26      * It represents group specifcation on which data is grouped.
27      */

28     public groupingspecification _groupingspecification0;
29
30     /**
31      * It represents keyword 'Group' of group by clause.
32      */

33     public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221;
34
35     /**
36      * It represents keyword 'By' of group by clause.
37      */

38     public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439222;
39
40     /**
41      * For solving group by data must be ordered,It represents order of group by.
42      */

43     private _Order groupOrder;
44
45     /**
46      * Note :-For documentation of following method refers to documentation of
47      * queryexpressionbody.
48      * @param object
49      * @return
50      * @throws com.daffodilwoods.database.resource.DException
51      */

52     public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.DException {
53       Object JavaDoc obj = _groupingspecification0.run(object);
54      return obj instanceof Object JavaDoc[] ? obj : new Object JavaDoc[]{obj};
55     }
56
57    public ColumnDetails[] getColumnDetails() throws DException {
58       return _groupingspecification0.getColumnDetails();
59    }
60
61    public void getColumnsIncluded(ArrayList aList) throws DException {
62       _groupingspecification0.getColumnsIncluded(aList);
63    }
64
65    public void getTablesIncluded(ArrayList aList) throws DException {
66
67    }
68    public ParameterInfo[] getParameterInfo() throws DException {
69       return null;
70    }
71    public _Reference[] getReferences(TableDetails[] tableDetails) throws DException {
72       return _groupingspecification0.getReferences(tableDetails);
73    }
74
75
76
77    /**
78     * This method is required to get order of group by.It also put detail of column
79     * in mapping which contain complete information of table and its corresponding
80     * columndetails.
81     * @param queryCols
82     * @return
83     * @throws DException
84     */

85    public _Order getOrder(_QueryColumns queryCols) throws DException {
86       if (groupOrder == null) {
87          ColumnDetails[] cols = getColumnDetails();
88
89   /* Done by Kaushik on 14/07/2004 to solve 'column not found' from TestHavingChecking.testDegreeChecking_10
90          start from line 89 to 105(commented line) */

91          int length=cols.length;
92          ColumnDetails[] cloned = new ColumnDetails[cols.length];
93          for (int i = 0; i < length; i++) {
94            if(cols[i].getUnderLyingReference()){
95              cloned[i]=cols[i];
96              continue;
97            }
98            try {
99              cloned[i]=(ColumnDetails)cols[i].clone();
100            }
101            catch (CloneNotSupportedException JavaDoc ex) {
102              throw new DException("DSE0", new Object JavaDoc[] {"Clone Not Supported"});
103            }
104          }
105          groupOrder = new SelectOrder(cloned);
106          addColumnsInHashMap(groupOrder.getColumnDetails(), queryCols.getQueryColsHashMap());
107       }
108       return groupOrder;
109    }
110
111    /**
112     * This method is responsible for putting detail of column involved in
113     * @param columnDetails
114     * @param mappingOfTableColumns
115     * @throws DException
116     */

117    private void addColumnsInHashMap(ColumnDetails[] columnDetails, HashMap mappingOfTableColumns) throws DException {
118       if (columnDetails == null) {
119          return;
120       }
121       for (int i = 0, length = columnDetails.length; i < length; i++) {
122          TableDetails td = columnDetails[i].getTableDetails();
123          ColumnDetails[] existing = (ColumnDetails[]) mappingOfTableColumns.get(td);
124          ColumnDetails[] result = addInArray(existing, columnDetails[i]);
125          mappingOfTableColumns.put(td, result);
126       }
127    }
128
129    /**
130     * This method is responsible for adding passed columndetail in array of column
131     * details.
132     * @param source
133     * @param toAdd
134     * @return
135     * @throws DException
136     */

137    private ColumnDetails[] addInArray(ColumnDetails[] source, ColumnDetails toAdd) throws DException {
138       if (source == null) {
139          return new ColumnDetails[] {toAdd};
140       }
141       int length = source.length;
142       ColumnDetails[] result = new ColumnDetails[length + 1];
143       System.arraycopy(source, 0, result, 0, length);
144       result[length] = toAdd;
145       return result;
146    }
147
148    public String JavaDoc toString() {
149       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
150       sb.append(" ");
151       sb.append(_SRESERVEDWORD12065439222);
152       sb.append(" ");
153       sb.append(_SRESERVEDWORD12065439221);
154       sb.append(" ");
155       sb.append(_groupingspecification0);
156       return sb.toString();
157    }
158
159    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
160       groupbyclause tempClass = new groupbyclause();
161       tempClass._groupingspecification0 = (groupingspecification) _groupingspecification0.clone();
162       tempClass._SRESERVEDWORD12065439221 = (SRESERVEDWORD1206543922) _SRESERVEDWORD12065439221.clone();
163       tempClass._SRESERVEDWORD12065439222 = (SRESERVEDWORD1206543922) _SRESERVEDWORD12065439222.clone();
164       return tempClass;
165    }
166
167
168 }
169
Popular Tags