KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.
2     booleanvalueexpression.predicates;
3
4 import java.util.*;
5
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.sql99.common.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.
11     booleanvalueexpression.*;
12 import com.daffodilwoods.daffodildb.server.sql99.expression.expressionprimary.*;
13 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
14 import com.daffodilwoods.daffodildb.server.sql99.token.*;
15 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
16 import com.daffodilwoods.daffodildb.utils.comparator.*;
17 import com.daffodilwoods.database.resource.*;
18 import com.daffodilwoods.database.utility.*;
19 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
20
21 /**
22  * A special type of predicate that allows user to check for any specific value
23  * in the specified range or beyond certain specified range, resulting in the
24  * need for a specific class. The BETWEEN Predicate is used to find all the
25  * values that lies between the two values.The BETWEEN predicate determines if
26  * a value is between a range of values.
27  * Syntax
28  * <between predicate> ::=Expression1 [ NOT ] BETWEEN [ ASYMMETRIC | SYMMETRIC ]Expression2 AND Expression3
29  */

30
31 public class betweenpredicate
32     extends PredicateAbstract
33     implements predicate, OperatorConstants, Datatypes, /*booleanterm,*/
34     /*IntegerPool, */
35     ExecutionPlanConstants, SimpleConstants {
36
37   /**
38    * The class representing expression indicating upper range.
39    */

40   public valueexpressionwithoutboolean _valueexpressionwithoutboolean0;
41
42   public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221;
43
44   /**
45    * The class representing expression indicating lower range.
46    */

47   public valueexpressionwithoutboolean _valueexpressionwithoutboolean2;
48
49   /**
50    * Optional Clause representing SYMMETRIC / UNSYMMETRIC clause.
51    * UNSYMMETRIC means boundary value is included while
52    * SYMMETRIC meansboundary value is not included.
53    * By Default it is UNSYMMETRIC.
54    */

55
56   public symmetricoption _Optsymmetricoption3;
57
58   public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442554;
59
60   public SRESERVEDWORD1206543922 _OptSRESERVEDWORD12065439225;
61
62   /**
63    *The class representing expression representing value that 'll be checked for teh given range.
64    */

65   public rowvalueexpressionwithoutboolean _rowvalueexpressionwithoutboolean6;
66
67   /**
68    *subQueryFlag is a flag used to indicate whether subQuery is involved in the condition or not.
69    */

70   private Boolean JavaDoc subQueryFlag = Boolean.FALSE;
71
72   boolean asymmetric = true;
73
74   private int[] appropriateDataTypes;
75
76   /**
77    * Comparator used for first and second operand
78    * For Example:
79    * A between 2 and 3
80    * then comparator1 is initialized with the help of 1 and 2 operand [A and 2].
81    */

82   private SuperComparator comparator1;
83
84   /**
85    * Comparator used for first and third operand
86    * For Example:
87    * A between 2 and 3
88    * then comparator1 is initialized with the help of 1 and 3 operand [A and 3].
89    */

90   private SuperComparator comparator2;
91
92   /**
93    * Methods Calculates cost of solving this predicate on the rows passed.
94    * @param rowCount, rows is the total no of rows on which predicate will be solved
95    * @param index, flag indicating Index is choosen or not.
96    * @return
97    * @throws DException
98    */

99
100   public double getCost(long rowCount, boolean index) throws DException {
101     rowCount *= rowCount * (CostFactorConstants.GREATERTHANEQUALTO / 100) *
102         (CostFactorConstants.GREATERTHANEQUALTO / 100);
103     if (index) {
104       rowCount *= CostFactorConstants.INDEXPREDICATE / 100;
105     }
106     return rowCount;
107   }
108
109   /**
110    * Returns Qualified Condition in case of qualified join.
111    * TableDetails passed represents the tables involved on right side of LOJ and on left side of ROJ.
112    * Algo:
113    * 1) We extract unique tables involved in the predicate.
114    * 2) If tables involed does not match with the passed tables, then we make onCondition, otherwise.
115    * 3) We make BVESingleTablePlan for each passed tables.
116    * For Example:
117    * A LOJ B on A.a1 between 2 and 3
118    * In the above example, Table involved in predicate is one, i.e. A and it lies on the left side of LOJ,
119    * then we solve this condition above LOJ as onCondition
120    *
121    * A LOJ B on B.b1 between 2 and 3
122    * In the above example, Table involved in predicate is one, i.e. B and it lies on the right side of LOJ,
123    * then we solve shift this condition to single Table Level
124    *
125    * @param tableDetails
126    * @return
127    * @throws DException
128    */

129
130   public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws
131       DException {
132     ArrayList uniqueTableList = getUniqueTableDetails(new ArrayList(),
133         columnDetails);
134     if (uniqueTableList.size() != 1) {
135       return new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this));
136     }
137     QualifiedBVE qualifiedBVE = getQualifiedBVEifBelongsToSingleTablePlan(
138         tableDetails, uniqueTableList);
139     if (qualifiedBVE == null) {
140       qualifiedBVE = new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this));
141     }
142     return qualifiedBVE;
143   }
144
145   private QualifiedBVE getQualifiedBVEifBelongsToSingleTablePlan(TableDetails[]
146       planTableDetails, ArrayList uniqueTableDetails) throws DException {
147     int length = planTableDetails.length;
148     TableDetails conditionTableDetails = (TableDetails) uniqueTableDetails.get(
149         0);
150     QualifiedBVE qualifiedBVE = null;
151     for (int j = 0; j < length; j++) {
152       if (planTableDetails[j] == conditionTableDetails) {
153         BVESingleTablePlan bveSingleTablePlan = new BVESingleTablePlan( (
154             booleanvalueexpression) BVEPlanMerger.getBooleanFactor(this),
155             conditionTableDetails);
156         BVESingleTablePlan[] bveSTPArray = new BVESingleTablePlan[] {
157             bveSingleTablePlan};
158         qualifiedBVE = new QualifiedBVE(bveSTPArray, null);
159         return qualifiedBVE;
160       }
161     }
162     return null;
163   }
164
165   /*
166       private ArrayList getUniqueTableDetails() throws DException {
167      ArrayList uniqueTableDetails = new ArrayList();
168      int cLength = columnDetails.length;
169      for (int i = 0; i < cLength; i++) {
170         int type = columnDetails[i].getType();
171         if (type == REFERENCE) {
172            TableDetails tableDetails = columnDetails[i].getTableDetails();
173            if (!uniqueTableDetails.contains(tableDetails)) {
174               uniqueTableDetails.add(tableDetails);
175            }
176         }
177         if (type == SCALARFUNCTION || type == CASEEXPRESSION) {
178            uniqueTableDetails.clear();
179            return uniqueTableDetails;
180         }
181      }
182      return uniqueTableDetails;
183       }
184    */

