KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import com.daffodilwoods.daffodildb.server.sql99.common.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.listenerevents.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
11 import com.daffodilwoods.daffodildb.server.sql99.expression.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.daffodildb.utils.field.*;
18 import com.daffodilwoods.database.resource.*;
19 import com.daffodilwoods.database.utility.*;
20 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.RightIndexed;
21 import com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.fromclause.tablesubquery;
22 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
23 import com.daffodilwoods.daffodildb.server.sql99.dql.queryexpression.queryspecification.derivedcolumn;
24
25 public class inpredicate extends PredicateAbstract implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, predicate, OperatorConstants, Datatypes, IntegerPool, ExecutionPlanConstants, SimpleConstants {
26    public inpredicatevalue _inpredicatevalue0;
27    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221;
28    public SRESERVEDWORD1206543922 _OptSRESERVEDWORD12065439222;
29    public rowvalueexpressionwithoutboolean _rowvalueexpressionwithoutboolean3;
30
31    private Boolean JavaDoc subQueryFlag = Boolean.FALSE;
32    private Boolean JavaDoc complexInnerQueryFlag = Boolean.FALSE;
33    private boolean canByteCached;
34
35    public double getCost(long rowCount, boolean index) throws DException {
36       return rowCount;
37    }
38
39    public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws DException {
40      ArrayList uniqueTableDetailsList = getUniqueTableDetails(new ArrayList(),columnDetails);
41       if (uniqueTableDetailsList.size() != 1) {
42          return new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this));
43       }
44       QualifiedBVE qualifiedBVE = getQualifiedBVEifBelongsToSingleTablePlan(tableDetails, uniqueTableDetailsList);
45       if (qualifiedBVE == null) {
46          qualifiedBVE = new QualifiedBVE(null, BVEPlanMerger.getBooleanFactor(this));
47       }
48       return qualifiedBVE;
49    }
50
51    private QualifiedBVE getQualifiedBVEifBelongsToSingleTablePlan(TableDetails[] planTableDetails, ArrayList uniqueTableDetailsList) throws DException {
52       TableDetails conditionTableDetail = ( (TableDetails[]) uniqueTableDetailsList.toArray(new TableDetails[uniqueTableDetailsList.size()]))[0];
53       for (int j = 0, length = planTableDetails.length; j < length; j++) {
54          if (planTableDetails[j] == conditionTableDetail) {
55             BVESingleTablePlan bveSingleTablePlan = new BVESingleTablePlan(BVEPlanMerger.getBooleanFactor(this), conditionTableDetail);
56             return new QualifiedBVE(new BVESingleTablePlan[] {bveSingleTablePlan}
57                                     , null);
58          }
59       }
60       return null;
61    }
62 /*
63    private ArrayList getUniqueTableDetails() throws DException {
64       ArrayList uniqueTableDetails = new ArrayList();
65       for (int i = 0, length = columnDetails.length; i < length; i++) {
66          int type = columnDetails[i].getType();
67          if (type == REFERENCE) {
68             TableDetails table = columnDetails[i].getTableDetails();
69             if (!uniqueTableDetails.contains(table)) {
70                uniqueTableDetails.add(table);
71             }
72          }
73          if (type == SCALARFUNCTION || type == CASEEXPRESSION) {
74             uniqueTableDetails.clear();
75             return uniqueTableDetails;
76          }
77       }
78       return uniqueTableDetails;
79    }
80 */

81    public int getPredicateType() throws DException {
82       if (_OptSRESERVEDWORD12065439222 != null) {
83          return OperatorConstants.NOTIN;
84       }
85       return OperatorConstants.IN;
86    }
87
88
89
90
91    /*
92     * Method reWritten by Kaushik on 20/07/2004 to use Index(if available) in InPredicate
93     * Use of Index Supported only when left side contains a single column of
94     * reference type and invaluelist contains constants only. e.g.
95     * examid in (1,2,4,5)
96     */

