KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > booleanvalueexpression > predicates > comparisonpredicate


1 package com.daffodilwoods.daffodildb.server.sql99.expression.
2     booleanvalueexpression.predicates;
3
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.client.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
11 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
12 import com.daffodilwoods.daffodildb.server.sql99.expression.
13     booleanvalueexpression.*;
14 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*;
15 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
16 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
17 import com.daffodilwoods.daffodildb.utils.field.*;
18 import com.daffodilwoods.database.resource.*;
19 import com.daffodilwoods.database.utility.P;
20 import com.daffodilwoods.database.resource.DException;
21 import com.daffodilwoods.daffodildb.utils.FieldUtility;
22 import com.daffodilwoods.daffodildb.utils.comparator.*;
23 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
24 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
25
    queryexpression;
26 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.
27
    queryspecification.queryspecification;
28 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.
29
    subquery;
30 import com.daffodilwoods.daffodildb.server.sql99.expression.
31
    AbstractValueExpression;
32 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.
33
    AbstractRowValueExpression;
34
35 /**
36  * Predicate are the most basic unit in any booleanvalueexpression. In order to handle predicate of
37  * the form <exp1 compOperator exp2>, need for a seperate class arises. Here exp1 and exp2 are any expression
38  * and compOperator is an operator for the comparison of the two expression.
39  */

40 public class comparisonpredicate
41     extends PredicateAbstract
42     implements predicate, Datatypes, TypeConstants, OperatorConstants,
43     ExecutionPlanConstants, SimpleConstants, JoinConditionTableGetter,
44     _ComparisonPredicate {
45
46   /**
47    * Right hand side expression of predicate.
48    */

49   public valueexpressionwithoutboolean _valueexpressionwithoutboolean0;
50
51   /**
52    * The class representing comparison operator to be used for the comparison between the two expression.
53    * = , < , <= , > , >= , != and the possible operators .
54    */

55   public compop _compop1;
56
57   /**
58    * Left hand side expression of predicate.
59    */

60   public rowvalueexpressionwithoutboolean _rowvalueexpressionwithoutboolean2;
61
62   /**
63    * Int value for that 'll contain the constant corresting to each comparison operator.
64    */

65   protected int Operator = -1;
66
67   /**
68    * Array of ColumnDetails, each indicating basic property of the Columns involved in the Comparison Predicate
69    */

70   ColumnDetails[] columnDetails;
71
72   /**
73    * SubQueryFlag is a flag used to indicate whether subQuery is involved in the condition or not.
74    */

75   private Boolean JavaDoc subQueryFlag = Boolean.FALSE;
76
77   /**
78    * Default Constructor initiated by parser
79    */

80
81   public comparisonpredicate() {
82   }
83
84   /**
85    * Constructor initiated from between predicate.
86    * @param object1 is Left Side Expression
87    * @param Operator0 is Operator type i.e. <, >, =, >= etc.
88    * @param object2 is Right Side Expression
89    * @param columns
90    */

91
92   public comparisonpredicate(rowvalueexpressionwithoutboolean object1,
93                              int Operator0,
94                              valueexpressionwithoutboolean object2,
95                              ColumnDetails[] columns) {
96     _rowvalueexpressionwithoutboolean2 = object1;
97     Operator = Operator0;
98     _valueexpressionwithoutboolean0 = object2;
99     columnDetails = columns;
100   }
101
102   /**
103    * Computes Cost of solving predicate for rows passed, boolean is passed to
104    * indicate whether predicate is solvable by index or not.
105    * Algo:
106    * 1) If comparison operator is equalto, then check for join predicate,
107    * if Join Predicate is (A = B) then Square Root of rowCount
108    * passed is returned.
109    * 2) Otherwise, rows passed is reduced by operator.
110    * @param rowCount
111    * @param index
112    * @return
113    * @throws DException
114    */

115
116   public double getCost(long rowCount, boolean index) throws DException {
117     double result = 0;
118     switch (Operator) {
119       case EQUALTO:
120         result = checkForJoinPredicate() ? Math.sqrt(rowCount) :
121             rowCount * CostFactorConstants.EQUALTO / 100;
122         break;
123       case GREATERTHAN:
124       case LESSTHAN:
125         result = rowCount * CostFactorConstants.GREATERTHAN / 100;
126         break;
127       case GREATERTHANEQUALTO:
128       case LESSTHANEQUALTO:
129         result = rowCount * CostFactorConstants.GREATERTHANEQUALTO / 100;
130     }
131     result = index ?
132         rowCount * CostFactorConstants.INDEXPREDICATE / 100 : rowCount + result;
133     return result;
134   }
135
136   /**
137    * Checks for condition like A = B. If Exists then true is returned otherwise false is returned.
138    * @return
139    * @throws DException
140    */

141
142   private boolean checkForJoinPredicate() throws DException {
143     return columnDetails.length == 2 && columnDetails[0].getType() == REFERENCE &&
144         columnDetails[1].getType() == REFERENCE;
145   }
146
147   /**
148    * Returns Qualified Condition in case of qualified join.
149    * TableDetails passed represents the tables involved on right side of LOJ
150    * and on the left side of ROJ.
151    * Algo:
152    * 1) We extract unique tables involved in the predicate.
153    * 2) If tables involved are greater than 1 or less than 1, then it means
154    * predicate involves two tables or zero tables, means predicate is to
155    * be solved as onCondition in qualified join.
156    * 3) If tables involed are exactly one, then we check whether that table
157    * lies in the array of tables passed, if it lies then we can shift
158    * predicate to singleTableLevel otherwise not.
159    * 4) For predicate to shift at singleTable Level we make BVESingleTablePLan
160    * otheriwse we make onCondition.
161    * For Example:
162    * A LOJ B on A.a1 = 2
163    * In the above example, Table involved in predicate is one, i.e. A and it
164    * lies on the left side of LOJ,
165    * then we solve this condition above LOJ as onCondition
166    *
167    * A LOJ B on B.b1 = 2
168    * In the above example, Table involved in predicate is one, i.e. B and it
169    * lies on the right side of LOJ,
170    * then we solve shift this condition to single Table Level
171    *
172    * A LOJ B on B.b1 = A.a1
173    * In the above example, Table involved in predicate is two, then we solve
174    * this condition above LOJ as onCondition.
175    * @param tableDetails
176    * @return
177    * @throws DException
178    */

179
180   public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws
181       DException {
182     ArrayList uniqueTableList = getUniqueTableDetails(new ArrayList(),
183         columnDetails);
184     if (uniqueTableList.size() != 1) {
185       return new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this));
186     }
187     QualifiedBVE qualifiedBVE = getQualifiedBVEifBelongsToSingleTablePlan(
188         tableDetails, uniqueTableList);
189     if (qualifiedBVE == null) {
190       qualifiedBVE = new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this));
191     }
192     return qualifiedBVE;
193   }
194
195   /**
196    * Returns Qualified Plan in case when Predicate can be shifted to single
197    * Table Level, otherwise return null.
198    * Passed Tables belongs to Qualified Plan.
199    * Algo:
200    * Passed Plan Tables is matched against Tables involved in the predicate.
201    * If it matches then this predicate can be shifted to Single Table Level,
202    * otherwise predicate is solved as onCondition.
203    * @param planTableDeails
204    * @param uniqueTabldeDetailsLsit
205    * @return
206    * @throws DException
207    */

