KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
2     queryspecification;
3
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.common.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
11 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
12 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.*;
13 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
14 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
15 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.*;
16 import com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata.*;
17 import com.daffodilwoods.daffodildb.server.sql99.dql.semanticchecker.*;
18 import com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.*;
19 import com.daffodilwoods.daffodildb.server.sql99.expression.
20     booleanvalueexpression.*;
21 import com.daffodilwoods.daffodildb.server.sql99.token.*;
22 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
23 import com.daffodilwoods.daffodildb.utils.parser.*;
24 import com.daffodilwoods.database.resource.*;
25 import com.daffodilwoods.database.sqlinitiator.*;
26 import com.daffodilwoods.database.utility.P;
27 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.order._OrderPlan;
28
29 /**
30  * <p>Title: QuerySpecification</p>
31  * <p>Description:
32  * QuerySpecification represents Simple Select(Except Set Operators) having two
33  * options with Select List. That are -
34  * 1. distinct
35  * 2. Top(n)
36      * If distinct is specified,then only distinct values of select list can occur in
37  * resultset.
38  * If Top(n) is specified, then only n top rows can occur in resultset. if n is
39  * greater than the total number of rows, then only that many rows will form
40  * the resultset.
41      * This class provides the functionality of semantic checking and Execution Plan.
42  * </p>
43  * <p>Copyright: Copyright (c) 2003</p>
44  * <p>Company: Daffodil S/W Ltd.</p>
45  * @author SelectTeam
46  * @version 1.0
47  */