97
98    public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws DException {
99      if(_OptSRESERVEDWORD12065439222 == null && (_inpredicatevalue0 instanceof tablesubquery)==false){
100        ColumnDetails[] columnDetails1 = _rowvalueexpressionwithoutboolean3.getColumnDetails();
101        ColumnDetails[] columnDetails2 = _inpredicatevalue0.getColumnDetails();
102
103
104        /* Done by Kaushik on 23/08/2004 to prevent shifting of in containing subquery to MultiValueIndexed*/
105        /* if ChecForSubQuery doesnot returns correct value tahn check this method in invauelist class */
106        boolean b = !_inpredicatevalue0.checkForSubQuery();
107        for (int i = 0; i < columnDetails2.length; i++) { //check for underLyingReference is added by sandeep to sort compiere problem,bug # 13435
108
if ((columnDetails2[i].getType() != CONSTANT && !columnDetails2[i].getQuestion()) || columnDetails2[i].getUnderLyingReference()) {
109              b = false;
110              break;
111           }
112        }
113        if (columnDetails1.length == 1 && columnDetails1[0].getType() == REFERENCE && b) {
114
115          SingleColumnPredicate singleColumnPredicate = new SingleColumnPredicate();
116          singleColumnPredicate.setPredicate(this);
117          singleColumnPredicate.setColumnName(columnDetails[0].getColumn());
118          allColumnPredicates.addSinglePredicate(new SingleColumnPredicate[] {singleColumnPredicate});
119          return;
120        }
121      }
122      allColumnPredicates.addToNonIndex(new booleanfactor(new booleantest(this)));
123    }
124    /**
125     * Returns a BVEConstants member telling the BVEPlanType of instance on which
126     * this method is invoked.<p>
127     * If this method finds any column of GROUPING type then it returns
128     * BVEConstants.BVEAGGREGATE.<p>
129     * If it is not an aggregate plan, then it check for ALLTABLEPLAN
130     * type by checking existence of CASE Expression OR SubQuery and
131     * ComplexInnerQuery. If founds any then returns BVEConstants.BVEALLTABLEPLAN.<p>
132     * If both cases fail it check for table count for this predicate,<p>
133     * If table count is One, returns BVEConstants.BVESINGLETABLEPLAN;<p>
134     * If Two, returns BVEConstants.BVEJOINRELATION;<p>
135     * Otherwise BVEConstants.BVEALLTABLEPLAN.<p>
136     * @param tableList An empty ArrayList which is filled in this method with
137     * table names used in this predicate.
138     * @return BVEConstants.MEMBER.
139     * @throws DException
140     */

141    private int getBVEPlanType(ArrayList tableList) throws DException {
142      /*done by vibha acc to findbug*/
143      Utility.getBooleanValue(checkForSubQuery());
144       for (int i = 0; i < columnDetails.length; i++) {
145          int type = columnDetails[i].getType();
146          if (type == GROUPING) {
147             return BVEConstants.BVEAGGREGATEPLAN;
148          }
149          if (type == SCALARFUNCTION || type == CASEEXPRESSION || type == FUNCTIONAL
150              || type == USERFUNCTION ) {
151             return BVEConstants.BVEALLTABLEPLAN;
152          }
153          if (type != CONSTANT) {
154             TableDetails tableDetail = columnDetails[i].getTableDetails();
155             if (tableDetail != null && !tableList.contains(tableDetail)) {
156                tableList.add(tableDetail);
157             }
158          }
159       }
160       if (subQueryFlag.booleanValue() && (complexInnerQueryFlag = new Boolean JavaDoc(checkForComplexInnerQuery())).booleanValue()) {
161          return BVEConstants.BVEALLTABLEPLAN;
162       }
163       int size = tableList.size();
164       if (size == 1) {
165          return BVEConstants.BVESINGLETABLEPLAN;
166       } else if (size == 2) {
167          return BVEConstants.BVEJOINRELATION;
168       } else {
169          return BVEConstants.BVEALLTABLEPLAN;
170       }
171    }
172
173    /**
174     * Returns _BVEPlan based on the type of instance of this Object.<p>
175     * <pre>
176     * instance type returned plan
177     * -------------------------------------------------------------------------
178     * BVEConstants.BVEAGGREGATEPLAN BVEAggregatePlan
179     * BVEConstants.BVEALLTABLEPLAN BVEAllTablePlan
180     * BVEConstants.BVESINGLETABLEPLAN BVESingleTablePlan
181     * BVEConstants.BVEJOINRELATION BVEAllTablePlan
182     *
183     * <pre>
184     * In case of BVEJOINRELATION, a _JoinRelation is wrapped in
185     * AllTablesJoinRelation and AllTablesJoinRelation in BVEAllTablePlan.
186     * @return
187     * @throws DException
188     */