208
209   private QualifiedBVE getQualifiedBVEifBelongsToSingleTablePlan(TableDetails[]
210       planTableDetails, ArrayList uniqueTableList) throws DException {
211     int length = planTableDetails.length;
212     TableDetails conditionTableDetails = (TableDetails) uniqueTableList.get(0);
213     QualifiedBVE qualifiedBVE = null;
214     for (int j = 0; j < length; j++) {
215       if (planTableDetails[j] == conditionTableDetails) {
216         BVESingleTablePlan bveSingleTablePlan = new BVESingleTablePlan( (
217             booleanvalueexpression) BVEPlanMerger.getBooleanFactor(this),
218             conditionTableDetails);
219         BVESingleTablePlan[] bveSTPArray = new BVESingleTablePlan[] {
220             bveSingleTablePlan};
221         qualifiedBVE = new QualifiedBVE(bveSTPArray, null);
222         return qualifiedBVE;
223       }
224     }
225     return null;
226   }
227
228   /**
229    * Returns Unique List of tables involved in the condition.
230    * @return
231    * @throws DException
232       private ArrayList getUniqueTableDetailsList() throws DException {
233      ArrayList uniqueTableDetails = new ArrayList(3);
234      for (int i = 0, cLength = columnDetails.length; i < cLength; i++) {
235         int type = columnDetails[i].getType();
236         if (type == REFERENCE) {
237            TableDetails table = columnDetails[i].getTableDetails();
238            if (!uniqueTableDetails.contains(table)) {
239               uniqueTableDetails.add(table);
240            }
241         }
242         if (type == SCALARFUNCTION || type == CASEEXPRESSION) {
243            uniqueTableDetails.clear();
244            return uniqueTableDetails;
245         }
246      }
247      return uniqueTableDetails;
248       }
249    */

250
251   /**
252    * Returns true for condition which is seekable, constraint for seekable
253    * condition is that both the sides of predicate should be
254    * REFERENCE and operator shud be EQUALTO
255    * For Example condition like : A = B
256    * @return
257    * @throws DException
258    */

259   public int canUseForSeek() throws DException {
260     if (Operator == -1) {
261       Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
262     }
263     ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
264         getColumnDetails();
265     ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
266         getColumnDetails();
267     if (columnDetails1.length == 1 && columnDetails2.length == 1 &&
268         Operator == EQUALTO) {
269       int type1 = columnDetails1[0].getType();
270       int type2 = columnDetails2[0].getType();
271       switch (type1) {
272         case TypeConstants.REFERENCE:
273           switch (type2) {
274             case TypeConstants.REFERENCE:
275               return TypeConstants.BOTHSIDESEEKABLE;
276             case TypeConstants.SCALARFUNCTION:
277             case TypeConstants.FUNCTIONAL:
278             case TypeConstants.CONSTANT:
279             case TypeConstants.CASEEXPRESSION:
280             case TypeConstants.USERFUNCTION:
281               return TypeConstants.LEFTSIDESEEKABLE;
282             case TypeConstants.GROUPING:
283               return TypeConstants.NOSEEK;
284             default:
285               throw new DException("DSE0",
286                                    new Object JavaDoc[] {"Invalid Case type1 [" + type1 +
287                                    "] type2 [" + type2 + "]"});
288
289           }
290         case TypeConstants.SCALARFUNCTION:
291         case TypeConstants.FUNCTIONAL:
292         case TypeConstants.CONSTANT:
293         case TypeConstants.CASEEXPRESSION:
294         case TypeConstants.USERFUNCTION:
295           switch (type2) {
296             case TypeConstants.REFERENCE:
297               return TypeConstants.RIGHTSIDESEEKABLE;
298             case TypeConstants.SCALARFUNCTION:
299             case TypeConstants.FUNCTIONAL:
300             case TypeConstants.GROUPING:
301             case TypeConstants.CONSTANT:
302             case TypeConstants.USERFUNCTION:
303               return TypeConstants.NOSEEK;
304             default:
305               throw new DException("DSE0",
306                                    new Object JavaDoc[] {"Invalid Case type1 [" + type1 +
307                                    "] type2 [" + type2 + "]"});
308           }
309       }
310     }
311     return TypeConstants.NOSEEK;
312   }
313
314   /**
315    * Returns PredicateType for predicate.
316    * @return
317    * @throws DException
318    */

319
320   public int getPredicateType() throws DException {
321     if (Operator == -1) {
322       Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
323     }
324     if (Operator == NOTEQUALTO) {
325       return Operator;
326     }
327     if (columnDetails.length != 2) {
328       throw new DException("DSE3558", null);
329     }
330     ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
331         getColumnDetails();
332     ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
333         getColumnDetails();
334     if (columnDetails1[0].getType() == REFERENCE &&
335         columnDetails2[0].getType() == CONSTANT) {
336       return Operator;
337     }
338     if (columnDetails1[0].getType() == REFERENCE &&
339         columnDetails2[0].getType() == REFERENCE) {
340       return JOINCOMPARISONPREDICATE;
341     }
342     switch (Operator) {
343       case GREATERTHAN:
344         return LESSTHAN;
345       case LESSTHAN:
346         return GREATERTHAN;
347       case GREATERTHANEQUALTO:
348         return LESSTHANEQUALTO;
349       case LESSTHANEQUALTO:
350         return GREATERTHANEQUALTO;
351     }
352     return Operator;
353   }
354
355   /**
356    * Returns Value of Constant column involved in the condition.
357    * Initiated while we are merging predicates in the TableReferenceMerger class.
358    *
359    * If both expression are constant & doesn't contain SubQuery niether underLyingReference only then their
360    * respective Run method called. if NPE occurs then checked for CaseExpression,Functional & ScalarFunction types
361    * if Yes then Passed(by throwing Exception DSE3804)
362    * @return
363    * @throws DException
364    */