185
186
187   /**
188    * Returns predicate type:
189    * If Not is present then predicate type NOTBETWEEN is returned
190    * If Not is not present then type RANGE_PREDICATE is returned
191    * @return
192    * @throws DException
193    */

194
195   public int getPredicateType() throws DException {
196     if (_OptSRESERVEDWORD12065439225 != null) {
197       return OperatorConstants.NOTBETWEEN;
198     }
199     return OperatorConstants.RANGE_PREDICATE;
200   }
201
202   /** Method decides whether this predicate can be solved by Index or not.
203    * Cases for which Predicate can be solved as NonIndexed Condition :
204    * 1) If predicate involves subquery.
205    * 2) If NOT is present in the predicate
206    * In all other cases we can choose index in predicate.
207    * If SYMMETRIC option is present then Boundaries are excluded.
208    * If ASYMMETRIC option is present then Boundaries are included.
209    * @param allColumnPredicates
210    * @throws DException
211    */

212
213   public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws
214       DException {
215     if (_OptSRESERVEDWORD12065439225 != null || checkForSubQuery()) { // not between
216
allColumnPredicates.addToNonIndex(BVEPlanMerger.getBooleanFactor(this));
217       return;
218     }
219     if (_Optsymmetricoption3 != null) {
220       String JavaDoc option = (String JavaDoc) _Optsymmetricoption3.run(null);
221       if (option.trim().equalsIgnoreCase("SYMMETRIC")) { // BOUNDARY EXCLUDED
222
setColumnPredicates(OperatorConstants.GREATERTHAN,
223                             OperatorConstants.LESSTHAN, allColumnPredicates);
224         return;
225       }
226     }
227     setColumnPredicates(OperatorConstants.GREATERTHANEQUALTO,
228                         OperatorConstants.LESSTHANEQUALTO, allColumnPredicates);
229   }
230
231   private void setColumnPredicates(int operator1, int operator2,
232                                    _AllColumnPredicates allColumnPredicates) throws
233       DException {
234     comparisonpredicate leftPredicate = new comparisonpredicate(
235         _rowvalueexpressionwithoutboolean6, operator1,
236         _valueexpressionwithoutboolean2,
237         getColumns(_rowvalueexpressionwithoutboolean6.getColumnDetails(),
238                    _valueexpressionwithoutboolean2.getColumnDetails()));
239     comparisonpredicate rightPredicate = new comparisonpredicate(
240         _rowvalueexpressionwithoutboolean6, operator2,
241         _valueexpressionwithoutboolean0,
242         getColumns(_rowvalueexpressionwithoutboolean6.getColumnDetails(),
243                    _valueexpressionwithoutboolean0.getColumnDetails()));
244     leftPredicate.setColumnPredicates(allColumnPredicates);
245     rightPredicate.setColumnPredicates(allColumnPredicates);
246   }
247
248   /**
249    * Returns a BVEConstants member telling the BVEPlanType of instance on which
250    * this method is invoked.<p>
251    * If this method finds any column of GROUPING type then it returns
252    * BVEConstants.BVEAGGREGATE.<p>
253    * If it is not an aggregate plan, then it check for ALLTABLEPLAN
254    * type by checking existence of CASE Expression OR SubQuery and
255    * ComplexInnerQuery. If founds any then returns BVEConstants.BVEALLTABLEPLAN.<p>
256    * If both cases fail it check for table count for this predicate,<p>
257    * If table count is One, returns BVEConstants.BVESINGLETABLEPLAN;<p>
258    * If Two, returns BVEConstants.BVEJOINRELATION;<p>
259    * Otherwise BVEConstants.BVEALLTABLEPLAN.<p>
260    * @param tableList An empty ArrayList which is filled in this method with
261    * table names used in this predicate.
262    * @return BVEConstants.MEMBER.
263    * @throws DException
264    */