189    public _BVEPlan getExecutionPlan() throws DException {
190       ArrayList tableList = new ArrayList();
191       int type = getBVEPlanType(tableList);
192       switch (type) {
193          case BVEConstants.BVEAGGREGATEPLAN:
194             return new BVEAggregatePlan(BVEPlanMerger.getBooleanFactor(this));
195          case BVEConstants.BVEALLTABLEPLAN:
196             return new BVEAllTablePlan(null, null, BVEPlanMerger.getBooleanFactor(this));
197          case BVEConstants.BVESINGLETABLEPLAN:
198             return new BVESingleTablePlan(BVEPlanMerger.getBooleanFactor(this), (TableDetails) tableList.get(0));
199          case BVEConstants.BVEJOINRELATION:
200             TableDetails[] tableDetails = (TableDetails[]) tableList.toArray(new TableDetails[2]);
201             _JoinRelation sr = new SimpleRelation(tableDetails, BVEPlanMerger.getBooleanFactor(this));
202             AllTablesJoinRelation atjr = new AllTablesJoinRelation(new _JoinRelation[] {sr});
203             return new BVEAllTablePlan(null, atjr, null);
204       }
205       throw new DException("DSE3547", new Object JavaDoc[] {this.toString()});
206    }
207
208
209    private boolean checkForComplexInnerQuery() throws DException {
210       _Reference[] references = getReferences(null);
211       int length = references.length;
212       for (int i = 0; i < length; i++) {
213          if (references[i].getReferenceType() == SUBQUERY) {
214             _Reference[] underlyingReferences = ( (subquery) references[i]).getUnderlyingReferences();
215             if (underlyingReferences != null && underlyingReferences.length != 0) {
216                /**
217                 * Done by Kaushik on 16-06-2004
218                 * To optimize for problem of ? in inner query when distinct is used.
219                 * otherwise time taken was much more bcoz of making Btree.
220                 * */

221                for (int j = 0; j < underlyingReferences.length; j++) {
222                   if(underlyingReferences[j].getReferenceType()==VARIABLECOLUMN)
223                      continue;
224                   else
225                      return true;
226                }
227                return false;
228             }
229          }
230       }
231       return false;
232    }
233
234    public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[] checkSemantic(com.daffodilwoods.daffodildb.server.serversystem._ServerSession parent) throws DException {
235       getColumnDetails();
236       _Reference[] reference1 = GeneralPurposeStaticClass.getJointReferences(_rowvalueexpressionwithoutboolean3.checkSemantic(parent), _inpredicatevalue0.checkSemantic(parent));
237        checkForSubqueryInPredicate();
238       checkCardinalitySemantic();
239       if(reference1==null || reference1.length==0){ // put by kaushik on 16/07/2004 for Invalid Column problem
240
checkDataTypes(parent);
241       }
242       return reference1;
243    }
244
245    private void checkDataTypes(_ServerSession session) throws DException {
246       int[] dt1 = _rowvalueexpressionwithoutboolean3.getByteComparison(session).getDataTypes();
247       int[] dt2 = _inpredicatevalue0.getByteComparison(session).getDataTypes();
248       if (dt1.length > 1) {
249          if (dt2.length > 1) { // one length can be in case (a,b) in (?)
250
Check.checkForDataTypes(dt1, dt2);
251          }
252       } else if (dt2.length > 1) {
253          for (int i = 0; i < dt2.length; i++) {
254             Check.checkForDatatype(dt1[0], dt2[i]);
255          }
256       } else {
257          Check.checkForDataTypes(dt1, dt2);
258       }
259    }
260
261    /**
262     * Checks Cardinality of Between Predicate
263     * Cardinality Checking
264     * Examples
265     * select * from a where a in ((2,3))
266     * above query is not valid as cardinality does not matches.
267     *
268     * select * from a where (a,b) in ((2,3),(3,4,5))
269     * above query is not valid as cardinality does not matches.
270     *
271     * @throws DException
272     */