48
49 public class queryspecification
50     implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter,
51     simpletable, TypeConstants {
52
53   /**
54    * Represents the 'from clause', 'where clause', 'groupby clause', 'having
55    * clause' of select query.
56    */

57
58   public tableexpression _tableexpression0;
59
60   /**
61    * Represents the selectlist of select query.
62    */

63
64   public selectlist _selectlist1;
65
66   /**
67    * Represents top function of select query.It is optional
68    */

69
70   public topfunction _Opttopfunction2;
71
72   /**
73    * Represents the distinct/all option of select list. It is optional. If
74    * not present, then ALL is implicit.
75    */

76
77   public setquantifier _Optsetquantifier3;
78
79   /**
80    * Represents 'SELECT' keyword.
81    */

82
83   public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439224;
84
85   /**
86    * Represents the columns involved in select list.
87    */

88
89   private ColumnDetails[] selectListColumnDetails;
90
91   /**
92    * Represents the object, through which semantic checking is performed.
93    */

94
95   private SemanticChecker semanticChecker;
96
97   /**
98    * Represents whether distinct is present or not.
99    */

100
101   private boolean isDistinct;
102
103   /**
104    * Represents the columns of any subquery involved in this query, whose
105    * values are to be provided by this query.
106    */

107
108   private _Reference[] underlyingReferencesSolvableByCurrentIterator;
109
110   /**
111    * Represents order by clause.
112    */

113
114   private _OrderByClause orderByClause;
115
116   /**
117    * This method initializes all the queryColumns of the query.
118    * If this query is involved in view definition, then it also includes the
119    * columns of upward query in which this view is used.
120    * This is done so as to map the columns to base level table.
121    * @return _QueryColumn
122    * @throws DException
123    */

124
125   private _QueryColumns initializeQueryColumns(ColumnDetails[]
126                                                cdsWithActualTableDetails) throws
127       DException {
128     HashMap mappingOfTableColumns = semanticChecker.
129         getMappingOfTableDetailsAndColumnsBelonging();
130     addColumnsInHashMap(cdsWithActualTableDetails, mappingOfTableColumns);
131
132
133     addUnderLyingRefInHashMap(mappingOfTableColumns);
134
135
136     QueryColumns queryColumns = new QueryColumns(mappingOfTableColumns);
137     queryColumns.setHasRecordMapping(semanticChecker.getHasRecordMapping());
138     return queryColumns;
139   }
140
141   /**
142    * This methods takes a TableExpressionPlan as an argument and then check
143    * for GroupByPlan and finaly returns QuerySpecification Plan.
144    * @param tableExpressionTablePlan
145    * @param session
146    * @param order
147    * @return QuerySpecificationPlan
148    * @throws DException
149    */

150
151   private _TablePlan getPlan(_TablePlan tableExpressionTablePlan,
152                              _ServerSession session, _Order order) throws
153       DException {
154
155     TableDetails[] tableDetails = getTableDetails();
156     _Reference[] selectReferences = _selectlist1.getReferences(tableDetails);
157     tableExpressionTablePlan = createGroupByPlan(tableExpressionTablePlan,
158                                                  session);
159     QuerySpecificationPlan plan = new QuerySpecificationPlan(createDistinctPlan(
160         tableExpressionTablePlan, selectReferences), selectListColumnDetails,
161         semanticChecker, selectReferences, _Opttopfunction2, _tableexpression0, null, this);
162     plan.setOrder(order);
163     return plan;
164   }
165
166   /**
167    * This method adds all the columns present in query. This method
168    * is different from getColumnDetails as getColumnDetails returns the
169    * columns belong to this query while this method returns all the
170    * columnDetails of this query as well as underlying query(either
171    * view is present or subQuery present in condition)
172    * This method is needed by DDL.
173    * @param aList
174    * @throws DException
175    */

176
177   public void getColumnsIncluded(ArrayList aList) throws DException {
178     _selectlist1.getColumnsIncluded(aList);
179     _tableexpression0.getColumnsIncluded(aList);
180   }
181
182   /**
183    * This method adds all the Tables present in query. This method
184    * is different from getTableDetails as getTableDetails returns the
185    * tables belong to this query while this method returns all the
186    * TableDetails of this query as well as underlying query(either
187    * view is present or subQuery present in condition)
188    * This method is needed by DDL.
189    * @param aList
190    * @throws DException
191    */

192
193   public void getTablesIncluded(ArrayList aList) throws DException {
194     _tableexpression0.getTablesIncluded(aList);
195   }
196
197   public ColumnDetails[] getColumnDetails() throws DException {
198     return semanticChecker.getDerivedColumnDetails();
199   }
200
201   /**
202    * This method is needed for Browser, when Parameterized query is fired from
203    * Browser.
204    * With the help of ParameterInfo Browser open ups daialog box
205    * (labelled by its corresponding name) for each question mark to put the
206    * values of question mark. If no name is specified for question mark, then
207    * Expr0 to ExprN is the name given to all question marks.
208    * @return ParameterInfo
209    * @throws DException
210    */

211
212   public ParameterInfo[] getParameterInfo() throws DException {
213     ParameterInfo[] pi = _tableexpression0.getParameterInfo();
214     ParameterInfo[] arr = _selectlist1.getParameterInfo();
215
216     if (pi == null && arr == null)
217       return null;
218     int j = 0;
219     ArrayList aList = new ArrayList(5);
220
221     if (arr != null) {
222       for (int i = 0; i < arr.length; i++) {
223         if (arr[i].getQuestionMark()) {
224           if (arr[i].getName() == null) {
225             arr[i].setName("Expr" + j++);
226           }
227           aList.add(arr[i]);
228         }
229         else if (arr[i].getSubQuery()) {
230              GeneralPurposeStaticClass.addRecursivelyParameterInfoOfSubquery(aList,arr[i].getParameterInfoArray(),j);
231         }
232
233       }
234     }
235
236     if (pi != null) {
237       for (int i = 0; i < pi.length; i++) {
238         if (pi[i].getQuestionMark()) {
239           if (pi[i].getName() == null) {
240             pi[i].setName("Expr" + j++);
241           }
242           aList.add(pi[i]);
243         }
244       }
245     }
246
247         return aList.size() == 0 ? null :
248         (ParameterInfo[]) aList.toArray(new ParameterInfo[0]);
249   }
250
251   /**
252    * This methods returns all the QuestionMarks.
253    * @param object
254    * @return
255    * @throws DException
256    */

257
258   public Object JavaDoc[] getParameters(Object JavaDoc object) throws DException {
259     Object JavaDoc[] obj1 = _selectlist1.getParameters(object);
260     Object JavaDoc[] obj2 = _tableexpression0.getParameters(object);
261     return GeneralPurposeStaticClass.getCombinedArray(obj1,obj2);
262   }
263
264
265   /**
266        * This method returns the information of groupBy columns which are primary keys.
267        * It is needed because only those columns of groupBy which are also primary keys
268    * can be updated through ResultSet.
269    * @return
270    * @throws DException
271    */

272
273   public String JavaDoc[] getGroupByPrimaryColumns() throws DException {
274     ArrayList list = new ArrayList();
275     semanticChecker.getGroupByPrimaryColumns(list);
276     String JavaDoc[] groupByprimaryColumns = null;
277     if (!list.isEmpty()) {
278       groupByprimaryColumns = (String JavaDoc[]) list.toArray(new String JavaDoc[list.size()]);
279     }
280     return groupByprimaryColumns;
281   }
282
283   /**
284    * This method is needed to obtain the characteristics of select query based
285    * on the type of resultset.
286    * @param object
287    * @return
288    * @throws DException
289    */

290   public _ColumnCharacteristics getColumnCharacteristics(Object JavaDoc object) throws
291       DException {
292     switch ( ( (_ServerSession) object).getType()) {
293       case IteratorConstants.UPDATABLE:
294         return new SelectColumnCharacteristics(selectListColumnDetails,
295                                                addColumnInitialIndex(
296             getAllTableDetails()), getGroupByPrimaryColumns(),
297                                                isDistinct ||
298                                                _tableexpression0.
299                                                _Optgroupbyclause1 != null,
300                                                ( (_ServerSession) object).
301                                                getType() ==
302                                                IteratorConstants.UPDATABLE);
303       case IteratorConstants.NONSCROLLABLE:
304         return new SelectColumnCharacteristics(selectListColumnDetails,
305                                                addColumnInitialIndex(
306             getAllTableDetails()), false);
307     }
308     throw new DException("DSE3522",
309                          new Object JavaDoc[] {new Integer JavaDoc( ( (_ServerSession) object).
310         getType())});
311   }
312
313   /**
314    * Returns the mapping of tables and its starting index in the row. It is
315    * required for listener work.
316    * @param tableDetails
317    * @return
318    * @throws DException
319    */

320
321   private Object JavaDoc[][] addColumnInitialIndex(TableDetails[] tableDetails) throws
322       DException {
323     int length = tableDetails.length;
324     Object JavaDoc[][] newMapping = new Object JavaDoc[length][3];
325     int index = 1;
326     for (int i = 0; i < length; ++i) {
327       newMapping[i][0] = tableDetails[i];
328       newMapping[i][1] = tableDetails[i].cc;
329       newMapping[i][2] = new Integer JavaDoc(index);
330       index = index + tableDetails[i].cc.getColumnCount();
331     }
332     return newMapping;
333   }
334
335   /**
336    * Does the semantic checking of the query.
337    * Asks the select list and the table expression to do semantic checking and
338    * return any unknown references.
339    * An object of the semantic checker is created and its check function is called, it
340    * performs the semantic checking required.
341        * Then a check is made to see if any set quantifier (ALL | DISTICT)is present
342        * if DISTINCT is present then isdistict is set to true , ALL is the default case
343    * Gets the userdefined columns in the select list
344    *
345    * @param session
346    * @param orderClause
347    * @return _References[]
348    * @throws DException
349    */

350
351   public _Reference[] checkSemantic(_ServerSession session,
352                                     _OrderByClause orderClause,
353                                     boolean checkUserRight,
354                                     boolean checkSetOperatorPresent) throws
355       DException {
356     isDistinct = isDistinct();
357     orderByClause = orderClause;
358     semanticChecker = getSemanticChecker(session, orderClause); // returns an intialized semantic checker object
359

360
361
362
363
364     if (checkSetOperatorPresent) {
365       if (semanticChecker.containsClauseFlag)
366         throw new DException("DSE0",
367                              new Object JavaDoc[] {"Contains Not allowed in Set Query "});
368     }
369
370     ColumnDetails[] queryColumns = semanticChecker.getAllColumnsInvolvedInQuery();
371
372     semanticChecker.setTableDetails(_tableexpression0.getTableDetails(session,
373         queryColumns)); // queryColumns are passed for Supporting Natural Join.
374
semanticChecker.check(session);
375     selectListColumnDetails = semanticChecker.getDerivedColumnDetails();
376
377     _Reference[] references = GeneralPurposeStaticClass.getJointReferences(
378         _selectlist1.checkSemantic(session),
379         _tableexpression0.checkSemantic(session, queryColumns, checkUserRight)); // Shifted Before Mapping Initialisation as It is used in SetQueryColumns of View
380
ColumnDetails[] unResolvedReferences = changeReferencesToColumns(references);
381     _Reference[] underLyingReferences = semanticChecker.
382         checkForUnderLyingReferences(unResolvedReferences);
383     underLyingReferences = GeneralPurposeStaticClass.getJointReferences(
384         underLyingReferences, extractQuestionMarcks(references));
385     getUnderlyingReferencesSolvableByCurrentIterator( (_Reference[])
386         unResolvedReferences, underLyingReferences);
387     _Reference[] re = getUnderlyingReferences(underLyingReferences);
388
389
390     return re;
391   }
392
393   /**
394    * Used to check whether distinct option is present with select list or not.
395    * @return
396    * @throws DException
397    */

398
399   private boolean isDistinct() throws DException {
400     if (_Optsetquantifier3 != null) {
401       if ( ( (String JavaDoc) _Optsetquantifier3.run(null)).equalsIgnoreCase("DISTINCT")) {
402         return true;
403       }
404     }
405     return false;
406   }
407
408   /**
409    * Returns all those references which are not solvable by this query.
410    * @param underLyingReferences
411    * @return
412    * @throws DException
413    */

414
415   private _Reference[] getUnderlyingReferences(_Reference[]
416                                                underLyingReferences) throws
417       DException {
418     _Reference[] underLyingReferences1 = semanticChecker.
419         getUnderLyingReferences();
420     underLyingReferences = GeneralPurposeStaticClass.getJointReferences(
421         underLyingReferences, underLyingReferences1);
422     underLyingReferences = GeneralPurposeStaticClass.getJointReferences(
423         underLyingReferences, _tableexpression0.getUnderlyingReferences());
424     return underLyingReferences;
425   }
426
427   /**
428    * This method is used to extract all the question marks present in passed
429    * references.
430    * @param references
431    * @return _References[]
432    * @throws DException
433    */

434
435   private _Reference[] extractQuestionMarcks(_Reference[] references) throws
436       DException {
437     if (references == null) {
438       return null;
439     }
440     ArrayList aList = new ArrayList(5);
441     for (int i = 0; i < references.length; i++) {
442       if (references[i] instanceof variablecolumn) {
443         aList.add(references[i]);
444       }
445     }
446     int size = aList.size();
447     return size == 0 ? null : (_Reference[]) aList.toArray(new _Reference[size]);
448   }
449
450   /**
451    * This method is required to get those references which are instance of
452    * columndetails
453    * @param references
454    * @return ColumnDetails[]
455    * @throws DException
456    */

457   private ColumnDetails[] changeReferencesToColumns(_Reference[] references) throws
458       DException {
459     if (references == null) {
460       return null;
461     }
462     ArrayList aList = new ArrayList(5);
463     for (int i = 0; i < references.length; i++) {
464       if (references[i] instanceof ColumnDetails) {
465         aList.add(references[i]);
466       }
467     }
468     return (ColumnDetails[]) aList.toArray(new ColumnDetails[0]);
469   }
470
471   /**
472    * Returns an object of the semantic checker. It is used to perform the
473    * semantic checking of select query. It initializes the following things -
474    * table details
475    * select column details
476    * from clause column details
477    * where column details
478    * Having column details
479    * order by column details
480    * order by key column details for the case of order by A,A+B
481    * @param session
482    * @param orderByClause
483    * @return SemanticChecker
484    * @throws DException
485    */

486   private SemanticChecker getSemanticChecker(_ServerSession session,
487                                              _OrderByClause orderByClause) throws
488       DException {
489     ColumnDetails[] selectCD = _selectlist1.getColumnDetails();
490     ColumnDetails[] fromCD = _tableexpression0.getFromClauseColumnDetails();
491     ColumnDetails[] whereCD = _tableexpression0.getWhereClauseColumnDetails();
492     ColumnDetails[] groupCD = _tableexpression0.getGroupByColumnDetails();
493     ColumnDetails[] havingCD = _tableexpression0.getHavingClauseColumnDetails();
494     ColumnDetails[] orderCD = orderByClause != null ?
495         orderByClause.getColumnDetails()
496         : null;
497     ColumnDetails[] orderKeyCD = orderByClause != null ?
498         orderByClause.getKeyColumnDetails()
499         : null;
500     return new SemanticChecker(session, whereCD, groupCD, havingCD, orderCD,
501                                selectCD, fromCD, _selectlist1, orderKeyCD,
502                                isDistinct);
503   }
504
505   /**
506    * Returns the selected columns.
507    * @return ColumnDetails[]
508    * @throws DException
509    */

510
511   public ColumnDetails[] getSelectedColumns() throws DException {
512     return selectListColumnDetails;
513   }
514
515   /**
516    * It is never called.
517    * @param parent
518    * @param userRightCheck
519    * @return _references[]
520    * @throws DException
521    */

522
523   public _Reference[] checkSemantic(com.daffodilwoods.daffodildb.server.
524
                                    serversystem._ServerSession parent,
525                                     boolean userRightCheck) throws DException {
526     throw new UnsupportedOperationException JavaDoc("Method not Supported");
527   }
528
529   /**
530        * It is used to add the passed columns to the passed map which contains table
531    * as key and columns as value. It is required when we've to add the columns
532    * of view which are shifted to this view definition.
533    * @param columnDetails
534    * @param mappingOfTableColumns
535    * @throws DException
536    */

537   private void addColumnsInHashMap(ColumnDetails[] columnDetails,
538                                    HashMap mappingOfTableColumns) throws
539       DException {
540     if (columnDetails == null) {
541       return;
542     }
543     for (int i = 0, length = columnDetails.length; i < length; i++) {
544       TableDetails td = columnDetails[i].getTableDetails();
545       ColumnDetails[] existing = (ColumnDetails[]) mappingOfTableColumns.get(td);
546       ColumnDetails[] result = addInArray(existing, columnDetails[i]);
547       mappingOfTableColumns.put(td, result);
548     }
549   }
550
551   /**
552    * Concats the two arrays into one.
553    * @param source
554    * @param toAdd
555    * @return ColumnDetails
556    * @throws DException
557    */

558
559   private ColumnDetails[] addInArray(ColumnDetails[] source,
560                                      ColumnDetails toAdd) throws DException {
561     if (source == null) {
562       return new ColumnDetails[] {
563           toAdd};
564     }
565     int length = source.length;
566     ColumnDetails[] result = new ColumnDetails[length + 1];
567     System.arraycopy(source, 0, result, 0, length);
568     result[length] = toAdd;
569     return result;
570   }
571
572
573   /**
574    * Returns the Execution Plan of query.
575    * Various steps are performed regarding this
576    * 1) In the first step we obtain mapping of table and corresponding columns used in query from semantic Checker, this is
577    * done to map the query columns to their base level tables.
578    <<<<<<< queryspecification.java
579    * 2) To Map the columns passed from view to the base level tables we added those columns 'cdsWithActualTableDetails' in mapping
580    * attained above.
581    * 3) In the next step we check that if distinct is present then check is it redundant
582    =======
583    * 2) In the next step we check that if distinct is present then whether it is redundant
584    >>>>>>> 1.69
585    * e.g. select distinct a from A group by a
586    * in this case distinct is redundant thus there is need to merge with Group by plan
587    * therefore to avoid merging we check and eliminate such cases for this we call the method
588    * checkForDistinctRedundant() ...
589    * 4) In the next step we adjust the order passed, possible two case arises
590    * a) When Distinct is specified in query
591    * Passed Order is checked, then two case arises
592    * i) If Order is Null
593    * Distinct Order becomes the final adjusted order and is sent to tableExpression level for merging with
594    * groupBy
595    * ii) If Order is Not Null, then two cases arises
596    * x) If Distinct Order can adjust according to Order passed, then
597    * Distinct Order is adjusted according to the Order passed and the final adjusted order and is sent to
598    * tableExpression level for merging with groupBy
599    * y) If Distinct Order can not adjust according to Order passed, then Distinct Level Order is sent to
600    * tableExpression Level For Merging with group By and Order passed is placed at Query Specification plan level to get
601    * it solved above tableExpression.
602    * b) If Distinct is not specified in the query then passed order becomes the final order and is sent to
603    * tableExpression level for merging with groupBy
604    * 5) In the next step, we made provision for support of indexing in Aggregates column Max and Min. Indexing is only supported in
605    * the case of max or min column with only reference type column and table involved shud be one in query and it shud not be view
606    * 6) Then, we make GroupByPlan if groupby is present in the query above the tableExpressionPlan which we recieve from tableExpression
607    * 7) Then we make DistinctPlan if distinct is specified over the plan returned from step 5.
608    * 8) Then we make QuerySpecificationPlan over the plan returned from step 6.
609    * 9) Finally, we return plan formed in step 7.
610    * @param session
611    * @param bve
612    * @param datedCondition
613    * @param order
614    * @param cdsWithActualTableDetails
615    * @param conditionTableDetails
616    * @return
617    * @throws DException
618    *--------------------------
619    *REQUIREMENT OF ARGUMENTS |
620    *--------------------------
621    *Condition >> This is SingleLevel Conditions of View .
622    * For the above view we would like to shift the condition V.Id = 1 to the Orders Table as V.Id column is
623    * actually of Orders.OrderId .Since in this tableExpression/querySpecification we are having the tablePlan
624        * of Orders so we need to pass the information upto this level.
625    *ViewOrder >> This is SingleLevel Conditions of View .
626    * For the above view we would like to shift the order on column V.Id to the Orders Table as V.Id column is
627    * actually of Orders.OrderId .Since in this tableExpression/querySpecification we are having the tablePlan
628        * of Orders so we need to pass the information to this level.
629    *QueryColumns >> QueryColumns helps to calculate the cost of Plan Generated.As it tells the columns involved in the
630    * Query.There is always a cost of extracting any column from the Database.This cost calculation work
631    * is done at SingleTablePlan.
632    *ConditionArray >> For Changing the type of joins beacuse of the condition present in where clause or on clause
633    * we need to pass the these conditions as they can change their meaning
634    * eg Select * from Orders left Outer Join "Order Details" on Orders.OrderId = 11111 where "Orders Details".OrderId > 1
635    * This Query will act as Select * from Orders , "Order Details" where "Orders Details".OrderId > 1 and Orders.OrderId = 11111
636    * We need to pass "Orders Details".OrderId > 1 information to qualifiedJoin of Orders left Outer Join "Order Details"
637    * so that it can change and treat it as simple Join.
638    * We could have passed TableDetails of condition only but for the following case
639    * for eg Select * from Orders left Outer Join "Order Details" on Orders.OrderId = 11111
640    * where "Orders Details".OrderId is null
641    * we need not to change the type as simple Join .
642    * and if Condition TableDetails had been passed then we would not have any indication that
643    * the tableDetails were of null Predicate.
644    */

645
646   public _TablePlan getExecutionPlan(_ServerSession session,
647                                      booleanvalueexpression bve,
648                                      _DatedFramework datedCondition,
649                                      _Order order,
650                                      ColumnDetails[] cdsWithActualTableDetails,
651                                      ConditionArray conditionArray) throws
652       DException {
653     _QueryColumns queryColumns = initializeQueryColumns(
654         cdsWithActualTableDetails);
655       if (checkForDistinctRedundant(session)) {
656       isDistinct = false;
657       semanticChecker.setDistinctRedundant();
658     }
659
660    _Order[] adjustedOrder = isDistinct ?
661      getAdjustedQuerySpecificationOrderAndTEOrder(order)
662     : new _Order[] {
663     order, null};
664
665     if( order != null){
666     _OrderPlan orderPlan = order.getOrderPlan(session);
667   if( orderPlan.getQueryLevelOrderPlans()!= null )
668   {
669     adjustedOrder[1] = adjustedOrder[0];
670     adjustedOrder[0] = null;
671   }
672   }
673
674   _TablePlan tablePlan = _tableexpression0.getExecutionPlan(session, bve,
675    datedCondition, queryColumns, adjustedOrder[0], conditionArray);
676    return getPlan(tablePlan, session, adjustedOrder[1]);
677
678
679   }
680
681
682   /**
683    * This method is used to set the aggregate columns which can be solved using
684    * index to the underlying plan.
685    * @param tablePlan
686    * @param session
687    * @return boolean
688    * @throws DException
689    */

690
691   private boolean handleAggregateForIndex(TableExpressionPlan tablePlan,
692                                           _ServerSession session) throws
693       DException {
694     TableDetails[] tables = semanticChecker.getTableDetails();
695     if (tables.length == 1 && tables[0].getTableType() != TypeConstants.VIEW &&
696         _tableexpression0.getWhereClause() == null
697         && _tableexpression0.getGroupByClause() == null) {
698       ColumnDetails[] aggregateColumnsForINdexing =
699           getAggregateColumnForIndexing();
700       if (aggregateColumnsForINdexing != null &&
701           tablePlan.
702           setAggregateColumnsForIndexing(aggregateColumnsForINdexing, session)) {
703         return true;
704       }
705     }
706     return false;
707   }
708
709   /**
710    * Returns an array of Aggregate Columns valid for Indexing.
711    * Aggregates Column are valid in the follwoing cases
712    * 1) Aggregate Column should be Max or Min.
713    * 2) Any Combination of Max and Min are not permitted.
714    * 3) If Two Max Columns are present then columns present in both the aggregates shud be the same.
715    * 4) Aggregates shud only contain the Reference type column
716    * 5) Only Single table should be involved in the query.
717    * @return ColumnDetails
718    * @throws DException
719    */

720   private ColumnDetails[] getAggregateColumnForIndexing() throws DException {
721     ColumnDetails[] aggregateColumns = semanticChecker.getAllAggregateColumns();
722     int length = aggregateColumns.length;
723     ColumnDetails column = aggregateColumns[0];
724     String JavaDoc functionType = column.getFunctionType();
725     String JavaDoc quantifier = column.getQuantifier();
726     ColumnDetails[] childs = column.getExistingColumnDetails();
727     if ( (functionType.equalsIgnoreCase("Max") ||
728           functionType.equalsIgnoreCase("Min")) && childs.length == 1 &&
729         childs[0].getType() == REFERENCE) {
730       if (length > 1) {
731         String JavaDoc columnName = childs[0].getAppropriateColumn();
732         for (int i = 1; i < length; i++) {
733           ColumnDetails column1 = aggregateColumns[i];
734           ColumnDetails[] childs1 = column1.getExistingColumnDetails();
735           if (childs1.length != 1 || childs1[0].getType() != REFERENCE ||
736               !column1.getFunctionType().equalsIgnoreCase(functionType) ||
737               !column1.getQuantifier().equalsIgnoreCase(quantifier) ||
738               !childs1[0].getAppropriateColumn().equalsIgnoreCase(columnName)) {
739             return null;
740           }
741         }
742       }
743       return aggregateColumns;
744     }
745     return null;
746   }
747
748   /**
749    * Adds the Foreign Key Columns passed form view into the select List of View Query to have values of that columns
750    * @param fKeyColumns
751    * @throws DException
752    */

753   public void setFKeyColumnDetails(ColumnDetails[] fKeyColumns) throws
754       DException {
755     int existingLength = selectListColumnDetails.length,
756         passedLength = fKeyColumns.length;
757     ColumnDetails[] newColumns = new ColumnDetails[existingLength +
758         passedLength];
759     System.arraycopy(selectListColumnDetails, 0, newColumns, 0, existingLength);
760     System.arraycopy(fKeyColumns, 0, newColumns, existingLength, passedLength);
761     selectListColumnDetails = newColumns;
762   }
763
764   /**
765    * It is needed to obtain different constructs of query in string format.
766    * @return QueryProperty
767    * @throws DException
768    */

769
770   public QueryProperty getStrings() throws DException {
771     QueryProperty queryProperty = new QueryProperty();
772     queryProperty.setFromClause(_tableexpression0.getfromClause());
773     queryProperty.setWhereClause(_tableexpression0.getWhereClause());
774     queryProperty.setGroupByClause(_tableexpression0.getGroupByClause());
775     queryProperty.setHavingClause(_tableexpression0.getHavingClause());
776     queryProperty.setColumnList(_selectlist1.toString());
777     return queryProperty;
778   }
779
780   /**
781    * Creates a GroupByPLan Over the plan passed as an argument.
782    * Initialization of GroupByPlan is done at this level because we do not have semanticChecker at tableExpression level and we
783    * require Semantic Checker for aggregate Columns.
784    * Steps
785    * 1) Checks whether GroupByClause or any other aggregate column is present or not
786    * If Group BY Clause is present then GroupByCondition is made which is used to distinguish two groups.
787    * Otherwise , no GroupByCondition is made.
788    * 2) GroupByPlan is made with GroupByCondityion obtained from step 1.
789    * 3) It also mark a flag whether aggregates can bve solved with the help of index or not.
790    * @param finalPlan
791    * @return _TablePlan
792    * @throws DException
793    */

794
795   private _TablePlan createGroupByPlan(_TablePlan finalPlan,
796                                        _ServerSession session) throws
797       DException {
798     GroupByCondition groupCondition = null;
799     if (_tableexpression0._Optgroupbyclause1 != null) {
800       TableDetails[] td = getTableDetails();
801       groupCondition = new GroupByCondition(_tableexpression0.
802                                             _Optgroupbyclause1, null, td);
803     }
804     ColumnDetails[] aggregateColumns = semanticChecker.getAllAggregateColumns();
805     boolean indexUsedInAggregate = false;
806     if (aggregateColumns != null) {
807       indexUsedInAggregate = handleAggregateForIndex( (TableExpressionPlan)
808           finalPlan, session);
809     }
810
811     if (aggregateColumns != null || groupCondition != null) {
812       _Reference[] havingClauseUnderlyingReferences = null;
813       if (_tableexpression0._Opthavingclause0 != null) {
814         havingClauseUnderlyingReferences = _tableexpression0._Opthavingclause0.
815             getReferences(_tableexpression0.getTableDetails());
816         havingClauseUnderlyingReferences = GeneralPurposeStaticClass.
817             getUnderLyingReferencesOnly(havingClauseUnderlyingReferences,
818                                         _tableexpression0.getTableDetails());
819       }
820       finalPlan = new GroupByPlan(finalPlan, groupCondition,
821                                   _tableexpression0.getGroupByLevelOrder(),
822                                   aggregateColumns,
823                                   _tableexpression0.getAggregateCondition(),
824                                   indexUsedInAggregate,
825                                   havingClauseUnderlyingReferences);
826     }
827
828     return finalPlan;
829   }
830
831   /**
832    * this method is used to make distinctplan on table expression plan ,if isdistinct
833        * flag is true.isdistinct flag shows that whether distinct is present in query
834    * or not.
835    * is present is query.
836    * @param finalPlan
837    * @param selectReferences
838    * @return _TablePlan
839    * @throws DException
840    */

841   private _TablePlan createDistinctPlan(_TablePlan finalPlan,
842                                         _Reference[] selectReferences) throws
843       DException {
844     return isDistinct ?
845         new DistinctPlan(finalPlan, null, selectListColumnDetails,
846                          selectReferences)
847         : finalPlan;
848   }
849
850   /**
851        * This method is used to get order when distinct is present but order by clause
852    * not speciifed.first element of array shows order which solved at tableexpession
853    * plan level and second element shows order which solved at queryspecification level.
854        * In this case queryspecification level order is null ,because order by clause
855    * not present.
856    * @param appSelectedColumn
857    * @return _Order[]
858    * @throws DException
859    */

860   private _Order[] createOrdersWhenNoOrderByButDistinctPresent(ColumnDetails[]
861       appSelectedColumn) throws DException {
862     return new _Order[] {
863         new SelectOrder(appSelectedColumn), null};
864   }
865
866   /**
867    * this method is used to get order when both distinct and order by clause is
868    * present and distinct clause column is different from order by column.
869    * @param order
870    * @param appSelectedColumn
871    * @return _Order[]
872    * @throws DException
873    */

874   private _Order[] createOrderWhenOrderByColsIsNotPresentInSelectedCols(_Order
875       order, ColumnDetails[] appSelectedColumn) throws DException {
876     SelectOrder distinctOrder = new SelectOrder(appSelectedColumn);
877     return new _Order[] {
878         distinctOrder, order};
879   }
880
881   /**
882    * This method is used to get order when distinct and order by clause both is
883    * present and order by column are present in select list.
884    * @param adjustedIndexesAndOrder
885    * @param appSelectedColumn
886    * @return _Order[]
887    * @throws DException
888    */

889   private _Order[] createOrderWhenOrderByColsIsPresentInSelectedCols(Object JavaDoc[]
890       adjustedIndexesAndOrder, ColumnDetails[] appSelectedColumn) throws
891       DException {
892     ColumnDetails[] adjustedColumnDetails = GeneralPurposeStaticClass.
893         getColumnDetailsAccToIndexes( (int[]) adjustedIndexesAndOrder[0],
894                                      appSelectedColumn);
895     SelectOrder distinctOrder = new SelectOrder(adjustedColumnDetails,
896                                                 (boolean[])
897                                                 adjustedIndexesAndOrder[
898                                                 1]);
899     return new _Order[] {
900         distinctOrder, null};
901   }
902
903   /**
904    * It is used to merge order needed for OrderBy and Distinct.
905    * When No Order By present create order according to distinct Cols
906    * When Order By is Present then we check whether All columns of OrderBy are available in SelectColumns
907    * If all cols are available then we merge the twoOrders , otherwise OrderBy Order is solved at QuerySpecification
908    * Level and Distinct Order is solved at Table expressionPlan Level
909    * @param order order of order by clause
910    * @return _Order[]
911    * @throws DException
912    */

913
914   private _Order[] getAdjustedQuerySpecificationOrderAndTEOrder(_Order order) throws
915       DException {
916     ColumnDetails[] appSelectedColumns = semanticChecker.
917         getAppropriateUserDefinedColumns();
918     if (order == null) {
919       return createOrdersWhenNoOrderByButDistinctPresent(appSelectedColumns);
920     }
921     Object JavaDoc[] adjustedIndexesAndOrder =
922         GeneralPurposeStaticClass.
923         getColumnIndexesAndBooleanOrderOfAdjustedOrder(order, appSelectedColumns,true);
924
925     if (adjustedIndexesAndOrder == null) {
926       return createOrderWhenOrderByColsIsNotPresentInSelectedCols(order,
927           appSelectedColumns);
928     }
929     return createOrderWhenOrderByColsIsPresentInSelectedCols(
930         adjustedIndexesAndOrder, appSelectedColumns);
931   }
932
933   /**
934    * Initializes the UnKnown References solvable by current level
935    * @param allUnderlyingRef All Un Known References
936    * @param underLyingRefNotSolvableByCurrentLevel Rest of References not solvable by current level
937    * @throws DException
938    */

939   private void getUnderlyingReferencesSolvableByCurrentIterator(_Reference[]
940       allUnderlyingRef, _Reference[] underLyingRefNotSolvableByCurrentLevel) throws
941       DException {
942     if (allUnderlyingRef == null) {
943       return;
944     }
945     if (underLyingRefNotSolvableByCurrentLevel == null) {
946       underlyingReferencesSolvableByCurrentIterator = allUnderlyingRef;
947       return;
948     }
949     ArrayList aList = new ArrayList();
950     boolean found = false;
951     for (int i = 0, length = allUnderlyingRef.length; i < length; i++) {
952       found = false;
953       for (int j = 0, len = underLyingRefNotSolvableByCurrentLevel.length;
954            j < len; j++) {
955         if (allUnderlyingRef[i] == underLyingRefNotSolvableByCurrentLevel[j]) {
956           found = true;
957           break;
958         }
959       }
960       if (!found) {
961         aList.add(allUnderlyingRef[i]);
962       }
963     }
964     underlyingReferencesSolvableByCurrentIterator = (_Reference[]) aList.
965         toArray(new _Reference[0]);
966   }
967
968   public String JavaDoc toString() {
969     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
970     sb.append(" ");
971     sb.append(_SRESERVEDWORD12065439224);
972     sb.append(" ");
973     if (_Optsetquantifier3 != null) {
974       sb.append(_Optsetquantifier3);
975     }
976     sb.append(" ");
977     if (_Opttopfunction2 != null) {
978       sb.append(_Opttopfunction2);
979     }
980     sb.append(" ");
981     sb.append(_selectlist1);
982     sb.append(" ");
983     sb.append(_tableexpression0);
984     return sb.toString();
985   }
986
987   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
988     queryspecification tempClass = new queryspecification();
989     tempClass._tableexpression0 = (tableexpression) _tableexpression0.clone();
990     tempClass._selectlist1 = (selectlist) _selectlist1.clone();
991     if (_Opttopfunction2 != null) {
992       tempClass._Opttopfunction2 = (topfunction) _Opttopfunction2.clone();
993     }
994     if (_Optsetquantifier3 != null) {
995       tempClass._Optsetquantifier3 = (setquantifier) _Optsetquantifier3.clone();
996     }
997     tempClass._SRESERVEDWORD12065439224 = (SRESERVEDWORD1206543922)
998         _SRESERVEDWORD12065439224.clone();
999     return tempClass;
1000  }
1001
1002  /**
1003       * If groupby clause is present or any aggregate column is present or distinct
1004   * is present or any functional column present in the selectList of query,
1005   * then the viewplan cannot be solved as simple plan.
1006   * Case of Functional columns is added as we are not able to have value of
1007   * functional columns from this query if we make this query optimizable
1008   * in case of view.
1009   * For purpose refer the documentation of queryexpressionbody.
1010   * @return boolean
1011   * @throws DException
1012   */