365
366   public Object JavaDoc getValue() throws DException {
367     if (columnDetails == null) {
368       throw new DException("DSE3559", null);
369     }
370     ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
371         getColumnDetails();
372     ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
373         getColumnDetails();
374
375
376     if (columnDetails2[0].getType() == CONSTANT &&
377         !columnDetails2[0].getUnderLyingReference()
378         && !_valueexpressionwithoutboolean0.checkForSubQuery()) {
379       FieldBase fieldBase1 = null;
380       try {
381         fieldBase1 = (FieldBase) _valueexpressionwithoutboolean0.run(null);
382       }
383       catch (NullPointerException JavaDoc ex1) {
384         if (columnDetails2[0].getType() == CONSTANT &&
385             !columnDetails2[0].getUnderLyingReference() ||
386             columnDetails2[0].getType() == FUNCTIONAL ||
387             columnDetails2[0].getType() == SCALARFUNCTION ||
388             columnDetails2[0].getType() == CASEEXPRESSION
389             ) {
390           throw new DException("DSE3804", null);
391         }
392         throw ex1;
393       }
394       fieldBase1.setDatatype(columnDetails1[0].getDatatype()); // Initiated as we want to make full use of byte comparison
395
return fieldBase1;
396     }
397
398     if (columnDetails1[0].getType() == CONSTANT &&
399         !columnDetails1[0].getUnderLyingReference()
400         && !_rowvalueexpressionwithoutboolean2.checkForSubQuery()) {
401       FieldBase fieldBase1 = null;
402       try {
403         fieldBase1 = (FieldBase) _rowvalueexpressionwithoutboolean2.run(null);
404       }
405       catch (NullPointerException JavaDoc ex) {
406         /* Done by Kaushik on 7/07/2004 to solve failed test Cases */
407         if (columnDetails1[0].getType() == CONSTANT &&
408             !columnDetails1[0].getUnderLyingReference() ||
409             columnDetails1[0].getType() == FUNCTIONAL ||
410             columnDetails1[0].getType() == SCALARFUNCTION ||
411             columnDetails1[0].getType() == CASEEXPRESSION
412             ) {
413           throw new DException("DSE3804", null);
414         }
415         throw ex;
416       }
417       fieldBase1.setDatatype(columnDetails2[0].getDatatype());
418       return fieldBase1;
419     }
420     throw new DException("DSE3804", null);
421   }
422
423   /**
424    * This method is initiated from setColumnPredicates. And it checks whether
425    * it contains more than one column of same table in this predicate. In this
426    * case we can't use this predicate in indexing.
427    * @return
428    * @throws DException
429    */

430
431   private boolean checkForMultipleReference() throws DException {
432     /* Done by Kaushik on 6/8/04 for TestHierarchicalSetOperator.testIntersectAll_IntersectAll
433      Set set = new HashSet();
434      for (int i = 0; i < columnDetails.length; i++) {
435        if (columnDetails[i].getType() == REFERENCE) {
436            if (!set.add(columnDetails[i].getAppropriateTableName())) {
437               return true;
438            }
439         }
440         if(columnDetails[i].getType() == FUNCTIONAL){
441           ColumnDetails cd[]=columnDetails[i].getChildColumnDetails();
442           for (int j = 0; j < cd.length; j++) {
443             if (cd[j].getType() == REFERENCE) {
444                 if (!set.add(cd[j].getAppropriateTableName())) {
445                    return true;
446                 }
447              }
448           }
449         }
450      }
451      return false;
452         /* End */

453      return checkForMultipleReference2(columnDetails, new HashSet());
454   }
455
456   /**
457    * Method decides whether this predicate can be solved by Index or not.
458    * Cases for which Predicate can be solved as NonIndexed Condition :
459    * 1) If predicate involves subquery.
460    * 2) If predicate involves NOTEQUALTO Operator.
461    * 3) If predicate involves any expression like a + 1. In this case Columns
462    * present in predicate is greater than 2.
463    * 4) If predicate involves both columns as CONSTANT then condition is
464    * solved as nonIndexedCondition.
465    * 5) If predicate involves both columns as REFERENCE of different tables
466    * then condition is solved as indexedCondition wrapped in joinPredicate.
467    * 7) If NOT is present in the predicate
468    *
469    * @param allColumnPredicates
470    * @throws DException
471    */

472   public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws
473       DException {
474     if (Operator == -1) {
475       Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
476     }
477
478     if (checkingForNotEqualTo() || subQueryFlag.booleanValue() ||
479         checkForMultipleReference() || checkForOtherCases()) {
480       allColumnPredicates.addToNonIndex(BVEPlanMerger.getBooleanFactor(this));
481       return;
482     }
483     SingleColumnPredicate singleColumnPredicate = new SingleColumnPredicate();
484     int index = checkForJoinPredicate(allColumnPredicates.getTableName());
485     if (index != -1) {
486       JoinPredicate joinPredicate = (index == 1)
487           ?
488           new JoinPredicate(BVEPlanMerger.getBooleanFactor(new RightIndexed(this,
489           Operator)))
490           : new JoinPredicate(BVEPlanMerger.getBooleanFactor(this));
491       String JavaDoc colName = columnDetails[index].getColumn(); //this line has been added to set
492
singleColumnPredicate.setPredicate(joinPredicate);
493       singleColumnPredicate.setColumnName(colName);
494       allColumnPredicates.addSinglePredicate(new SingleColumnPredicate[] {
495                                              singleColumnPredicate});
496       return;
497     }
498     ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
499         getColumnDetails();
500     ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
501         getColumnDetails();
502     if (columnDetails1[0].getType() == REFERENCE) { // for A = 2
503
singleColumnPredicate.setPredicate(this);
504       singleColumnPredicate.setColumnName(columnDetails1[0].getColumn());
505     }
506     else { // for 2 = A
507
singleColumnPredicate.setPredicate(new RightIndexed(this, Operator));
508       singleColumnPredicate.setColumnName(columnDetails2[0].getColumn());
509     }
510     allColumnPredicates.addSinglePredicate(new SingleColumnPredicate[] {
511                                            singleColumnPredicate});
512   }
513
514   /**
515    * Returns index of column involved in the condition whose table name
516    * matches with the passed table otheriwse -1 is returned.
517    * @param tableName
518    * @return
519    * @throws DException
520    */