273    private void checkCardinalitySemantic() throws DException {
274       int cardinality1 = _rowvalueexpressionwithoutboolean3.getCardinality();
275       int cardinality2 = _inpredicatevalue0.getCardinality();
276       if (cardinality1 != -1 && cardinality2 != -1 && cardinality1 != cardinality2) {
277          throw new DException("DSE214", null);
278       }
279    }
280
281    private Boolean JavaDoc rightSubQuery = null;
282
283    public Object JavaDoc run(Object JavaDoc object) throws com.daffodilwoods.database.resource.DException {
284       Object JavaDoc fieldBase1 = _rowvalueexpressionwithoutboolean3.run(object);
285       if (rightSubQuery == null) {
286         /*done by vibha acc to findbug */
287           rightSubQuery = Utility.getBooleanValue( _inpredicatevalue0 instanceof tablesubquery);
288       }
289       if (rightSubQuery.booleanValue()) {
290          Object JavaDoc fieldBase2 = _inpredicatevalue0.run(object);
291          int cmp = handleSubQuery(fieldBase1, (_Iterator) fieldBase2, null, object);
292
293          return cmp == 0 ? (_OptSRESERVEDWORD12065439222 != null ? IntegerPool.Integer1 : IntegerPool.Integer0)
294              : (_OptSRESERVEDWORD12065439222 != null ? IntegerPool.Integer0 : IntegerPool.Integer1);
295       } else {
296         int cmp = handlingOFSimpleAndConstants(fieldBase1, canByteCached ? null : _inpredicatevalue0.run(object), null, object);
297          return _OptSRESERVEDWORD12065439222 == null ? cmp == 0 ? IntegerPool.Integer0 : IntegerPool.Integer1 : cmp != 0 ? IntegerPool.Integer0 : IntegerPool.Integer1;
298       }
299    }
300
301    private int[] getArrayOfDataType(ParameterInfo[] pi) throws DException {
302       int length = pi.length;
303       int[] obj = new int[length];
304       for (int i = 0; i < length; i++) {
305          obj[i] = pi[i].getDataType();
306       }
307       return obj;
308    }
309
310    public ParameterInfo[] getParameterInfo() throws DException {
311       int t;
312       ParameterInfo[] p1 = _rowvalueexpressionwithoutboolean3.getParameterInfo();
313       ParameterInfo[] p2 = _inpredicatevalue0.getParameterInfo();
314
315       ArrayList result = new ArrayList(5);
316       int length1 = p1.length, length2 = p2.length, count = 0, maxDataType = -1;
317       for (int i = 0; i < length2; i++) {
318          if (p2[i].getSubQuery()) {
319            ParameterInfo[] pa = p2[i].getParameterInfoArray();
320           /*Done by vibha to solve bug no 12106 check is done for null */
321             if (pa != null) {
322                result.addAll(Arrays.asList(pa));
323             }
324          } else if (p2[i].getQuestionMark()) {
325             int pos = i % length1;
326             if (!p1[pos].getQuestionMark()) {
327                if (length2 == 1) {
328                   if (length1 == 1) {
329                      p2[i].setName(p1[pos].getName());
330                      /* Next Three Lines Done by Kaushik on 15/09/2004 to solve Bug no. 11994 */
331                      p2[i].setDataType(p1[pos].getDataType());
332                   } else {
333                      p2[i].setDataType(Datatypes.ARRAY);
334                      p2[i].setSubType(getArrayOfDataType(p1));
335                   }
336                } else {
337                   /* Done by Kaushik to Solve Bug no. 11508 */
338                   p2[i].setName(p1[pos].getName()+"_"+ count++);
339                   p2[i].setDataType(p1[pos].getDataType());
340                }
341             }
342             result.add(p2[i]);
343             t = p2[i].getDataType();
344             if (maxDataType < t) {
345                maxDataType = t;
346             }
347          }
348       }
349       for (int i = length1 - 1; i >= 0; i--) {
350          if (p1[i].getQuestionMark()) {
351             result.add(0, p1[i]);
352          }
353          t = p1[i].getDataType();
354          if (maxDataType < t) {
355             maxDataType = t;
356          }
357       }
358       return (ParameterInfo[]) result.toArray(new ParameterInfo[0]);
359    }
360 /*
361          for (int i = 0; i < length2; i++) {
362          ;//// Removed By Program ** System.out.println("inpredicate.getParameterInfo() Going to Setting dataType p2[i].getQuestionMark() >> "+p2[i].getQuestionMark());
363             if (p2[i].getSubQuery()) {
364                ParameterInfo[] pa = p2[i].getParameterInfoArray();
365              Done by vibha to solve bug no 12106 check is done for null
366                if (pa != null) {
367                   result.addAll(Arrays.asList(pa));
368                }
369             } else if (p2[i].getQuestionMark()) {
370                int pos = i % length1;
371                if (!p1[pos].getQuestionMark()) {
372                   if (length2 == 1) {
373                      if (length1 == 1) {
374                         p2[i].setName(p1[pos].getName());
375                         /* Next Three Lines Done by Kaushik on 15/09/2004 to solve Bug no. 11994
376                         p2[i].setDataType(p1[pos].getDataType());
377                      } else {
378                         p2[i].setDataType(Datatypes.ARRAY);
379                         p2[i].setSubType(getArrayOfDataType(p1));
380                      }
381                   } else {
382                      /* Done by Kaushik to Solve Bug no. 11508
383                      p2[i].setName(p1[pos].getName()+"_"+ count++);
384                      p2[i].setDataType(p1[pos].getDataType());
385                   }
386                }
387                result.add(p2[i]);
388                t = p2[i].getDataType();
389                if (maxDataType < t) {
390                   maxDataType = t;
391                }
392             }
393          }
394          for (int i = length1 - 1; i >= 0; i--) {
395             if (p1[i].getQuestionMark()) {
396                result.add(0, p1[i]);
397             }
398             t = p1[i].getDataType();
399             if (maxDataType < t) {
400                maxDataType = t;
401             }
402          }*/