1013
1014  public boolean isViewOptimizationPossible() throws DException {
1015
1016    /*Done by vibha to solve bug no 11826 on 15-09-2004 */
1017    if (_Opttopfunction2 != null || _tableexpression0._Optgroupbyclause1 != null ||
1018        semanticChecker.getAllAggregateColumns() != null || isDistinct ||
1019        checkForFunctionalColInSelectList() ||
1020        (underlyingReferencesSolvableByCurrentIterator != null
1021         && underlyingReferencesSolvableByCurrentIterator.length != 0)) {
1022      return false;
1023    }
1024    return true;
1025  }
1026
1027  /**
1028   * Checks whether any functional column is present in select list.
1029   * @return boolean
1030   * @throws DException
1031   */

1032
1033  private boolean checkForFunctionalColInSelectList() throws DException {
1034    ColumnDetails[] columns = _selectlist1.getDerivedColumnDetails();
1035    for (int i = 0; i < columns.length; i++) {
1036      if (columns[i].getTable() == null) {
1037        return true;
1038      }
1039    }
1040    return false;
1041  }
1042
1043  /**
1044   * This is Called when this querySpecification is of unoptimizable ViewType.
1045   * it returns the TablePlan[] of all the underLying tables
1046       * To Map the columns passed from view to the base level tables we added those
1047   * columns 'cdsWithActualTableDetails' in mapping attained above.
1048   * @param session
1049   * @param condition
1050   * @param order
1051   * @param cdsWithActualTableDetails
1052   * @param conditionTableDetails
1053   * @return _TablePlan[]
1054   * @throws DException
1055   */

