KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.
2     fromclause;
3
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*;
11 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
12 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.order.*;
13 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
14 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.*;
15 import com.daffodilwoods.daffodildb.server.sql99.dql.semanticchecker.*;
16 import com.daffodilwoods.daffodildb.server.sql99.expression.*;
17 import com.daffodilwoods.daffodildb.server.sql99.token.*;
18 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
19 import com.daffodilwoods.database.resource.*;
20
21 /**
22  * Class representing from subQuery with optional derived column list.Optional
23  * derived column list not supported till now.
24  * <p>Title: From SubQuery</p>
25  * <p>Description: Class is used to represent logical view at runtime which is
26  * created as the query is executed
27  * and is destroyed as soon as query execution is finished.</p>
28  * <p>Copyright: Copyright (c) 2003</p>
29  * <p>Company: Daffodil Software Ltd</p>
30  * @author Select Team
31  * @version 1.0
32  */

33 public class derivedtableOptSRESERVEDWORD1206543922correlationnameOptparenderivedcolumnlist extends ViewAbstract implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,tableprimary {
34
35    /**
36     * Columns of From SubQuery used is specified as list.
37     * If specified, only columns related to this view are accessible.
38     */

39    public parenderivedcolumnlist _Optparenderivedcolumnlist0;
40
41    /**
42     * Logical View Name of From SubQuery
43     * Result of this view is referred by this alias Name.
44     */

45    public correlationname _correlationname1;
46
47    /**
48     * It represnets keyword as
49     */

50    public SRESERVEDWORD1206543922 _OptSRESERVEDWORD12065439222;
51
52    /**
53     * Logical View.
54     * Query involved in this variable is sued to create logical view.
55     */

56    public derivedtable _derivedtable3;
57
58    /**
59     * All tables involved in this query, also the tables involved inside logical View.
60     */

61    private TableDetails[] allTableDetails;
62
63    public void verifyValues(_VariableValueOperations variableValueOperation) throws
64        DException {
65    }
66
67    public void setDefaultValues(_VariableValueOperations variableValueOperation) throws
68        DException {
69    }
70
71    /**
72     * Returns Execution Plan associated with this logical View.
73     * Steps required to do so in order to achieve this are:
74     * 1) New ViewObject is created for the query, this view Object represents the query involved
75     * in the from SubQuery.
76     * 2) Checks for View Involved as Optimizable or not.
77     * If View is Optimizable:
78     * then Plans of query involved is pulled out to merge it with the main query, means instead of fromSubQuery
79     * involved, we rewrite the whole query in place of view.
80     * If View is not Optimizable:
81     * then Plans of query involved are not pulled out to merge it with the main query, means the query is evaluated here only
82     * and its result is only utilised.
83     * @param session
84     * @param datedFrameWork
85     * @param bvePlan
86     * @param orderPlan
87     * @param queryColumns
88     * @param conditionArray
89     * @return
90     * @throws DException
91     */

92    public _TablePlan[] getTablePlan(_ServerSession session,
93                                     _DatedFramework datedFrameWork,
94                                     _BVEPlan bvePlan, _OrderPlan orderPlan,
95                                     _QueryColumns queryColumns,
96                                     ConditionArray conditionArray) throws
97        DException {
98       return getViewPlan(session, tableDetails.cc, datedFrameWork, queryColumns,
99                          bvePlan, orderPlan, conditionArray);
100    }
101
102    public _TablePlan[] getTablePlans(_ServerSession session,
103                                      _DatedFramework datedFrameWork,
104                                      _BVEPlan bvePlan, _OrderPlan orderPlan,
105                                      _QueryColumns queryColumns,
106                                      ConditionArray conditionArray) throws
107        DException {
108       return getTablePlan(session, datedFrameWork, bvePlan, orderPlan,
109                           queryColumns, conditionArray);
110    }
111
112    protected _DatedFramework getAdjustedDatedFrameWork(_DatedFramework
113        datedFrameWork) throws DException {
114       if (datedFrameWork != null) {
115          TableDetails tableDetail = datedFrameWork.getTableDetails();
116          if (tableDetail != null) { // table will be null when codition needs to be merged in every Plan.
117
if (tableDetail == tableDetails) {
118                return datedFrameWork;
119             }
120          }
121          return null; // Null Means that condition will be merged in the every plan.
122
}
123       return datedFrameWork;
124    }
125
126    /**
127     * Creates a mapping of columnName against the actual ColumnDetails object involved in the query.
128     * Algo:
129     * 1) We retrieve selected columns involved in the from SubQuery.
130     * 2) If derived column list specified is not null, then syntaxChecking is performed that view columns Names
131     * should be equal in no to cols involved in the query.
132     * Mapping is made up of derived column specified in list against query column involved.
133     * For Example:
134     * select * from (Select a1, a1 from A) as B(b1,b2,b3)
135     * Query is not valid as derived column Name list specified is not equal in number to that of columns involved
136     * in the from SubQuery.
137     * 3) Syntax Checking is performed to check whether duplicate columns are involved in the selected columns of
138     * query involved.
139     * For Example:
140     * select * from (Select a1, a1 from A) as B
141     * Query is not valid as it contains two duplicate columns a1 in selected columns of from Subquery.
142     * 4) Mapping returned is used to change properties of columns involved in the whole query.
143     * @param queryExpression
144     * @return
145     * @throws DException
146     */

147    private Object JavaDoc[][] getMappingOfColAndCD(queryexpression queryExpression) throws
148        DException {
149       String JavaDoc[] viewColumnNames = null;
150       ColumnDetails[] selectColumns = queryExpression.getSelectedColumns();
151       if (_Optparenderivedcolumnlist0 != null) {
152          viewColumnNames = (String JavaDoc[]) _Optparenderivedcolumnlist0.run(null);
153       } else {
154          return inCaseOfAllColumnsOfQuery(selectColumns);
155       }
156       if (viewColumnNames.length != selectColumns.length) {
157          throw new DException("DSE3533", null);
158       }
159       checkViewColumns(viewColumnNames);
160       int length = viewColumnNames.length;
161       Object JavaDoc[][] mappingOfColumnAndCD = new Object JavaDoc[length][2];
162       for (int i = 0; i < length; ++i) {
163          if (!selectColumns[i].isValidForView()) {
164             throw new DException("DSE8207", null);
165          }
166          mappingOfColumnAndCD[i][0] = viewColumnNames[i];
167          mappingOfColumnAndCD[i][1] = selectColumns[i];
168       }
169       return mappingOfColumnAndCD;
170    }
171
172    /**
173     * Checks for Duplicate Columns involved in the view columns specified.
174     * @param viewColumnNames
175     * @throws DException
176     */

177    private void checkViewColumns(String JavaDoc[] viewColumnNames) throws DException {
178       for (int i = 0, length = viewColumnNames.length; i < length - 1; ++i) {
179          String JavaDoc columnName = viewColumnNames[i];
180          for (int j = i + 1; j < length; ++j) {
181             if (columnName.equalsIgnoreCase(viewColumnNames[j])) {
182                throw new DException("DSE3535", new Object JavaDoc[] {columnName, columnName});
183             }
184          }
185       }
186    }
187
188    /**
189     * Create Mapping of columnName against ColumnDetails of query in case when derived column list is not specified
190     * @param viewColumnNames
191     * @throws DException
192     */

193    private Object JavaDoc[][] inCaseOfAllColumnsOfQuery(ColumnDetails[] columns) throws
194        DException {
195       int length = columns.length;
196       Object JavaDoc[][] mappingOfColumnAndCD = new Object JavaDoc[length][2];
197       for (int i = 0; i < length; ++i) {
198          if (!columns[i].isValidForView()) {
199             throw new DException("DSE3534", null);
200          }
201          mappingOfColumnAndCD[i][0] = columns[i].getAppropriateColumn();
202          mappingOfColumnAndCD[i][1] = columns[i];
203       }
204       return mappingOfColumnAndCD;
205    }
206
207    public Object JavaDoc run(Object JavaDoc object) throws DException {
208      if(_Optparenderivedcolumnlist0 == null)
209       return _derivedtable3.run(object);
210      else
211       throw new UnsupportedOperationException JavaDoc("Method run not supported");
212    }
213
214    public TableDetails[] getTableDetails(_ServerSession serverSession, ColumnDetails[] queryColumns) throws
215        DException {
216       if (tableDetails == null) {
217          tableDetails = new TableDetails();
218          tableDetails.setTableName(new String JavaDoc[] { (String JavaDoc) _correlationname1.run(null)});
219          SemanticChecker.initializeCatalogNameAndSchemaNameOfTable(tableDetails,
220              serverSession);
221          tableDetails.cc = _derivedtable3.getColumnCharacteristics(serverSession);
222          tableDetails.setTableType(TypeConstants.VIEW);
223          tableDetails.setAsFromSubQuery();
224          queryexpression queryExpression = _derivedtable3._derivedtable0.
225              _tablesubquery0._queryexpression0;
226          viewObject = new ViewObject(queryExpression,
227                                      getMappingOfColAndCD(queryExpression));
228       }
229       return new TableDetails[] {tableDetails};
230    }
231
232    public _Reference[] checkSemantic(com.daffodilwoods.daffodildb.server.serversystem._ServerSession parent, ColumnDetails[] queryColumns, boolean checkUserRight) throws DException {
233      if(_Optparenderivedcolumnlist0 != null)
234       throw new UnsupportedOperationException JavaDoc("Method not supported");
235       queryexpression queryExpression = _derivedtable3._derivedtable0.
236           _tablesubquery0._queryexpression0;
237 /*Dst by Sandeep 0n 28/01/2005 */
238       if(queryExpression.getOrderByclause()!=null)
239          throw new DException("DSE8207",null); // Order by Not Supported in View Definition
240
/*DEND*/
241     if ((queryExpression.toString().toLowerCase().indexOf("contains")) > 0 ) {
242      throw new DException("DSE8152", null);
243     }
244
245       _Reference[] references1 = _derivedtable3.checkSemantic(parent, checkUserRight);
246
247       SemanticChecker.checkForDuplicateColumnsInvolved(queryExpression.
248           getSelectedColumns());
249       return references1;
250    }
251
252    public ColumnDetails[] getColumnDetails() throws DException {
253       return _derivedtable3.getColumnDetails();
254    }
255
256    public ParameterInfo[] getParameterInfo() throws DException {
257       return _derivedtable3.getParameterInfo();
258    }
259
260    public void getColumnsIncluded(ArrayList aList) throws DException {
261       _derivedtable3.getColumnsIncluded(aList);
262    }
263
264    public void getTablesIncluded(ArrayList aList) throws DException {
265       _derivedtable3.getTablesIncluded(aList);
266    }
267
268    public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
269       return _derivedtable3.getParameters(object);
270    }
271
272    public TableDetails[] getTablesForBlankInsert() throws DException {
273       throw new java.lang.UnsupportedOperationException JavaDoc(
274           "Method getTablesForBlankInsert() not yet implemented.");
275    }
276
277    public void setTablesForInsertion(ColumnMappingHandler parm1,
278                                      _VariableValueOperations vv) throws com.
279
       daffodilwoods.database.resource.DException {
280       /**@todo Implement this com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.fromclause.tablereference method*/
281       throw new java.lang.UnsupportedOperationException JavaDoc(
282           "Method setTablesForInsertion() not yet implemented.");
283    }
284
285    public TableDetails[] getAllTableDetails() throws DException {
286       if (allTableDetails == null) {
287          allTableDetails = _derivedtable3._derivedtable0._tablesubquery0._queryexpression0.getAllTableDetails();
288       }
289       return allTableDetails;
290    }
291
292    public TableDetails[] getViewTableDetails() throws DException {
293       ArrayList list = new ArrayList();
294       list.add(tableDetails);
295       TableDetails[] tables = _derivedtable3._derivedtable0._tablesubquery0.
296           _queryexpression0.getViewTableDetails();
297       if (tables != null) {
298          list.addAll(Arrays.asList(tables));
299       }
300       return list.isEmpty() ? null :
301           (TableDetails[]) list.toArray(new TableDetails[list.size()]);
302    }
303
304    public _Reference[] getUnderlyingReferences() throws DException {
305       return null;
306    }
307
308    public String JavaDoc toString() {
309       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
310       sb.append(" ");
311       sb.append(_derivedtable3);
312       sb.append(" ");
313       if (_OptSRESERVEDWORD12065439222 != null) {
314          sb.append(_OptSRESERVEDWORD12065439222);
315       }
316       sb.append(" ");
317       sb.append(_correlationname1);
318       sb.append(" ");
319       if (_Optparenderivedcolumnlist0 != null) {
320          sb.append(_Optparenderivedcolumnlist0);
321       }
322       return sb.toString();
323    }
324
325    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
326       derivedtableOptSRESERVEDWORD1206543922correlationnameOptparenderivedcolumnlist
327           tempClass = new
328           derivedtableOptSRESERVEDWORD1206543922correlationnameOptparenderivedcolumnlist();
329       if (_Optparenderivedcolumnlist0 != null) {
330          tempClass._Optparenderivedcolumnlist0 = (parenderivedcolumnlist)
331              _Optparenderivedcolumnlist0.clone();
332       }
333       tempClass._correlationname1 = (correlationname) _correlationname1.clone();
334       if (_OptSRESERVEDWORD12065439222 != null) {
335          tempClass._OptSRESERVEDWORD12065439222 = (SRESERVEDWORD1206543922)
336              _OptSRESERVEDWORD12065439222.clone();
337       }
338       tempClass._derivedtable3 = (derivedtable) _derivedtable3.clone();
339       return tempClass;
340    }
341
342 }
343
Popular Tags