403
404
405    public AbstractRowValueExpression[] getChilds() {
406       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_rowvalueexpressionwithoutboolean3), (AbstractRowValueExpression) (_inpredicatevalue0)};
407       return childs;
408    }
409
410    public void setDefaultValues(_VariableValueOperations variableValueOperation) throws DException {
411    }
412
413    public String JavaDoc toString() {
414       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
415       sb.append(" ");
416       sb.append(_rowvalueexpressionwithoutboolean3);
417       sb.append(" ");
418       if (_OptSRESERVEDWORD12065439222 != null) {
419          sb.append(_OptSRESERVEDWORD12065439222);
420       }
421       sb.append(" ");
422       sb.append(_SRESERVEDWORD12065439221);
423       sb.append(" ");
424       sb.append(_inpredicatevalue0);
425       return sb.toString();
426    }
427
428    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
429       inpredicate tempClass = new inpredicate();
430       tempClass._inpredicatevalue0 = (inpredicatevalue) _inpredicatevalue0.clone();
431       tempClass._SRESERVEDWORD12065439221 = (SRESERVEDWORD1206543922) _SRESERVEDWORD12065439221.clone();
432       if (_OptSRESERVEDWORD12065439222 != null) {
433          tempClass._OptSRESERVEDWORD12065439222 = (SRESERVEDWORD1206543922) _OptSRESERVEDWORD12065439222.clone();
434       }
435       tempClass._rowvalueexpressionwithoutboolean3 = (rowvalueexpressionwithoutboolean) _rowvalueexpressionwithoutboolean3.clone();
436       try {
437          tempClass.getColumnDetails();
438       } catch (DException ex) {
439          throw new RuntimeException JavaDoc(ex.getMessage());
440       }
441       return tempClass;
442    }
443
444    private int handleSubQuery(Object JavaDoc value, _Iterator iterator, _ServerSession serverSession, Object JavaDoc object) throws DException {
445       int res = -1;
446       if (complexInnerQueryFlag == null || complexInnerQueryFlag.booleanValue()) { // Inorder to reinitialize Btree in case of Order in SubQuery.
447
iterator.setConditionVariableValue(null, null, 1);
448       }
449       if (iterator.first()) {
450          do {
451             Object JavaDoc iteratorValue = ( (_SelectIterator) iterator).getSelectColumnValues();
452             try {
453                res = comparator.compare(value, iteratorValue);
454             } catch (NullPointerException JavaDoc ex) {
455                if (!_rowvalueexpressionwithoutboolean3.getByteComparison(object).canUseByteComparison() || !_inpredicatevalue0.getByteComparison(object).canUseByteComparison()) {
456                   comparator = new CPckfduDpnqbsbups(); //getAppropriateObjectComparatorInCaseofSubQuery(value, iteratorValue, serverSession);
457
} else {
458                   comparator = getAppropriateSuperComparatorInCaseofSubQuery(value, iteratorValue, serverSession);
459                }
460                res = comparator.compare(value, iteratorValue);
461             }
462             if (res == 0) {
463                break;
464             }
465          } while (iterator.next());
466       }
467       return res;
468    }
469
470    private int handlingOFSimpleAndConstants(Object JavaDoc value1, Object JavaDoc value2, _ServerSession serverSession, Object JavaDoc object) throws DException {
471       try {
472          return comparator.compare(value1, value2);
473       } catch (NullPointerException JavaDoc ex) {
474          ByteComparison leftByteComparison = _rowvalueexpressionwithoutboolean3.getByteComparison(object);
475          ByteComparison rightByteComparison = _inpredicatevalue0.getByteComparison(object);
476
477          synchronized (this) {
478             value2 = value2 != null ? value2 : _inpredicatevalue0.run(object);
479
480 /* Done by Kaushik on 9/8/04 to Appropriate handling of inPredicate Solving */
481             comparator = getAppropriateComparatorNEW(leftByteComparison, rightByteComparison, value1, value2, serverSession);
482             return comparator.compare(value1, value2);
483          }
484       }
485    }
486
487    public SuperComparator getAppropriateComparator(ByteComparison byteComparison1, ByteComparison byteComparison2, Object JavaDoc value1, Object JavaDoc value2, _ServerSession serverSession) throws DException {
488       if (!byteComparison1.canUseByteComparison() || !byteComparison2.canUseByteComparison()) {
489          return com.daffodilwoods.daffodildb.utils.GetByteComparator.objectComparator;
490       }
491       canByteCached = canByteCached();
492       if (value1 instanceof Object JavaDoc[]) {
493          Object JavaDoc[] source2 = (Object JavaDoc[]) value2;
494          int length = source2.length;
495          SuperComparator[] comparators = new SuperComparator[length];
496          Object JavaDoc[] source1 = (Object JavaDoc[]) value1;
497
498            for (int i = 0; i < length; i++) {
499
500               comparators[i] = getJoinComparator(source1, (source2[i] instanceof Object JavaDoc[])?(Object JavaDoc[]) source2[i]:source2, serverSession);
501
502            }
503          SuperComparator comparator = new CJoNvujmWbmvfeDpnqbsbups(comparators);
504          return canByteCached ? new ByteInSimpleComparator(comparator, value2)
505              : comparator;
506       }
507       if (value2 instanceof Object JavaDoc[]) {
508          SuperComparator[] comparators = getInComparators( (FieldBase) value1, (Object JavaDoc[]) value2, serverSession);
509          return canByteCached ? new ByteInComparator(comparators, value2)
510              : (SuperComparator)new CJoDpnqbsbups(comparators);
511       }
512       SuperComparator comparator = null;
513       try {
514          comparator = getComparator( (FieldBase) value1, (FieldBase) value2, serverSession);
515       } catch (NullPointerException JavaDoc ex) {
516          throw ex;
517       }
518       return canByteCached ? new ByteInSimpleComparator(comparator, value2)
519           : comparator;
520    }
521
522    private SuperComparator[] getInComparators(FieldBase fieldBase, Object JavaDoc[] source2, _ServerSession serverSession) throws DException {
523       int length = source2.length;
524       SuperComparator[] comparators = new SuperComparator[length];
525       for (int i = 0; i < length; i++) {
526          try {
527             comparators[i] = getComparator(fieldBase, (FieldBase) source2[i],
528                                            serverSession);
529          } catch (ClassCastException JavaDoc ex) {
530             throw ex;
531          }
532       }
533       return comparators;
534    }
535
536    private boolean canByteCached() throws DException {
537       ColumnDetails[] rightColumns = _inpredicatevalue0.getColumnDetails();
538       for (int i = 0; i < rightColumns.length; i++) {
539          if (rightColumns[i].getType() == REFERENCE || rightColumns[i].getQuestion()) {
540             return false;
541          }
542       }
543       return true;
544    }
545
546    public void releaseResource() throws DException {
547       synchronized (this) {
548          super.releaseResource();
549          canByteCached = false;
550       }
551    }
552
553
554    public boolean checkCD(ColumnDetails[] cd){
555      for (int i = 0; i < cd.length; i++) {
556        if(cd[i].toString().toLowerCase().indexOf("system.")>=0)
557          return false;
558      }
559      return true;
560    }
561
562
563    /** Method Written by kaushik on 9/08/2004 for appropriate Comparator generation
564     * 5 in (2,3)
565     * value1 :: value to be checked inside List e.g. 5
566     * value2 :: value in list e.g 2 or 3
567     */