1056
1057  /**
1058   * This is Called when this querySpecification is of unoptimizable ViewType.
1059   * it returns the TablePlan[] of all the underLying tables
1060       * To Map the columns passed from view to the base level tables we added those
1061   * columns 'cdsWithActualTableDetails' in mapping attained above.
1062   * @param session
1063   * @param condition
1064   * @param order
1065   * @param cdsWithActualTableDetails
1066   * @param conditionArray
1067   * @return _TablePlan[]
1068   * @throws DException
1069   */

1070
1071  public _TablePlan[] getTablePlans(_ServerSession session,
1072                                    booleanvalueexpression condition,
1073                                    _Order order,
1074                                    ColumnDetails[] cdsWithActualTableDetails,
1075                                    ConditionArray conditionArray) throws
1076      DException {
1077    _QueryColumns queryColumns = initializeQueryColumns(
1078        cdsWithActualTableDetails);
1079    _TablePlan[] tablePlans = _tableexpression0.getTablePlans(session,
1080        condition, order, queryColumns, conditionArray);
1081    return tablePlans.length == 1 &&
1082        tablePlans[0] instanceof TableExpressionPlan ? new _TablePlan[] {
1083        getPlan(tablePlans[0], session, null)}
1084        : tablePlans;
1085  }
1086
1087  /**
1088   * This method is called when the query is part of view definition and that
1089   * view is optimizable. Then the upward query needs the bve plan of view's
1090   * query to merge this BvePlan with its BvePlan.
1091   * @return _BVEPLAN
1092   * @throws DException
1093   */