521
522   private int checkForJoinPredicate(String JavaDoc tableName) throws DException {
523     for (int i = 0; i < columnDetails.length; i++) {
524       int type = columnDetails[i].getType();
525       if (type != REFERENCE) {
526         return -1;
527       }
528     }
529     for (int i = 0; i < columnDetails.length; i++) {
530       /* Done by Kaushik on 26/08/2004 to Solve Bug No. 11467 */
531       TableDetails td = columnDetails[i].getTable();
532       if (td != null &&
533           td.getAppropriateOnlyTableName().equalsIgnoreCase(tableName)) {
534         return i;
535       }
536     }
537     return -1;
538   }
539
540   private boolean checkingForNotEqualTo() throws DException {
541     if (Operator == -1) {
542       Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
543     }
544     if (Operator == NOTEQUALTO) {
545       return true;
546     }
547     return false;
548   }
549
550   /**
551    * Returns a BVEConstants member telling the BVEPlanType of instance on which
552    * this method is invoked.<p>
553    * If this method finds any column of GROUPING type then it returns
554    * BVEConstants.BVEAGGREGATE.<p>
555    * If it is not an aggregate plan, then it check for ALLTABLEPLAN
556    * type by checking existence of CASE Expression OR SubQuery and
557    * ComplexInnerQuery. If founds any then returns BVEConstants.BVEALLTABLEPLAN.<p>
558    * If both cases fail it check for table count for this predicate,<p>
559    * If table count is One, returns BVEConstants.BVESINGLETABLEPLAN;<p>
560    * If Two, returns BVEConstants.BVEJOINRELATION;<p>
561    * Otherwise BVEConstants.BVEALLTABLEPLAN.<p>
562    * @param tableList An empty ArrayList which is filled in this method with
563    * table names used in this predicate.
564    * @return BVEConstants.MEMBER.
565    * @throws DException
566    */

567   private int getBVEPlanType(ArrayList tableList) throws DException {
568     int countForFunctionalcolumn = 0;
569     return checkType(columnDetails, tableList, countForFunctionalcolumn);
570   }
571
572   private int checkType(ColumnDetails[] cd, ArrayList tableList,
573                         int countForFunctionalcolumn) throws DException {
574     /*Done by vibha acc to find bug*/
575     subQueryFlag = Utility.getBooleanValue(checkForSubQuery());
576     for (int i = 0; i < cd.length; i++) {
577       int type = cd[i].getType();
578       if (type == SCALARFUNCTION || type == FUNCTIONAL) { //type == CASEEXPRESSION ||
579
countForFunctionalcolumn++;
580         int ctype = checkType(cd[i].getChildColumnDetails(), tableList,
581                               countForFunctionalcolumn);
582         if (ctype == BVEConstants.BVEAGGREGATEPLAN ||
583             ctype == BVEConstants.BVEALLTABLEPLAN)
584           return ctype;
585       }
586       if (type == GROUPING) {
587         return BVEConstants.BVEAGGREGATEPLAN;
588       }
589       if (type == CASEEXPRESSION)
590         return BVEConstants.BVEALLTABLEPLAN;
591       if (type != CONSTANT) {
592         TableDetails tableDetail = cd[i].getTableDetails();
593         if (tableDetail != null && !tableList.contains(tableDetail)) {
594           tableList.add(tableDetail);
595         }
596       }
597     }
598     if (subQueryFlag.booleanValue() && checkForComplexInnerQuery()) {
599       return BVEConstants.BVEALLTABLEPLAN;
600     }
601     int len = tableList.size();
602     if (len == 1) {
603       return BVEConstants.BVESINGLETABLEPLAN;
604     }
605     if (len == 2) {
606       if (countForFunctionalcolumn < 2)
607         return BVEConstants.BVEJOINRELATION;
608     }
609     return BVEConstants.BVEALLTABLEPLAN;
610
611   }
612
613   /**
614    * Returns _BVEPlan based on the type of instance of this Object.<p>
615    * <pre>
616    * instance type returned plan
617    * -------------------------------------------------------------------------
618    * BVEConstants.BVEAGGREGATEPLAN BVEAggregatePlan
619    * BVEConstants.BVEALLTABLEPLAN BVEAllTablePlan
620    * BVEConstants.BVESINGLETABLEPLAN BVESingleTablePlan
621    * BVEConstants.BVEJOINRELATION BVEAllTablePlan
622    *
623    * <pre>
624    * In case of BVEJOINRELATION, a _JoinRelation is wrapped in
625    * AllTablesJoinRelation and AllTablesJoinRelation in BVEAllTablePlan.
626    * and returned.<p>
627    * @return
628    * @throws DException
629    */

630   public _BVEPlan getExecutionPlan() throws DException {
631     ArrayList tableList = new ArrayList();
632     switch (getBVEPlanType(tableList)) {
633       case BVEConstants.BVESINGLETABLEPLAN:
634         return new BVESingleTablePlan(BVEPlanMerger.getBooleanFactor(this),
635                                       (TableDetails) tableList.get(0));
636       case BVEConstants.BVEAGGREGATEPLAN:
637         return new BVEAggregatePlan(BVEPlanMerger.getBooleanFactor(this));
638       case BVEConstants.BVEJOINRELATION:
639         _JoinRelation simpleRelation = new SimpleRelation( (TableDetails[])
640             tableList.toArray(new TableDetails[tableList.size()]),
641             BVEPlanMerger.getBooleanFactor(this));
642         AllTablesJoinRelation allTablesJoinRelation = new AllTablesJoinRelation(new
643             _JoinRelation[] {simpleRelation});
644         BVEAllTablePlan bveAllTablePlan = new BVEAllTablePlan(null,
645             allTablesJoinRelation, null);
646         return bveAllTablePlan;
647       case BVEConstants.BVEALLTABLEPLAN:
648         return new BVEAllTablePlan(null, null, BVEPlanMerger.getBooleanFactor(this));
649     }
650     throw new DException("DSE3547", new Object JavaDoc[] {this.toString()});
651   }
652
653   /**
654    * ComplexInnerQuery means that subQuery contains the column of outer query.
655    * In this case this condition is treated as remaining condition.
656    * @return
657    * @throws DException
658    */