265
266   private int getBVEPlanType(ArrayList tableList) throws DException {
267     /*Done by vibha to Acc to findbug */
268     subQueryFlag = Utility.getBooleanValue(checkForSubQuery());
269     for (int i = 0; i < columnDetails.length; i++) {
270
271       int type = columnDetails[i].getType();
272       if (type == GROUPING) {
273         return BVEConstants.BVEAGGREGATEPLAN;
274       }
275       if (type == SCALARFUNCTION || type == CASEEXPRESSION ||
276           type == FUNCTIONAL) {
277         return BVEConstants.BVEALLTABLEPLAN;
278       }
279       if (type != CONSTANT) {
280         TableDetails tableDetail = columnDetails[i].getTableDetails();
281         if (tableDetail != null && !tableList.contains(tableDetail)) {
282           tableList.add(tableDetail);
283         }
284       }
285     }
286     if (checkForSubQuery() && checkForComplexInnerQuery()) {
287       return BVEConstants.BVEALLTABLEPLAN;
288     }
289     int size = tableList.size();
290     if (size == 1) {
291       return BVEConstants.BVESINGLETABLEPLAN;
292     }
293     else if (size == 2) {
294       return BVEConstants.BVEJOINRELATION;
295     }
296     else {
297       return BVEConstants.BVEALLTABLEPLAN;
298     }
299   }
300
301   /**
302    * Returns _BVEPlan based on the type of instance of this Object.<p>
303    * <pre>
304    * instance type returned plan
305    * -------------------------------------------------------------------------
306    * BVEConstants.BVEAGGREGATEPLAN BVEAggregatePlan
307    * BVEConstants.BVEALLTABLEPLAN BVEAllTablePlan
308    * BVEConstants.BVESINGLETABLEPLAN BVESingleTablePlan
309    * BVEConstants.BVEJOINRELATION BVEAllTablePlan
310    *
311    * <pre>
312    * In case of BVEJOINRELATION, a _JoinRelation is wrapped in
313    * AllTablesJoinRelation and AllTablesJoinRelation in BVEAllTablePlan.
314    * and returned.<p>
315    * @return
316    * @throws DException
317    */