1094
1095  public _BVEPlan getBveExecutionPlan() throws DException {
1096    return _tableexpression0.getBveExecutionPlan();
1097  }
1098
1099  /**
1100   * This method checks for the case where if distinct is specifed then
1101   * is it redundant or not.
1102   * e.g.
1103   * select distinct a from A group by a
1104   * or
1105       * select distinct a from A (a is the primary key hence it is distinct there
1106   * fore the distinct specified in the select list is redundant)
1107   * There are two case to be considered
1108       * i)- the columns in the select list are also present in the group by clause
1109   * ii)- the columns in the select list form the primary key
1110   *
1111   * @param session
1112   * @return boolean
1113   * @throws DException
1114   */

1115  private boolean checkForDistinctRedundant(_ServerSession session) throws
1116      DException {
1117    if (!isDistinct) {
1118      return false;
1119    }
1120    TableDetails[] td = _tableexpression0.getTableDetails(session, null);
1121    return td.length == 1 && td[0].getTableType() == TypeConstants.TABLE
1122        && checkForPk(session, td[0]) ? true : checkDistinctWithGroupBy();
1123  }
1124
1125  /**
1126   * This method is needed to check whether selected columns contains primary
1127   * key. It is required to check the redundancy of 'distinct'.
1128   * select distinct a1, a2 from A
1129   * Algo ::
1130   * firstly the name of the columns that form the primary key are got from
1131   * the serverSession
1132   * If the Array returned is null then
1133   * return false as there are no primary key
1134   * Next the selected columns are got from the semantic checker
1135   * for each column in the primary key we check if it is present in the
1136       * selected columns if all the primary key columns are in the selected columns
1137   * then the method returns true
1138   * else
1139   * it returns false
1140   *
1141   * @param session
1142   * @param tableDetails
1143   * @return boolean
1144   * @throws DException
1145   */