659
660   private boolean checkForComplexInnerQuery() throws DException {
661     _Reference[] references = getReferences(null);
662     int length = references.length;
663     for (int i = 0; i < length; i++) {
664       if (references[i].getReferenceType() == SUBQUERY) {
665         if ( ( (subquery) references[i]).getUnderlyingReferences() != null) {
666           return true;
667         }
668       }
669     }
670     return false;
671   }
672
673   /**
674    * Cardinality of predicate is checked.
675    * By Cardinality of predicate we mean that columns on both sides of
676    * predicate are equal in number.
677    * Cardinality is -1 in case of question mark.
678    * For Example:
679    * (A,2) = (2,2)
680    * Here both sides cardinality is 2
681    *
682    * A = 2
683    * Here both sides cardinality is 1
684    */

685
686   private void performingCardinalityChecking() throws DException {
687     int cardinality1 = _rowvalueexpressionwithoutboolean2.getCardinality();
688     int card2 = _valueexpressionwithoutboolean0.getCardinality();
689     if (cardinality1 != -1 && card2 != -1 && cardinality1 != card2) {
690       throw new DException("DSE214", null);
691     }
692     if (Operator != -1) {
693       Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
694     }
695   }
696
697   /**
698    * This is the most important method in this class that is executed maximum
699    * times. The basic purpose of the run method is to evaluate the condition.
700    * The argument is actually some VariableValue, that is passed for the
701    * purpose of providing the value of any column (which is actually an
702    * instanceof _Reference) used in the condition. The return type of the run
703    * method is a fieldBase in the form of Object class.
704    *
705    * Run Method returns value 0, -1, 1, -2 or 2 on the basis whether predicate
706    * solves on the current record or not.
707    * Steps:
708    * 1) On Calling run we retrieves values for _rowvalueexpressionwithoutboolean2
709    * and _valueexpressionwithoutboolean0
710    * 2) Thereafter, appropriate comparator is initialised by catching NPE for
711    * the first time. Comparator is decided on the basis of Byte Comparison
712    * usage.
713    * If Bytes Comparison is allowed
714    * then appropriate comparators are made for both the operands
715    *
716    * If Bytes Comparison is not allowed
717    * CPckfduDpnqbsbups is initialised for for both the operands
718    * 3) On the basis of compare value from comparator appropriate FiledBase is
719    * returned
720    * @param object
721    * @return
722    * @throws com.daffodilwoods.database.resource.DException
723    */

724   public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.
725
      DException {
726
727     Object JavaDoc fieldBase1 = _rowvalueexpressionwithoutboolean2.run(object);
728     Object JavaDoc fieldBase2 = _valueexpressionwithoutboolean0.run(object);
729
730     int cmp = -1;
731     try {
732       cmp = comparator.compare(fieldBase1, fieldBase2);
733     }
734     catch (NullPointerException JavaDoc ex) {
735       ByteComparison bc1 = _rowvalueexpressionwithoutboolean2.getByteComparison(
736           object);
737       ByteComparison bc2 = _valueexpressionwithoutboolean0.getByteComparison(
738           object);
739       synchronized (this) {
740         try {
741
742           comparator = getAppropriateComparator(bc1, bc2, fieldBase1,
743                                                 fieldBase2, null);
744
745           cmp = comparator.compare(fieldBase1, fieldBase2); //if(this.toString().toLowerCase().indexOf("DivisionBased".toLowerCase()) != -1)
746

747         }
748         catch (NullPointerException JavaDoc npe) {
749           throw npe;
750         }
751       }
752     }
753     catch (DException ex1) {
754       throw ex1;
755     }
756     return booleanResult[Operator - 1][cmp + 2];
757   }
758
759   private int getRespectiveOperator(String JavaDoc oper) throws DException {
760     if (oper.equals(EQUALTOSTRING) || oper.equals(DOUBLEEQUALTOSTRING)) {
761       return EQUALTO;
762     }
763     else if (oper.equals(GREATERTHANSTRING)) {
764       return GREATERTHAN;
765     }
766     else if (oper.equals(GREATERTHANEQUALTOSTRING)) {
767       return GREATERTHANEQUALTO;
768     }
769     else if (oper.equals(LESSTHANSTRING)) {
770       return LESSTHAN;
771     }
772     else if (oper.equals(LESSTHANEQUALTOSTRING)) {
773       return LESSTHANEQUALTO;
774     }
775     else if (oper.equals(NOTEQUALTOSTRING) || oper.equals(NOTEQUALTOSTRING1)) {
776       return NOTEQUALTO;
777     }
778     return 0;
779   }
780
781   private boolean checkForSubQuery(ParameterInfo[] pi) throws DException {
782     for (int i = 0; i < pi.length; i++) {
783       if (pi[i].getSubQuery()) {
784         return true;
785       }
786     }
787     return false;
788   }
789
790   /**
791    * This method is called from Browser, when Parameterized query is fired from Browser.
792    * With the help of ParameterInfo Browser open ups daialog box(labelled by its corresponding name)
793    * for each question mark to put the values of question mark.
794    * In this method we set the name,datatype of one side to question mark of
795    * other side.
796    * Also in case of subQuery, all the ParameterInfo of subQuery are added into
797    * the list.
798    * @return
799    * @throws DException
800    */