568    public SuperComparator getAppropriateComparatorNEW(ByteComparison byteComparison1, ByteComparison byteComparison2, Object JavaDoc value1, Object JavaDoc value2, _ServerSession serverSession) throws DException {
569    if (!byteComparison1.canUseByteComparison() || !byteComparison2.canUseByteComparison()) {
570       return com.daffodilwoods.daffodildb.utils.GetByteComparator.objectComparator;
571    }
572
573    canByteCached = canByteCached();
574    int cardinality1 = _rowvalueexpressionwithoutboolean3.getCardinality();
575    Object JavaDoc[] source2 = (Object JavaDoc[]) value2;
576    int length = source2.length;
577    SuperComparator[] comparators = new SuperComparator[length];
578    SuperComparator comparator = null;
579       boolean leftArray=cardinality1>1;
580       Object JavaDoc[] source1 = leftArray ? (Object JavaDoc[]) value1 : new Object JavaDoc[]{value1};
581       if (canByteCached)/*Work done in respect to bug no. 634 (Site Repository) -- Sandeep Kadiyan dec 6, 2005*/
582         Arrays.sort(source2, new Comparator(com.daffodilwoods.daffodildb.utils.GetByteComparator.objectComparator));
583       if(leftArray){
584          if (source2[0] instanceof Object JavaDoc[]) {
585             for (int i = 0; i < length; i++) {
586                comparators[i] = getJoinComparator(source1, (Object JavaDoc[]) source2[i], serverSession);
587             }
588          } else {
589             comparators[0] = getJoinComparator(source1, source2, serverSession);
590          }
591          comparator = new CJoNvujmWbmvfeDpnqbsbups(comparators);
592       }
593       else{
594          if(source2.length>0 && source2[0] instanceof Object JavaDoc[])
595             comparators = getInComparators( (FieldBase) source1[0], (Object JavaDoc[]) source2[0], serverSession);
596         else
597             comparators = getInComparators( (FieldBase) source1[0], source2, serverSession);
598          comparator = new CJoDpnqbsbups(comparators);
599       }
600       return canByteCached ? new ByteInComparator(comparators, source2)
601           : comparator;
602 }
603
604     /*Done by vibha to solve bug no 11825 on 14-09-2004*/
605  private void checkForSubqueryInPredicate() throws DException {
606   if(_rowvalueexpressionwithoutboolean3.checkForSubQuery())
607     throw new DException("DSE216", null);
608  }
609
610 }
611
Popular Tags