1146  private boolean checkForPk(_ServerSession session, TableDetails tableDetails) throws
1147      DException {
1148    String JavaDoc[] pks = ( (_ServerSession) session).getUniqueInformation(
1149        tableDetails.getQualifiedIdentifier());
1150    if (pks == null) {
1151      return false;
1152    }
1153    ColumnDetails[] selectedColumns = semanticChecker.getDerivedColumnDetails();
1154    for (int i = 0; i < pks.length; i++) {
1155      int j = 0;
1156      for (; j < selectedColumns.length; j++) {
1157        if (selectedColumns[j].getType() == REFERENCE) {
1158          if (pks[i].equalsIgnoreCase(selectedColumns[j].getAppropriateColumn())) {
1159            break;
1160          }
1161        }
1162      }
1163      if (j == selectedColumns.length) {
1164        return false;
1165      }
1166    }
1167    return true;
1168  }
1169
1170  /**
1171   * This method checks if the selected columns are present in group by.
1172   * It is required to check the redundancy of 'distinct'.
1173   * e.g.
1174   * For Select disticnt a1 , a2 from A group by a1 ,a2
1175   * This method returns true
1176   * Algo:
1177   * First the group by cols are got from the tableexpresesion
1178   * Then the selected cols are got from the semantic checker
1179   * For each group by column
1180       * the coluumn is checked if the same column is present in the selected columns
1181   * if all the selected columns are present in then method returns true
1182   * else returns false
1183   *
1184   * @return boolean
1185   * @throws DException
1186   */