801
802   public ParameterInfo[] getParameterInfo() throws DException {
803     boolean subQueryFlag = false;
804     boolean flag = false;
805     ParameterInfo[] parameterInfo1 = _rowvalueexpressionwithoutboolean2.
806         getParameterInfo();
807     ParameterInfo[] parameterInfo2 = _valueexpressionwithoutboolean0.
808         getParameterInfo();
809     ParameterInfo[] result = null;
810     result = new ParameterInfo[parameterInfo1.length + parameterInfo2.length];
811     System.arraycopy(parameterInfo1, 0, result, 0, parameterInfo1.length);
812     System.arraycopy(parameterInfo2, 0, result, parameterInfo1.length,
813                      parameterInfo2.length);
814
815     /*Done by vibha to solve bug no 11864,11880 on 21-09-2004*/
816
817     if (_rowvalueexpressionwithoutboolean2 instanceof rowsubquery) {
818       ColumnDetails[] cd1 = ( (rowsubquery) _rowvalueexpressionwithoutboolean2).
819           _rowsubquery0.getSelectedColumnDetails();
820       for (int i = 0; i < cd1.length; i++) {
821         for (int j = 0; j < result.length; j++) {
822           if (result[j].getQuestionMark()) {
823             result[j].setDataType(cd1[i].getDatatype());
824           }
825         }
826       }
827     }
828
829     if (_valueexpressionwithoutboolean0 instanceof rowsubquery) {
830       ColumnDetails[] cd1 = ( (rowsubquery) _valueexpressionwithoutboolean0).
831           _rowsubquery0.getSelectedColumnDetails();
832       for (int i = 0; i < cd1.length; i++) {
833         for (int j = 0; j < result.length; j++) {
834           if (result[j].getQuestionMark()) {
835             result[j].setDataType(cd1[i].getDatatype());
836
837           }
838         }
839
840       }
841     }
842
843     flag = checkForSubQuery(result);
844     if (flag) {
845       ArrayList temp = new ArrayList(5);
846       for (int i = 0; i < result.length; i++) {
847         if (result[i].getSubQuery()) {
848           ParameterInfo[] tempPI = result[i].getParameterInfoArray();
849           if (tempPI != null) {
850             temp.addAll(Arrays.asList(tempPI));
851           }
852         }
853         else if (result[i].getQuestionMark()) {
854           temp.add(result[i]);
855         }
856       }
857       return (ParameterInfo[]) temp.toArray(new ParameterInfo[0]);
858     }
859     ArrayList aList = new ArrayList();
860     int columnCount1 = parameterInfo1.length;
861     int columnCount2 = parameterInfo2.length;
862     if (columnCount1 == columnCount2) {
863       for (int i = 0; i < columnCount1; i++) {
864         if (parameterInfo1[i].getQuestionMark()) {
865           if (!parameterInfo2[i].getQuestionMark()) {
866             parameterInfo1[i].setName(parameterInfo2[i].getName());
867             if (parameterInfo1[i].getDataType() == -1)
868               parameterInfo1[i].setDataType(parameterInfo2[i].getDataType());
869           }
870           else {
871             if (parameterInfo1[i].getDataType() == -1)
872               parameterInfo1[i].setDataType(VARCHAR);
873           }
874           aList.add(parameterInfo1[i]);
875         }
876       }
877       for (int i = 0; i < columnCount2; i++) {
878         if (parameterInfo2[i].getQuestionMark()) {
879           if (!parameterInfo1[i].getQuestionMark()) {
880             parameterInfo2[i].setName(parameterInfo1[i].getName());
881             /* Check placed by Kaushik on 16/09/2004 to Solve Bug No. 11910 */
882             if (parameterInfo2[i].getDataType() == -1)
883               parameterInfo2[i].setDataType(parameterInfo1[i].getDataType());
884           }
885
886           else {
887             if (parameterInfo2[i].getDataType() == -1)
888               parameterInfo2[i].setDataType(VARCHAR);
889           }
890           aList.add(parameterInfo2[i]);
891         }
892       }
893     }
894     else {
895       int maxDataType = -1;
896       for (int i = 0; i < columnCount1; i++) {
897         int type = parameterInfo1[i].getDataType();
898         if (maxDataType < type) {
899           maxDataType = type;
900         }
901       }
902       for (int i = 0; i < columnCount2; i++) {
903         int type = parameterInfo2[i].getDataType();
904         if (maxDataType < type) {
905           maxDataType = type;
906         }
907       }
908       for (int i = 0; i < columnCount1; i++) {
909         if (parameterInfo1[i].getQuestionMark()) {
910           aList.add(parameterInfo1[i]);
911           parameterInfo1[i].setDataType(maxDataType);
912         }
913       }
914       for (int i = 0; i < columnCount2; i++) {
915         if (parameterInfo2[i].getQuestionMark()) {
916           aList.add(parameterInfo2[i]);
917           /* Check placed by Kaushik on 16/09/2004 to Solve Bug No. 11910 */
918           if (parameterInfo2[i].getDataType() == -1)
919             parameterInfo2[i].setDataType(maxDataType);
920         }
921       }
922
923     }
924
925     return (ParameterInfo[]) aList.toArray(new ParameterInfo[0]);
926   }
927
928   public void setOperator(int Type) throws DException {
929     Operator = Type;
930   }
931
932   /**
933    * In this some cases are checked in which we can't use this predicate in
934    * indexing. These are -
935    * 1. When more than two columns are involved.
936    * 2. When Two Columns are involved then
937    * A. Both columns are constants
938    * B. One of the column is part of Outer query.
939    * @return
940    * @throws DException
941    */

942
943   private boolean checkForOtherCases() throws DException {
944     if (columnDetails.length != 2) {
945       return true;
946     }
947     return columnDetails[0].getType() == CONSTANT &&
948         columnDetails[1].getType() == CONSTANT
949         ||
950         (columnDetails[0].getUnderLyingReference() &&
951          columnDetails[1].getUnderLyingReference())
952         || columnDetails[0].checkNegativeValueFlag() ||
953         columnDetails[1].checkNegativeValueFlag();
954
955   }
956
957   /**
958    * This method is needed in insert through resultset and is called from
959    * join condition of qualified join.
960    * @param td
961    * @return
962    * @throws com.daffodilwoods.database.resource.DException
963    */

964
965   public TableDetails[] getCorrespondingTablesInvolved(TableDetails[] td) throws
966       com.daffodilwoods.database.resource.DException {
967     ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
968         getColumnDetails();
969     ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
970         getColumnDetails();
971     if (columnDetails1.length > 1 || columnDetails2.length > 1) {
972       return null;
973     }
974     TableDetails toRet1 = null, toRet2 = null;
975     if (Operator == -1) {
976       Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
977     }
978     if (Operator == EQUALTO || Operator == LESSTHANEQUALTO ||
979         Operator == GREATERTHANEQUALTO) {
980       toRet1 = getCorrespondingTableDetail(false, td);
981       toRet2 = getCorrespondingTableDetail(true, td);
982       if ( (toRet1 != null ^ toRet2 != null) == false) {
983         return null;
984       }
985       return toRet1 != null ? new TableDetails[] {
986           toRet1}
987           : new TableDetails[] {
988           toRet2};
989     }
990     return null;
991   }
992
993   private TableDetails getCorrespondingTableDetail(boolean flag,
994       TableDetails[] td) throws DException {
995     TableDetails tolook = null, toRet = null;
996     ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
997         getColumnDetails();
998     ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
999         getColumnDetails();
1000    if (flag) {
1001      tolook = columnDetails1[0].getTableDetails();
1002      toRet = columnDetails2[0].getTableDetails();
1003    }
1004    else {
1005      tolook = columnDetails2[0].getTableDetails();
1006      toRet = columnDetails1[0].getTableDetails();
1007    }
1008    int len = td.length;
1009    for (int i = 0; i < len; i++) {
1010      if (td[i] == tolook) {
1011        return toRet;
1012      }
1013    }
1014    return null;
1015  }
1016
1017  /**
1018   * This method checks the equality of values specified by the user for the qualified join
1019   * - join condition. If any of the value is null, than we retrun. ( value for the second
1020   * non conditional value is specified by set default values method).
1021   * If the values got from the left and right side
1022   * <ol><li>mismatches, throws exception.</li>
1023   * <li>are both null, throws exception.</li></ol>
1024   */