318
319   public _BVEPlan getExecutionPlan() throws DException {
320     ArrayList tableList = new ArrayList();
321     int type = getBVEPlanType(tableList);
322     switch (type) {
323       case BVEConstants.BVEAGGREGATEPLAN:
324         return new BVEAggregatePlan(BVEPlanMerger.getBooleanFactor(this));
325       case BVEConstants.BVEALLTABLEPLAN:
326         return new BVEAllTablePlan(null, null, BVEPlanMerger.getBooleanFactor(this));
327       case BVEConstants.BVESINGLETABLEPLAN:
328         return new BVESingleTablePlan(BVEPlanMerger.getBooleanFactor(this),
329                                       (TableDetails) tableList.get(0));
330       case BVEConstants.BVEJOINRELATION:
331         TableDetails[] tableDetails = (TableDetails[]) tableList.toArray(new
332             TableDetails[2]);
333         _JoinRelation sr = new SimpleRelation(tableDetails,
334                                               BVEPlanMerger.getBooleanFactor(this));
335         AllTablesJoinRelation atjr = new AllTablesJoinRelation(new
336             _JoinRelation[] {sr});
337         return new BVEAllTablePlan(null, atjr, null);
338     }
339     throw new DException("DSE3547", new Object JavaDoc[] {this.toString()});
340   }
341
342   /**
343    * ComplexInnerQuery means that subQuery contains the column of outer query.
344    * In this case this condition is treated as remaining condition.
345    * @return
346    * @throws DException
347    */

348
349   private boolean checkForComplexInnerQuery() throws DException {
350     _Reference[] references = getReferences(null);
351     int length = references.length;
352     for (int i = 0; i < length; i++) {
353       if (references[i].getReferenceType() == SUBQUERY) {
354         if ( ( (subquery) references[i]).getUnderlyingReferences() != null) {
355           return true;
356         }
357       }
358     }
359     return false;
360   }
361
362   /**
363    * This method performs the semantic checking of cardinality and initiates
364    * checking of underlying children. Some Runtime checking like checking of
365    * dataType are performed at runtime.
366    * @param parent
367    * @return
368    * @throws DException
369    */

370
371   public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[]
372       checkSemantic(com.daffodilwoods.daffodildb.server.serversystem.
373
                    _ServerSession parent) throws DException {
374     _Reference[] reference = GeneralPurposeStaticClass.getJointReferences(
375         _rowvalueexpressionwithoutboolean6.checkSemantic(parent),
376         _valueexpressionwithoutboolean2.checkSemantic(parent));
377     reference = GeneralPurposeStaticClass.getJointReferences(reference,
378         _valueexpressionwithoutboolean0.checkSemantic(parent));
379     checkCardinalityChecking();
380     checkDataTypes(parent);
381     return reference;
382     /*dend*/
383   }
384
385   private void checkDataTypes(_ServerSession session) throws DException {
386     int[] dt1 = _rowvalueexpressionwithoutboolean6.getByteComparison(session).
387         getDataTypes();
388     int[] dt2 = _valueexpressionwithoutboolean2.getByteComparison(session).
389         getDataTypes();
390     int[] dt3 = _valueexpressionwithoutboolean0.getByteComparison(session).
391         getDataTypes();
392     Check.checkForDataTypes(dt1, dt2);
393     Check.checkForDataTypes(dt1, dt3);
394     appropriateDataTypes = getAppropriateDataTypes(getAppropriateDataTypes(dt1,
395         dt2), dt3);
396     setDataTypeforParameterMarker();
397   }
398
399   /**
400    * Checks Cardinality of Between Predicate. -1 is to avoid checking of
401    * Question marks.
402    * Cardinality Checking
403    * Examples
404    * select * from a where a between (2,3) and (3,4)
405    * above query is not valid as cardinality does not matches.
406    *
407    * select * from a where (a,b) between (2,3) and (3,4,5)
408    * above query is not valid as cardinality does not matches.
409    *
410    * @throws DException
411    */