1187  private boolean checkDistinctWithGroupBy() throws DException {
1188    ColumnDetails[] groupColumns = _tableexpression0.getGroupByColumnDetails();
1189    if (groupColumns == null) {
1190      return false;
1191    }
1192    ColumnDetails[] selectedColumns = semanticChecker.getDerivedColumnDetails();
1193    for (int i = 0; i < groupColumns.length; i++) {
1194      String JavaDoc column = groupColumns[i].getAppropriateColumn();
1195      int j = 0;
1196      for (; j < selectedColumns.length; j++) {
1197        if (column.equalsIgnoreCase(selectedColumns[j].getAppropriateColumn())) {
1198          break;
1199        }
1200      }
1201      if (j == selectedColumns.length) {
1202        return false;
1203      }
1204    }
1205    return true;
1206  }
1207
1208  public Object JavaDoc run(Object JavaDoc object) throws DException {
1209    throw new UnsupportedOperationException JavaDoc("Method not supported");
1210  }
1211
1212  /**
1213   * Note:-For documentation of following method please refers to queryexpressionbody
1214   * @param variableValueOperation
1215   * @throws DException
1216   */

1217  public void setDefaultValues(_VariableValueOperations variableValueOperation) throws
1218      DException {
1219    _tableexpression0.setDefaultValues(variableValueOperation);
1220  }
1221
1222  public _Reference[] getReferences(TableDetails[] tableDetails) throws
1223      DException {
1224    return GeneralPurposeStaticClass.getJointReferences(_selectlist1.
1225        getReferences(getTableDetails()),
1226        _tableexpression0.getReferences(getTableDetails()));
1227  }
1228
1229  public void setTablesForInsertion(ColumnMappingHandler parm1,
1230                                    _VariableValueOperations vv) throws com.
1231
      daffodilwoods.database.resource.DException {
1232    _tableexpression0.setTablesForInsertion(parm1, vv);
1233  }
1234
1235  public TableDetails[] getTablesForBlankInsert() throws com.daffodilwoods.
1236
      database.resource.DException {
1237    return _tableexpression0._fromclause3.getTablesForBlankInsert();
1238  }
1239
1240  public TableDetails[] getAllTableDetails() throws DException {
1241    return _tableexpression0.getAllTableDetails();
1242  }
1243
1244  public TableDetails[] getTableDetails() throws DException {
1245    return _tableexpression0.getTableDetails();
1246  }
1247
1248  public void verifyValues(_VariableValueOperations vv) throws DException {
1249    _tableexpression0.verifyValues(vv);
1250  }
1251
1252  public TableDetails[] getViewTableDetails() throws DException {
1253    return _tableexpression0.getViewTableDetails();
1254  }
1255
1256  public boolean isSimpleQuery(_ServerSession serverSession) throws DException {
1257    boolean refType = true;
1258    ColumnDetails[] cds = _selectlist1.getDerivedColumnDetails();
1259    for (int i = 0; cds != null && i < cds.length; i++) {
1260      if (cds[i].getType() == ColumnDetails.SCALARSUBQUERY || cds[i].getType() == ColumnDetails.GROUPING) {
1261        refType = false;
1262        break;
1263      }
1264    }
1265    return refType && !isDistinct && orderByClause == null &&
1266        _tableexpression0.isSimpleQuery(serverSession);
1267  }
1268
1269  public void checkSemanticForUpdate() throws DException {
1270    _tableexpression0.checkSemanticForUpdate();
1271    if (semanticChecker.getAllAggregateColumns() != null || isDistinct) {
1272      throw new DException("DSE0", null);
1273    }
1274  }
1275
1276  public boolean hasConstantSelectedColumn(booleanvalueexpression bve) throws
1277      DException {
1278    if (bve != null) {
1279      ColumnDetails cds[] = bve.getColumnDetails();
1280      ArrayList arr = new ArrayList(cds.length);
1281      GeneralPurposeStaticClass.addRecursively(cds,arr);
1282      for (int i = 0,length = arr.size(); i < length; i++) {
1283        ColumnDetails cd = (ColumnDetails)arr.get(i);
1284        if(cd.getType() == REFERENCE){
1285          for (int j = 0; j < selectListColumnDetails.length; j++) {
1286            if( cd.getAppropriateColumn().equalsIgnoreCase(selectListColumnDetails[j].getAppropriateColumn())){
1287                if( selectListColumnDetails[j].getType() != REFERENCE )
1288                  return true;
1289                break ;
1290            }
1291          }
1292        }
1293      }
1294    }
1295    return false;
1296  }
1297
1298  /* Done by Kaushik for view Problem in Joins */
1299  private void addUnderLyingRefInHashMap(HashMap mappingOfTableColumns) throws
1300      DException {
1301    if (underlyingReferencesSolvableByCurrentIterator != null) {
1302      for (int i = 0,
1303           length = underlyingReferencesSolvableByCurrentIterator.length;
1304           i < length; i++) {
1305        ColumnDetails cd = (ColumnDetails)
1306            underlyingReferencesSolvableByCurrentIterator[i];
1307        TableDetails td = cd.getTable();
1308        ColumnDetails[] existing = (ColumnDetails[]) mappingOfTableColumns.get(
1309            td);
1310        ColumnDetails[] result = addInArray(existing, cd);
1311        mappingOfTableColumns.put(td, result);
1312      }
1313    }
1314  }
1315
1316  public void showMap(String JavaDoc message, Map map) {
1317    Set set = map.entrySet();
1318    Iterator iter = set.iterator();
1319    while (iter.hasNext()) {
1320      Map.Entry me = (Map.Entry) iter.next();
1321    }
1322
1323  }
1324}
1325
Popular Tags