1025  public void verifyValues(_VariableValueOperations vv) throws DException {
1026  }
1027
1028  public AbstractRowValueExpression[] getChilds() {
1029    AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {
1030        (AbstractRowValueExpression) (_rowvalueexpressionwithoutboolean2),
1031        (AbstractRowValueExpression) (_valueexpressionwithoutboolean0)};
1032    return childs;
1033  }
1034
1035  /**
1036   * This method sets the default value for the qualified join - join condition
1037   * consisting of equals operator.If any of the value is null, value for the
1038   * second non conditional column is set to maintain the join condition.
1039   * If any of the value is not null, it's value is put in vv.
1040   */

1041
1042  public void setDefaultValues(_VariableValueOperations variableValueOperation) throws
1043      DException {
1044    if (Operator == -1) {
1045      Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
1046    }
1047    if (Operator != EQUALTO || checkForFunctionalOrGroupingColumn() ||
1048        ! (columnDetails.length == 2)) {
1049      return;
1050    }
1051    Object JavaDoc leftValue = _rowvalueexpressionwithoutboolean2.run(
1052        variableValueOperation);
1053    Object JavaDoc rightValue = _valueexpressionwithoutboolean0.run(
1054        variableValueOperation);
1055    ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
1056        getColumnDetails();
1057    ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
1058        getColumnDetails();
1059    if (leftValue == null && rightValue != null &&
1060        ! (rightValue instanceof IgnoreValue)) {
1061      putInMapping(variableValueOperation, columnDetails1[0], rightValue);
1062    }
1063    ( (VariableValueOperations) variableValueOperation).show();
1064    if (leftValue != null && rightValue == null &&
1065        ! (leftValue instanceof IgnoreValue)) {
1066      putInMapping(variableValueOperation, columnDetails2[0], leftValue);
1067    }
1068  }
1069
1070  /**
1071   * This method performs the semantic checking of cardinality and initiates
1072   * checking of underlying children. Some Runtime checking like checking of
1073   * dataType are performed at runtime.
1074   * @param parent
1075   * @return
1076   * @throws DException
1077   */

1078
1079  public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[]
1080      checkSemantic(com.daffodilwoods.daffodildb.server.serversystem.
1081
                    _ServerSession parent) throws DException {
1082    _Reference[] reference1 = GeneralPurposeStaticClass.getJointReferences(
1083        _rowvalueexpressionwithoutboolean2.checkSemantic(parent),
1084        _valueexpressionwithoutboolean0.checkSemantic(parent));
1085    performingCardinalityChecking();
1086    setDatatypeforNull(_valueexpressionwithoutboolean0,
1087                       _rowvalueexpressionwithoutboolean2);
1088    if (reference1 == null )
1089      checkDataTypes(parent);
1090    return reference1;
1091  }
1092
1093  private void checkDataTypes(_ServerSession session) throws DException {
1094    try {
1095      int[] dt1 = _rowvalueexpressionwithoutboolean2.getByteComparison(session).
1096          getDataTypes();
1097      int[] dt2 = _valueexpressionwithoutboolean0.getByteComparison(session).
1098          getDataTypes();
1099      Check.checkForDataTypes(dt1, dt2);
1100    }
1101    catch (DException ex) {
1102      throw ex;
1103    }
1104  }
1105
1106  /**
1107   * This method returns the estimate of the rows remaining after the execution
1108   * of this condition on passed number of rows.
1109   * @param noOfRows
1110   * @return
1111   * @throws DException
1112   */

1113
1114  public long getEstimatedRows(long noOfRows) throws DException {
1115    if (Operator == -1) {
1116      Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
1117    }
1118    switch (Operator) {
1119      case EQUALTO:
1120        return checkForJoinPredicate() ? (long) Math.sqrt(noOfRows) :
1121            noOfRows * CostFactorConstants.EQUALTO / 100;
1122      case GREATERTHAN:
1123      case LESSTHAN:
1124        return noOfRows * CostFactorConstants.GREATERTHAN / 100;
1125      case GREATERTHANEQUALTO:
1126      case LESSTHANEQUALTO:
1127        return noOfRows * CostFactorConstants.GREATERTHANEQUALTO / 100;
1128    }
1129    return noOfRows;
1130  }
1131
1132  public ColumnDetails[] getColumnDetails() throws DException {
1133    if (columnDetails == null) {
1134      ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean2.
1135          getColumnDetails();
1136      ColumnDetails[] columnDetails2 = _valueexpressionwithoutboolean0.
1137          getColumnDetails();
1138      ColumnDetails[] result = new ColumnDetails[columnDetails1.length +
1139          columnDetails2.length];
1140      int i;
1141      for (i = 0; i < columnDetails1.length; i++) {
1142        result[i] = columnDetails1[i];
1143      }
1144      for (int j = 0; j < columnDetails2.length; j++, i++) {
1145        result[i] = columnDetails2[j];
1146      }
1147      this.columnDetails = result;
1148    }
1149    /*@Following check will initialize subQueryFlag to indicate whether condition involves SubQuery **/
1150    /* done by vibha acc to findbug*/
1151    subQueryFlag = Utility.getBooleanValue(checkForSubQuery());
1152    /*@Following will initialize the operator **/
1153    if (Operator == -1) {
1154      Operator = getRespectiveOperator( (String JavaDoc) _compop1.run(null));
1155
1156    }
1157    return columnDetails;
1158  }
1159
1160  /**
1161   * This method puts the value of the join condtion conditional column to the variableValueOperation
1162   * object passed, that is used to update the value in the corresponding table when commit of save
1163   * point is called.
1164   */