412
413   private void checkCardinalityChecking() throws DException {
414     int c1 = _rowvalueexpressionwithoutboolean6.getCardinality();
415     int c2 = _valueexpressionwithoutboolean2.getCardinality();
416     int c3 = _valueexpressionwithoutboolean0.getCardinality();
417     if (c1 != -1 && c2 != -1 && c3 != -1 && (c1 != c2 || c2 != c3 || c1 != c3)) {
418       throw new DException("DSE214", null);
419     }
420   }
421
422   /**
423    * This method is called from Browser, when Parameterized query is fired from Browser.
424    * With the help of ParameterInfo Browser open ups daialog box(labelled by its corresponding name)
425    * for each question mark to put the values of question mark.
426    * @return
427    * @throws DException
428    */

429
430   public ParameterInfo[] getParameterInfo() throws DException {
431     boolean isSubQuery = false;
432     ParameterInfo[] p1 = _rowvalueexpressionwithoutboolean6.getParameterInfo();
433     ParameterInfo[] p2 = _valueexpressionwithoutboolean2.getParameterInfo();
434     ParameterInfo[] p3 = _valueexpressionwithoutboolean0.getParameterInfo();
435     ArrayList aList = new ArrayList(5);
436
437     int count = 0, maxDataType = -1;
438     for (int i = 0; i < p1.length; i++) {
439       if (p1[i].getSubQuery()) {
440         if (p1[i].getParameterInfoArray() != null)
441           aList.addAll(Arrays.asList(p1[i].getParameterInfoArray()));
442       }
443       else if (p1[i].getQuestionMark()) {
444          if (i< appropriateDataTypes.length && p1[i].getDataType() == -1)
445                 p1[i].setDataType(appropriateDataTypes[i]);
446       aList.add(p1[i]);
447       }
448
449     }
450
451     for (int i = 0; i < p2.length; i++) {
452       if (p2[i].getSubQuery()) { //if P2 has SubQuery
453
ParameterInfo[] array = p2[i].getParameterInfoArray();
454         if (array != null) {
455           aList.addAll(Arrays.asList(array));
456         }
457         isSubQuery = true;
458       }
459       else if (p2[i].getQuestionMark()) { //Check for the Parameter marker
460
if (i< appropriateDataTypes.length && p2[i].getDataType() == -1 ) {
461           p2[i].setDataType(appropriateDataTypes[i]);
462         }
463         aList.add(p2[i]);
464       }
465     }
466     for (int i = 0; i < p3.length; i++) {
467       if (p3[i].getSubQuery()) {
468         ParameterInfo[] array = p3[i].getParameterInfoArray();
469         if (array != null) {
470           aList.addAll(Arrays.asList(array));
471         }
472         isSubQuery = true;
473       }
474       else if (p3[i].getQuestionMark()) {
475         if (i< appropriateDataTypes.length && p3[i].getDataType() == -1 ) {
476            p3[i].setDataType(appropriateDataTypes[i]);
477         }
478         aList.add(p3[i]);
479       }
480     }
481
482     return (ParameterInfo[]) aList.toArray(new ParameterInfo[0]);
483   }
484
485
486   /**
487      public ParameterInfo[] getParameterInfo() throws DException {
488    boolean isSubQuery = false;
489    ParameterInfo[] p1 = _rowvalueexpressionwithoutboolean6.getParameterInfo();
490    ParameterInfo[] p2 = _valueexpressionwithoutboolean2.getParameterInfo();
491    ParameterInfo[] p3 = _valueexpressionwithoutboolean0.getParameterInfo();
492    ArrayList aList = new ArrayList(5);
493
494    int count = 0, maxDataType = -1;
495
496
497    ParameterInfo[] requiredParameterInfo1=getRequiredParameterInfo(p1);
498      ParameterInfo[] requiredParameterInfo2=getRequiredParameterInfo(p2);
499      ParameterInfo[] requiredParameterInfo3=getRequiredParameterInfo(p3);
500     if(requiredParameterInfo1 !=null)
501       for (int i = 0; i < requiredParameterInfo1.length; i++) {
502     if(i <appropriateDataTypes.length && requiredParameterInfo1[i].getDataType()==-1){
503       requiredParameterInfo1[i].setDataType(appropriateDataTypes[i]);
504     requiredParameterInfo1[i].setName("Expr-"+count++);
505     }
506       }
507
508
509     if(requiredParameterInfo2 !=null)
510      for (int i = 0; i < requiredParameterInfo2.length; i++) {
511    if(i <appropriateDataTypes.length && requiredParameterInfo2[i].getDataType()==-1){
512      requiredParameterInfo2[i].setDataType(appropriateDataTypes[i]);
513      requiredParameterInfo2[i].setName("Expr-"+count++);
514    }
515      }
516
517    if(requiredParameterInfo3 !=null)
518       for (int i = 0; i < requiredParameterInfo3.length; i++) {
519     if(i <appropriateDataTypes.length && requiredParameterInfo2[i].getDataType()==-1){
520       requiredParameterInfo3[i].setDataType(appropriateDataTypes[i]);
521     requiredParameterInfo3[i].setName("Expr-"+count++);
522     }
523       }
524
525
526    return (ParameterInfo[]) aList.toArray(new ParameterInfo[0]);
527      }
528    */