1165  private void putInMapping(_VariableValueOperations variableValueOperation,
1166                            ColumnDetails columnDetails, Object JavaDoc value) throws
1167      DException {
1168    ( (VariableValueOperations) variableValueOperation).addColumnValues(new
1169        _Reference[] {columnDetails}
1170        , new Object JavaDoc[] {value}
1171        , 1);
1172  }
1173
1174  private boolean checkForFunctionalOrGroupingColumn() throws DException {
1175    int length = columnDetails.length;
1176    for (int i = 0; i < length; i++) {
1177      if (columnDetails[i].getType() == FUNCTIONAL ||
1178          columnDetails[i].getType() == GROUPING) {
1179        return true;
1180      }
1181    }
1182    return false;
1183  }
1184
1185  public String JavaDoc toString() {
1186    StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
1187    sb.append(" ");
1188    sb.append(_rowvalueexpressionwithoutboolean2.toString().trim());
1189    sb.append(_compop1 == null ? getRespectiveOperatorString(Operator) :
1190              _compop1 + "");
1191    sb.append(_valueexpressionwithoutboolean0.toString().trim());
1192    return sb.toString();
1193  }
1194
1195  private String JavaDoc getRespectiveOperatorString(int oper) {
1196    if (oper == EQUALTO) {
1197      return EQUALTOSTRING;
1198    }
1199    else if (oper == GREATERTHAN) {
1200      return GREATERTHANSTRING;
1201    }
1202    else if (oper == GREATERTHANEQUALTO) {
1203      return GREATERTHANEQUALTOSTRING;
1204    }
1205    else if (oper == LESSTHAN) {
1206      return LESSTHANSTRING;
1207    }
1208    else if (oper == LESSTHANEQUALTO) {
1209      return LESSTHANEQUALTOSTRING;
1210    }
1211    else if (oper == NOTEQUALTO) {
1212      return NOTEQUALTOSTRING;
1213    }
1214    return 0 + "";
1215  }
1216
1217  public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
1218    comparisonpredicate tempClass = new comparisonpredicate();
1219    tempClass._valueexpressionwithoutboolean0 = (valueexpressionwithoutboolean)
1220        _valueexpressionwithoutboolean0.clone();
1221    tempClass._compop1 = (compop) _compop1.clone();
1222    tempClass.Operator = Operator;
1223    tempClass._rowvalueexpressionwithoutboolean2 = (
1224        rowvalueexpressionwithoutboolean) _rowvalueexpressionwithoutboolean2.
1225        clone();
1226    try {
1227      tempClass.getColumnDetails();
1228    }
1229    catch (DException ex) {
1230      throw new RuntimeException JavaDoc(ex.getMessage());
1231    }
1232    return tempClass;
1233  }
1234
1235  /* Done by Kaushik on 6/8/04 for TestHierarchicalSetOperator.testIntersectAll_IntersectAll */
1236  private boolean checkForMultipleReference2(ColumnDetails[] cd, Set set) throws
1237      DException {
1238    for (int i = 0; i < cd.length; i++) {
1239      if (cd[i].getType() == REFERENCE) {
1240        if (!set.add(cd[i].getAppropriateTableName())) {
1241          return true;
1242        }
1243      }
1244      if (cd[i].getType() == FUNCTIONAL) {
1245        return checkForMultipleReference2(cd[i].getChildColumnDetails(), set);
1246      }
1247    }
1248    return false;
1249  }
1250
1251  /*@ METHOD written by Kaushik on 11/08/2004
1252   for appropriate comparator generation in comparison pedicate
1253   **/

1254
1255  public SuperComparator getAppropriateComparator(ByteComparison
1256                                                  byteComparison1,
1257                                                  ByteComparison
1258                                                  byteComparison2,
1259                                                  Object JavaDoc value1, Object JavaDoc value2,
1260                                                  _ServerSession serverSession) throws
1261      DException {
1262    if (!byteComparison1.canUseByteComparison() ||
1263        !byteComparison2.canUseByteComparison()) {
1264      initializeDatatypes((FieldBase)value1,(FieldBase)value2);
1265      return new CPckfduDpnqbsbups();
1266    }
1267    int cardinality = _rowvalueexpressionwithoutboolean2.getCardinality();
1268    if (cardinality > 1) {
1269      return getJoinComparator( (Object JavaDoc[]) value1, (Object JavaDoc[]) value2,
1270                               serverSession);
1271    }
1272    return getComparator( (FieldBase) value1, (FieldBase) value2, serverSession);
1273  }
1274
1275  /*Method writeen by Sandeep Kadiyan to return a instance of ComparisionPredicateJoinComparator
1276      to solve Bug 12577
1277   */

1278
1279  protected SuperComparator getJoinComparator(Object JavaDoc[] fieldBase1,
1280                                              Object JavaDoc[] fieldBase2,
1281                                              _ServerSession serverSession) throws
1282      DException {
1283    int length = fieldBase1.length;
1284    SuperComparator[] comparators = new SuperComparator[length];
1285    for (int i = 0; i < length; i++) {
1286      try {
1287        comparators[i] = getComparator( (FieldBase) fieldBase1[i],
1288                                       (FieldBase) fieldBase2[i], serverSession);
1289      }
1290      catch (ClassCastException JavaDoc ex) {
1291        throw ex;
1292      }
1293    }
1294    return new ComparisionPredicateJoinComparator(comparators, Operator);
1295  }
1296
1297  private void setDatatypeforNull(valueexpressionwithoutboolean
1298                                  _valueexpressionwithoutboolean0,
1299                                  rowvalueexpressionwithoutboolean
1300                                  _rowvalueexpressionwithoutboolean2) throws
1301      DException {
1302    ColumnDetails cd1[] = _valueexpressionwithoutboolean0.getColumnDetails();
1303    ColumnDetails cd2[] = _rowvalueexpressionwithoutboolean2.getColumnDetails();
1304    if (cd1.length == cd2.length) {
1305      for (int i = 0; i < cd1.length; i++) {
1306        if (cd1[i].getColumnName()[0].equalsIgnoreCase("null")) {
1307          cd1[i].setDatatype(cd2[i].getDatatype());
1308        }
1309        if (cd2[i].getColumnName()[0].equalsIgnoreCase("null")) {
1310          cd2[i].setDatatype(cd1[i].getDatatype());
1311        }
1312      }
1313    }
1314  }
1315}
1316
Popular Tags