529
530   public AbstractRowValueExpression[] getChilds() {
531     AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {
532         (AbstractRowValueExpression) (_rowvalueexpressionwithoutboolean6),
533         (AbstractRowValueExpression) (_valueexpressionwithoutboolean2),
534         (AbstractRowValueExpression) (_valueexpressionwithoutboolean0)};
535     return childs;
536   }
537
538   public void setDefaultValues(_VariableValueOperations variableValueOperation) throws
539       DException {
540   }
541
542   /**
543    * This method returns the estimate of the rows remaining after the execution
544    * of this condition on passed number of rows.
545    * @param noOfRows
546    * @return
547    * @throws DException
548    */

549
550   public long getEstimatedRows(long noOfRows) throws DException {
551     return noOfRows * (CostFactorConstants.GREATERTHANEQUALTO / 100) *
552         (CostFactorConstants.GREATERTHANEQUALTO / 100);
553   }
554
555   /**
556    * This is the most important method in this class that is executed maximum
557    * times. The basic purpose of the run method is to evaluate the condition.
558    * The argument is actually some VariableValue, that is passed for the
559    * purpose of providing the value of any column (which is actually an
560    * instanceof _Reference) used in the condition. The return type of the run
561    * method is a fieldBase in the form of Object class.
562    *
563    * Run Method returns value 0, -1, 1, -2 or 2 on the basis whether predicate
564    * solves on the current record or not.
565    * Steps:
566    * 1) On Calling run we retrieves values for _rowvalueexpressionwithoutboolean6,
567    * _valueexpressionwithoutboolean2 and _valueexpressionwithoutboolean0.
568    * 2) Thereafter, appropriate comparator is initialised by catching NPE for
569    * the first time.
570    * Comparator is decided on the basis of Byte Comparison usage.
571    * If Bytes Comparison is allowed
572    * then appropriate comparators are made for 1st and 2nd argument & 1st and 3rd argument.
573    * flag asymmetric is initialised for calling up appropriate procedure.
574    *
575    * If Bytes Comparison is not allowed
576    * CPckfduDpnqbsbups is initialised for 1st and 2nd argument & 1st and 3rd argument.
577    * 3) On the basis of compare value from comparator appropriate FiledBase is returned
578    * 4) if NOT presents and compare value is 0 then 1 is returned otherwise 0 is returned
579    * @param object
580    * @return
581    * @throws com.daffodilwoods.database.resource.DException
582    */

583   public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.
584
      DException {
585     Object JavaDoc result1 = _rowvalueexpressionwithoutboolean6.run(object);
586     Object JavaDoc result2 = _valueexpressionwithoutboolean2.run(object);
587     Object JavaDoc result3 = _valueexpressionwithoutboolean0.run(object);
588     Object JavaDoc finalResult = null;
589     try {
590       if (comparator1 == null) {
591         throw new NullPointerException JavaDoc();
592       }
593     }
594     catch (NullPointerException JavaDoc npe) {
595       asymmetric = _Optsymmetricoption3 == null ? true
596           :
597           ( (String JavaDoc) _Optsymmetricoption3.run(null)).equalsIgnoreCase(
598           "ASYMMETRIC");
599       ByteComparison bc1 = _rowvalueexpressionwithoutboolean6.getByteComparison(
600           object);
601       ByteComparison bc2 = _valueexpressionwithoutboolean2.getByteComparison(
602           object);
603       ByteComparison bc3 = _valueexpressionwithoutboolean0.getByteComparison(
604           object);
605       comparator1 = getAppropriateComparator(bc1, bc2, result1, result2, null);
606       comparator2 = getAppropriateComparator(bc1, bc3, result1, result3, null);
607     }
608     if (asymmetric) {
609       finalResult = handlingOfAsymmetric(result1, result2, result3, false);
610     }
611     else {
612       finalResult = handlingOfSymmetric(result1, result2, result3, false);
613     }
614     if (_OptSRESERVEDWORD12065439225 != null) {
615       return finalResult.hashCode() == 0 ? IntegerPool.Integer1
616           : finalResult.hashCode() == -2
617           ? finalResult
618           : finalResult.hashCode() == 2
619           ? finalResult
620           : IntegerPool.Integer0;
621
622     }
623     return finalResult;
624   }
625
626   /**
627    * Asymmetric Module is used to compare values including boundaries. therefore
628    * operator is GREATERTHANEQUALTO and LESSTHANEQUALTO.
629    * For Example if predicate is A between 2 and 3, then
630    * @param result1 is A
631    * @param result2 is 2
632    * @param result3 is 3
633    * @param nullSortedHigh
634    * @return
635    * @throws DException
636    */

637   private Object JavaDoc handlingOfAsymmetric(Object JavaDoc result1, Object JavaDoc result2,
638                                       Object JavaDoc result3, boolean nullSortedHigh) throws
639       DException {
640     int cmp;
641    cmp = comparator1.compare(result1, result2);
642     Object JavaDoc obj1 = booleanResult[GREATERTHANEQUALTO - 1][cmp + 2];
643     if (obj1.hashCode() != 0) {
644       return obj1;
645     }
646     cmp = comparator2.compare(result1, result3);
647     return booleanResult[LESSTHANEQUALTO - 1][cmp + 2];
648   }
649
650   /**
651    * Symmetric Module is used to compare values excluding boundaries. therefore
652    * operator is GREATERTHAN and LESSTHAN.
653    * For Example if predicate is A between 2 and 3, then
654    * @param result1 is A
655    * @param result2 is 2
656    * @param result3 is 3
657    * @param nullSortedHigh
658    * @return
659    * @throws DException
660    */

661   private Object JavaDoc handlingOfSymmetric(Object JavaDoc result1, Object JavaDoc result2,
662                                      Object JavaDoc result3, boolean nullSortedHigh) throws
663       DException {
664     int cmp;
665     cmp = comparator1.compare(result1, result2);
666     Object JavaDoc obj1 = booleanResult[GREATERTHAN - 1][cmp + 2];
667     if (obj1.hashCode() != 0) {
668       return obj1;
669     }
670     cmp = comparator2.compare(result1, result3);
671     return booleanResult[LESSTHAN - 1][cmp + 2];
672   }
673
674   /**
675    * This method is called from SelectedColumnIterator. When execute is called
676    * with different type of values of Parameters. In this case we've to initialize
677    * the comparators again.
678    * @throws DException
679    */

680
681   public void releaseResource() throws DException {
682     super.releaseResource();
683     comparator1 = comparator2 = null;
684   }
685
686   private ColumnDetails[] getColumns(ColumnDetails[] columns1,
687                                      ColumnDetails[] columns2) throws
688       DException {
689     int length1 = columns1.length;
690     int length2 = columns2.length;
691     ColumnDetails[] result = new ColumnDetails[columns1.length +
692         columns2.length];
693     int i = 0;
694     for (; i < length1; i++) {
695       result[i] = columns1[i];
696     }
697     for (int j = 0; j < length2; j++, i++) {
698       result[i] = columns2[j];
699     }
700     return result;
701   }
702
703   public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
704     betweenpredicate tempClass = new betweenpredicate();
705     tempClass._valueexpressionwithoutboolean0 = (valueexpressionwithoutboolean)
706         _valueexpressionwithoutboolean0.clone();
707     tempClass._SRESERVEDWORD12065439221 = (SRESERVEDWORD1206543922)
708         _SRESERVEDWORD12065439221.clone();
709     tempClass._valueexpressionwithoutboolean2 = (valueexpressionwithoutboolean)
710         _valueexpressionwithoutboolean2.clone();
711     if (_Optsymmetricoption3 != null) {
712       tempClass._Optsymmetricoption3 = (symmetricoption) _Optsymmetricoption3.
713           clone();
714     }
715     tempClass._SNONRESERVEDWORD1364442554 = (SNONRESERVEDWORD136444255)
716         _SNONRESERVEDWORD1364442554.clone();
717     if (_OptSRESERVEDWORD12065439225 != null) {
718       tempClass._OptSRESERVEDWORD12065439225 = (SRESERVEDWORD1206543922)
719           _OptSRESERVEDWORD12065439225.clone();
720     }
721     tempClass._rowvalueexpressionwithoutboolean6 = (
722         rowvalueexpressionwithoutboolean) _rowvalueexpressionwithoutboolean6.
723         clone();
724     try {
725       tempClass.getColumnDetails();
726     }
727     catch (DException ex) {
728       throw new RuntimeException JavaDoc(ex.getMessage());
729     }
730     return tempClass;
731   }
732
733   public String JavaDoc toString() {
734     StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
735     sb.append(" ");
736     sb.append(_rowvalueexpressionwithoutboolean6);
737     sb.append(" ");
738     if (_OptSRESERVEDWORD12065439225 != null) {
739       sb.append(_OptSRESERVEDWORD12065439225);
740     }
741     sb.append(" ");
742     sb.append(_SNONRESERVEDWORD1364442554);
743     sb.append(" ");
744     if (_Optsymmetricoption3 != null) {
745       sb.append(_Optsymmetricoption3);
746     }
747     sb.append(" ");
748     sb.append(_valueexpressionwithoutboolean2);
749     sb.append(" ");
750     sb.append(_SRESERVEDWORD12065439221);
751     sb.append(" ");
752     sb.append(_valueexpressionwithoutboolean0);
753     return sb.toString();
754   }
755
756   private int[] getAppropriateDataTypes(int[] dt1, int[] dt2) throws DException {
757     int[] maxdataType = new int[dt1.length];
758     for (int i = 0; i < dt1.length; i++) {
759       maxdataType[i] = dt1[i] > dt2[i] ? dt1[i] : dt2[i];
760     }
761     return maxdataType;
762   }
763
764   private void setDataTypeforParameterMarker() throws DException {
765     for (int i = 0; i < appropriateDataTypes.length; i++) {
766       if (appropriateDataTypes[i] == -1)
767         appropriateDataTypes[i] = BIGDECIMAL;
768     }
769   }
770
771
772 }
773
Popular Tags