KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > iterator > set > ExceptAllIterator


1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set;
2
3 import com.daffodilwoods.daffodildb.client.*;
4 import com.daffodilwoods.daffodildb.server.sql99.common.*;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
7 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
8 import com.daffodilwoods.daffodildb.utils.comparator.*;
9 import com.daffodilwoods.daffodildb.utils.field.*;
10 import com.daffodilwoods.database.resource.*;
11 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs;
12
13 /**
14  * <p>Title: ExceptAllIterator </p>
15  * <p> This Class is responsible to retrieve the results from a select query
16  * having EXCEPT ALL operator. If Except All to be applied to two result set
17  * Ra and Rb, Except All operator displays all the rows from the left result
18  * set that are not present in right result set.
19  *
20  * This class is required to support the <EXCEPT ALL Clause> set operator. If EXCEPT is specified, then the number of duplicates
21  * of R that T contains is the maximum of (m - n) and 0 where m is the no of duplicates in table R and n is the no of duplicates in table T</p>
22  * <p>Copyright: Copyright (c) 2003</p>
23  * <p>Company: </p>
24  * @author unascribed
25  * @version 1.0
26  */

27
28 public class ExceptAllIterator extends BaseJoinIterator {
29
30
31    /**
32     * Variable represents whether right resultset/second iterator has more
33     * records in current navigation direction.
34     */

35    protected boolean checkInSecondIterator;
36
37    /**
38     * Selected columns of Left Iterator
39     */

40    protected _Reference[] leftColumnReferences;
41
42    /**
43     * Selected columns of right Iterator
44     */

45    protected _Reference[] rightColumnReferences; //selected References from RightIterator
46

47    /**
48     * Order By Columns corresponding to left iterator
49     */

50    protected _Reference[] orderLeftCD;
51    /**
52     * Order By Columns corresponding to right iterator
53     */

54    protected _Reference[] orderRightCD;
55
56    /**
57     * THe comparator that 'll be initialized during its constructor and 'll be used to compare the values. from the two iterator.
58     */

59    /**
60     * The comparator i.e used to compare the values of selected columns of left
61     * iterator with that of righ iterator.
62     */

63    protected SuperComparator comparator;
64    /**
65     * The comparator i.e used to compare one set of values of selected columns of
66     * left iterator with another set of selected column values from same iterator.
67     */

68    protected SuperComparator leftComparator;
69    /**
70     * The comparator i.e used to compare one set of values of selected columns of
71     * right iterator with another set of selected column values from same iterator.
72     */

73    protected SuperComparator rightComparator;
74 // */
75

76
77
78    /**
79     * A public constructor, that takes five arguments, two are left and right iterators, and
80     * other two are left and right side selected column References. A comparator is also provided for the
81     * purpose of comparison.
82     *
83     * A state is also maintained, that specifies the current status of the current level iterator(this).
84     *
85     * The State INVALIDSTATE means iterator is not aligned properly and needs to be aligned
86     * before doing any further operations.
87     *
88     * The State VALIDSTATE means iterator is aligned properly and can be moved next()/ previous()
89     * as well as values can also be retrieved
90     *
91     * The State BEFOREFIRST means, iterator has reached before the first record or there is no record in the result set.
92     * Iterator is not aligned properly and needs to be aligned through calling first()/ last() before doing any further operations.
93     *
94     * The State AFTERLAST means, iterator has reached after the last record or there is no record in the result set.
95     * Iterator is not aligned properly and needs to be aligned through calling first()/ last() before doing any further operations.
96     *
97     * Initailizes the variable required to get set operation result of given
98     * resultsets.
99     */

100    public ExceptAllIterator(_Iterator leftIterator, _Iterator rightIterator, _Reference[] leftColumnReferences0, _Reference[] rightColumnReferences0, SuperComparator comparator0, _Reference[] orderLeftCD0, _Reference[] orderRightCD0, SuperComparator leftComparator0, SuperComparator rightComparator0) throws DException {
101       super(leftIterator, rightIterator);
102       leftColumnReferences = leftColumnReferences0;
103       rightColumnReferences = rightColumnReferences0;
104       comparator = comparator0;
105       checkInSecondIterator = true;
106       orderLeftCD = orderLeftCD0;
107       orderRightCD = orderRightCD0;
108       leftComparator = leftComparator0;
109       rightComparator = rightComparator0;
110    }
111
112    /**
113     * This method is responsible for retrieving the first record.
114     * 1. First record from both underlying iterator is retrieved. If left
115     * iterator has no records, return false.
116     * 2. Now, a record has to be retrieved from the left iterator such that
117     * right iterator has no record that has same selected column values as
118     * as that of current record from left iterator. If right iterator has
119     * no records, goto step 3, else goto step 4.
120     * 3. Variable checkInSecondIterator is set to false indicating that now,
121     * there is no need to check records from right iterator, all the records
122     * from the left iterator will be returned. Return true.
123     * 4. Selected Column Values got from right iterator are compared with that
124     * of current record from left iterator.
125     * a. If both values are same, navigate both iterators in forward direction
126     * to skip the common record. goto step 5.
127     * b. Else If left iterator has smaller values, right iterator can't get
128     * similar set of values if navigated in forward direction from current
129     * position, since the data of right iterator is sorted. Return true.
130     * c. Else navigate the right iterator in the forward direction till right
131     * iterator is pointed to record that has larger or equal values of
132     * selected columns as compared to left iterator. goto step 5.
133     * 5. If right iterator has no more records, goto step 3, else goto step 4.
134     *
135     * DETAILED DOCUMENTATION
136     *
137     * i. If leftiterator.first() returns false then the state 'll be set to AFTERLAST and the method 'll return false .
138     * ii. Else if rightIterator.first() return false then flag 'checkInSecondIterator' 'll be set to false implying
139     * that all records from the current position to the last of firstIterator 'll be the valid records for ExceptAllIterator
140     * and the method 'll return true and state 'll be set to VALIDSTATE.
141     * iii.Else alignnext() 'll be called that 'll align to the next valid record that is not present in the second iterator
142     * and its result 'll be returned.
143     *
144     * @return true if record found, false otherwise.
145     * @throws com.daffodilwoods.database.resource.DException
146     */

147    public boolean first() throws com.daffodilwoods.database.resource.DException {
148       checkInSecondIterator = true;
149       if (!leftIterator.first()) {
150          state = AFTERLAST;
151          return false;
152       }
153       if (!rightIterator.first()) {
154          checkInSecondIterator = false;
155          state = VALIDSTATE;
156          return true;
157       }
158       return (state = alignNext() ? VALIDSTATE : AFTERLAST) != AFTERLAST;
159    }
160    /**
161     * This method is responsible for retrieving the last record.
162     * 1. Last record from both underlying iterator is retrieved. If left
163     * iterator has no records, return false.
164     * 2. Now, a record has to be retrieved from the left iterator such that
165     * right iterator has no record that has same selected column values as
166     * that of current record from left iterator. If right iterator has no
167     * records, goto step 3, else goto step 4.
168     * 3. Variable checkInSecondIterator is set to false indicating that now,
169     * there is no need to check records from right iterator, all the records
170     * from the left iterator will be returned. Return true.
171     * 4. Selected Column Values got from right iterator are compared with that
172     * of current record from left iterator.
173     * a. If both values are same, navigate both iterators in backward direction
174     * to skip the common record. goto step 5.
175     * b. Else If left iterator has larger values, right iterator can't get
176     * similar set of values if navigated in backward direction from current
177     * position, since the data of right iterator is sorted. Return true.
178     * c. Else navigate the right iterator in the backward direction till right
179     * iterator is pointed to record that has smaller or equal values of
180     * selected columns as compared to left iterator. goto step 5.
181     * 5. If right iterator has no more records, goto step 3, else goto step 4.
182     *
183     * DETAILED DOCUMENTAION
184     *
185     * i. If leftiterator.last() returns false then the state 'll be set to BEFOREFIRST and the method 'll return false .
186     * ii. Else if rightIterator.last() return false then flag 'checkInSecondIterator' 'll be set to false implying
187     * that all records from the current position to the first of firstIterator 'll be the valid records for ExceptAllIterator
188     * and the method 'll return true and state 'll be set to VALIDSTATE.
189     * iii.Else alignprevious() 'll be called that 'll align to the previous valid record that is not present in the second iterator
190     * and its result 'll be returned.
191     *
192     * @return true if record found, false otherwise.
193     * @throws com.daffodilwoods.database.resource.DException
194     */

195    public boolean last() throws com.daffodilwoods.database.resource.DException {
196       checkInSecondIterator = true;
197       if (!leftIterator.last()) {
198          state = BEFOREFIRST;
199          return false;
200       }
201       if (!rightIterator.last()) {
202          checkInSecondIterator = false;
203          state = VALIDSTATE;
204          return true;
205       }
206       return (state = alignPrevious() ? VALIDSTATE : BEFOREFIRST) != BEFOREFIRST;
207    }
208    /**
209     * This method is responsible for retrieving the next record.
210     * 1. Next record from left iterator is retrieved. If no record
211     * found, return false.
212     * 2. Now, a record has to be retrieved from the left iterator such that
213     * right iterator has no record that has same selected column values as that
214     * of current record from left iterator. Selected Column Values got from right
215     * iterator are compared with that of current record from left iterator.
216     * a. If both values are same, navigate both iterators in forward direction
217     * to skip the common record. goto step 5.
218     * b. Else If left iterator has smaller values, right iterator can't get
219     * similar set of values if navigated in forward direction from current
220     * position, since the data of right iterator is sorted. Return true.
221     * c. Else navigate the right iterator in the forward direction till right
222     * iterator is pointed to record that has larger or equal values of
223     * selected columns as compared to left iterator. goto step 5.
224     * 3. If right iterator has no more records, Variable checkInSecondIterator
225     * is set to false indicating that now, there is no need to check records
226     * from right iterator, all the records from the left iterator will be
227     * returned. Return true, Else goto step 2.
228     *
229     * DETAILED DOCUMENTATION
230     *
231     * i. If previous state is INVALIDSTATE,
232     * through Invalid State Exception.
233     * ii. Else If previous state is AFTERLAST,
234     * return false.
235     * iii. Else If previous state is BEFOREFIRST,
236     * call and return its first() .
237     * iv. Else If left Iterator could not iterate to the valid next position then method 'll return false.
238     * v. Else alignnext() 'll be called that 'll align to the next valid record that is not present in the second iterator
239     * and its result 'll be returned.
240     *
241     * @return true if record found, false otherwise.
242     * @throws com.daffodilwoods.database.resource.DException
243     */

244    public boolean next() throws com.daffodilwoods.database.resource.DException {
245       if (state == INVALIDSTATE) {
246          throw new DException("DSE4116", null);
247       }
248       if (state == BEFOREFIRST) {
249          return first();
250       }
251       if (!leftIterator.next()) {
252          state = AFTERLAST;
253          return false;
254       }
255       return (state = alignNext() ? state : AFTERLAST) != AFTERLAST;
256    }
257
258    /**
259     * This method is responsible for retrieving the previous record.
260     * 1. Previous record from left iterator is retrieved. If no record
261     * found, return false.
262     * 2. Now, a record has to be retrieved from the left iterator such that
263     * right iterator has no record that has same selected column values as that
264     * of current record from left iterator. Selected Column Values got from right
265     * iterator are compared with that of current record from left iterator.
266     * a. If both values are same, navigate both iterators in backward direction
267     * to skip the common record. goto step 6.
268     * b. Else If left iterator has larger values, right iterator can't get
269     * similar set of values if navigated in backward direction from current
270     * position, since the data of right iterator is sorted. Return true.
271     * c. Else navigate the right iterator in the backward direction till right
272     * iterator is pointed to record that has smaller or equal values of
273     * selected columns as compared to left iterator. goto step 5.
274     * 3. If right iterator has no more records, Variable checkInSecondIterator
275     * is set to false indicating that now, there is no need to check records
276     * from right iterator, all the records from the left iterator will be
277     * returned. Return true, Else goto step 2.
278     *
279     * DETAILED DOCUMENTATION
280     *
281     * i. If previous state is INVALIDSTATE,
282     * through Invalid State Exception.
283     * ii. Else If previous state is BEFOREFIRST,
284     * return false.
285     * iii.Else If previous state is AFTERLAST,
286     * call and return its last() .
287     * iv. Else If left Iterator could not iterate to the valid previous position then method 'll return false.
288     * v. Else alignprevious() 'll be called that 'll align to the previous valid record that is not present in the second iterator
289     * and its result 'll be returned.
290     *
291     * @return true if record found, false otherwise.
292     * @throws com.daffodilwoods.database.resource.DException
293     */

294    public boolean previous() throws com.daffodilwoods.database.resource.DException {
295     if (state == INVALIDSTATE)
296       throw new DException("DSE4117", null);
297     if (state == AFTERLAST)
298       return last();
299     if (!leftIterator.previous()) {
300       state = BEFOREFIRST;
301       return false;
302     }
303     return (state = alignPrevious() ? state : BEFOREFIRST) != BEFOREFIRST;
304   }
305
306    /**
307     * Move the single iterator on just next distinct record.
308     * @param iterator one of the underlying iterator to navigate in forward
309     * direction
310     * @param value current values of selected columns
311     * @param references selected columns in query
312     * @param left true if left iterator is nagigated, false if right iterator
313     * is navigated.
314     * @return true if distinct record found, false otherwise.
315     * @throws DException
316     */

317    boolean moveForwardDistinct(_Iterator iterator, Object JavaDoc value, _Reference[] references, boolean left) throws DException {
318       while (iterator.next()) {
319          if (compare(iterator.getColumnValues(references), value, left) != 0) {
320             return true;
321          }
322       }
323       return false;
324    }
325
326    /**
327     * Move the single iterator on just previous distinct record.
328     * @param iterator one of the underlying iterator to navigate in backward
329     * direction
330     * @param value current values of selected columns
331     * @param references selected columns in query
332     * @param left true if left iterator is nagigated, false if right iterator
333     * is navigated.
334     * @return true if distinct record found, false otherwise.
335     * @throws DException
336     */

337
338    boolean moveBackwardDistinct(_Iterator iterator, Object JavaDoc value, _Reference[] references, boolean left) throws DException {
339       while (iterator.previous()) {
340          if (compare(iterator.getColumnValues(references), value, left) != 0) {
341             return true;
342          }
343       }
344       return false;
345    }
346
347    /**
348     * Next record is retrived from the passed iterator.
349     * @param iterator underlying iterator to navigate
350     * @param value
351     * @param references
352     * @return true if next record found, false otherwise
353     * @throws DException
354     */

355    boolean moveForward(_Iterator iterator, Object JavaDoc value, _Reference[] references) throws DException {
356       return iterator.next();
357    }
358
359    /**
360     * Previous record is retrived from the passed iterator.
361     * @param iterator underlying iterator to navigate
362     * @param value
363     * @param references
364     * @return true if next record found, false otherwise
365     * @throws DException
366     */

367    boolean moveBackward(_Iterator iterator, Object JavaDoc value, _Reference[] references) throws DException {
368       return iterator.previous();
369    }
370
371    /**
372     * The purpose of this method is to align the left iterator in the forward
373     * direction to a record such that right iterator has no record with values
374     * of selected columns same as that of current record from left iterator.
375     *
376     * DETAILED DOCUMENTATION
377     *
378     * Algo :
379     *
380     * 1. if flag <checkInSecondIterator> is false, then method 'll return true.
381     * 2. Repeat step 3 to 6 unconditionally.
382     * 3. Else left and right side value 'll be evaluated .
383     * 4. Based on the comparison result, if both are equal then both the iterators 'll be moved to its next record. If
384     * left could not move, method 'll return false . If right iterator couldn't move then flag <checkInSecondIterator>
385     * 'll be set to false and the method 'll return tue.
386     * 5. IF left Value is greater than the right one, then right Iterator 'll be moved to its next distinct position.If right ]
387     * iterator couldn't moved successfully then flag <checkInSecondIterator>
388     * 'll be set to false and the method 'll return tue and continue in the loop.
389     * 6 Else return true.
390     *
391     * @return true if underlying iterators are aligned, false otherwise.
392     * @throws DException
393     */

394    boolean alignNext() throws DException {
395       if (!checkInSecondIterator && !rightIterator.next()) {
396          return true;
397       } while (true) {
398          Object JavaDoc leftObjectValues = leftIterator.getColumnValues(orderLeftCD);
399          Object JavaDoc rightObjectValues = rightIterator.getColumnValues(orderRightCD);
400          int cmp = compare(leftObjectValues, rightObjectValues);
401          if (cmp == 0) {
402             if (!moveForward(leftIterator, leftObjectValues, orderLeftCD)) {
403                return false;
404             }
405             if (!moveForward(rightIterator, rightObjectValues, orderRightCD)) {
406                checkInSecondIterator = false;
407                return true;
408             }
409          } else if (cmp > 0) {
410             if (!moveForwardDistinct(rightIterator, rightObjectValues, orderRightCD, false)) {
411                checkInSecondIterator = false;
412                return true;
413             }
414          } else {
415             checkInSecondIterator = true;
416             return true;
417          }
418
419       }
420    }
421
422    /**
423     * The purpose of this method is to align the left iterator in the backward
424     * direction to a record such that right iterator has no record with values
425     * of selected columns same as that of current record from left iterator.
426     *
427     * Algo :
428     *
429     * 1. if flag <checkInSecondIterator> is false, then method 'll return true.
430     * 2. Repeat step 3 to 6 unconditionally.
431     * 3. Else left and right side value 'll be evaluated .
432     * 4. Based on the comparison result, if both are equal then both the iterators 'll be moved to its previous record. If
433     * left could not move, method 'll return false . If right iterator couldn't move then flag <checkInSecondIterator>
434     * 'll be set to false and the method 'll return tue.
435     * 5. IF left Value is smaller than the right one, then right Iterator 'll be moved to its previous distinct position.If right ]
436     * iterator couldn't moved successfully then flag <checkInSecondIterator>
437     * 'll be set to false and the method 'll return tue and continue in the loop.
438     * 6 Else return true.
439     *
440     * @return true if underlying iterators are aligned, false otherwise.
441     * @throws DException
442     */

443    boolean alignPrevious() throws DException {
444       if (!checkInSecondIterator && !rightIterator.previous()) {
445          return true;
446       } while (true) {
447          Object JavaDoc leftObjectValues = leftIterator.getColumnValues(orderLeftCD);
448          Object JavaDoc rightObjectValues = rightIterator.getColumnValues(orderRightCD);
449          int cmp = compare(leftObjectValues, rightObjectValues);
450          if (cmp == 0) {
451             if (!moveBackward(leftIterator, leftObjectValues, orderLeftCD)) {
452                return false;
453             }
454             if (!moveBackward(rightIterator, rightObjectValues, orderRightCD)) {
455                checkInSecondIterator = false;
456                return true;
457             }
458          } else if (cmp < 0) {
459             if (!moveBackwardDistinct(rightIterator, rightObjectValues, orderRightCD, false)) {
460                checkInSecondIterator = false;
461                return true;
462             }
463          } else {
464             checkInSecondIterator = true;
465             return true;
466          }
467       }
468    }
469
470    /**
471     * Compares selected column values from left iterator with that of right
472     * iterator.
473     * @param object1 values of selected columns of left iterator
474     * @param object2 values of selected columns of right iterator
475     * @return 0 , if values are same
476     * < 0, if ob1 < ob2
477     * > 0, if ob1 > ob2
478     * @throws DException
479     */

480    int compare(Object JavaDoc object1, Object JavaDoc object2) throws DException{
481     int cmp = comparator.compare(object1,object2);
482     return cmp;
483   }
484
485
486   /**
487    * Compares one set of selected column values from iterator with another set
488    * of values of selected columns.
489    * iterator.
490    * @param object1 values of selected columns of left iterator
491    * @param object2 values of selected columns of right iterator
492    * @param left true, if left iterator values are compared
493    * false, if right iterator values are compared
494    * @return 0 , if values are same
495    * < 0, if ob1 < ob2
496    * > 0, if ob1 > ob2
497    * @throws DException
498    */

499   int compare(Object JavaDoc object1, Object JavaDoc object2, boolean left) throws DException {
500       int cmp = left ? leftComparator.compare(object1, object2) : rightComparator.compare(object1, object2);
501       return cmp;
502    }
503
504    /**
505     * This method is used to get the key of the iterator.
506     * @return an object array having the keys of left and right iterator,
507     * keys corresponding to right iterator will be null if there are no records
508     * in right iterator.
509     * @throws DException
510     */

511    public Object JavaDoc getKey() throws DException {
512      if (state == INVALIDSTATE || state == BEFOREFIRST || state == AFTERLAST)
513        throw new DException("DSE4116", null);
514      return checkInSecondIterator ? new Object JavaDoc[] {
515          leftIterator.getKey(), rightIterator.getKey()}
516          : new Object JavaDoc[] {
517          leftIterator.getKey(), null};
518    }
519
520    /**
521     * This method is responsible to move to a particular record having the
522     * passed key. This method moves the left iterator to the key passed and
523     * checks the keys corresponding to right iterator. If keys are null,
524     * variable checkInSecondIterator is set to false indicating that there are
525     * no records in right iterator, false, otherwise.
526     * @param kee key of particular record to move
527     * @throws DException
528     */

529    public void move(Object JavaDoc kee) throws DException {
530      Object JavaDoc[] key = (Object JavaDoc[]) kee;
531      leftIterator.move(key[0]);
532      if (key[1] != null) {
533        rightIterator.move(key[1]);
534        checkInSecondIterator = true;
535      }
536      else
537        checkInSecondIterator = false;
538    }
539
540    /**
541     * The following methods are used for getting values of current record.
542     * The values of current record are retrieved from the left resultset.
543     */

544    /**
545     * This method is used to retrieve the values of passed references.
546     * @param references reference for which values are to be retrived.
547     * Reference may be column or parameter.
548     * @return NonShared FieldBases denoting the value of References. Non Shared
549     * FieldBases are those for which BufferRange is not shared with some other
550     * FieldBase.
551     * @throws DException
552     */

553    public Object JavaDoc getColumnValues(_Reference[] references) throws DException {
554       int[] indexes = GeneralPurposeStaticClass.getSelectedIndexes(references, leftColumnReferences);
555       _Reference[] leftReferences = GeneralPurposeStaticClass.getReferencesToIndex(indexes, leftColumnReferences);
556       return leftIterator.getColumnValues(leftReferences);
557    }
558
559    /**
560     * This method is used to retrieve the value of passed reference.
561     * @param reference reference for which value is to be retrived.
562     * Reference may be column or parameter.
563     * @return NonShared FieldBase denoting the value of Reference. Non Shared
564     * FieldBases are those for which BufferRange is not shared with some other
565     * FieldBase.
566     * @throws DException
567     */

568    public Object JavaDoc getColumnValues(_Reference reference) throws DException {
569       int index = GeneralPurposeStaticClass.getSelectedColumnIndex(reference, leftColumnReferences);
570       if (index == -1) {
571          return leftIterator.getColumnValues(reference);
572       }
573       _Reference leftReferences = leftColumnReferences[index];
574       return leftIterator.getColumnValues(leftReferences);
575    }
576
577    /**
578     * This method return the shared FieldBases for the passed references. By Shared
579     * FieldBase we mean, BufferRange of FieldBase is shared with other FieldBase
580     * objects.
581     * @param references reference for which values are to be retrived
582     * @return shared field base correspondition to passed column reference
583     * @throws DException
584     */

585    public FieldBase[] fields(_Reference[] references) throws DException {
586       int[] indexes = GeneralPurposeStaticClass.getSelectedIndexes(references, leftColumnReferences);
587       _Reference[] leftReferences = GeneralPurposeStaticClass.getReferencesToIndex(indexes, leftColumnReferences);
588       return leftIterator.fields(leftReferences);
589    }
590
591    /**
592     * This method return the shared FieldBase for the passed reference. By Shared
593     * FieldBase we mean, BufferRange of FieldBase is shared with other FieldBase
594     * objects.
595     * @param reference reference for which value is to be retrived
596     * @return shared field base correspondition to passed column reference
597     * @throws DException
598     */

599    public FieldBase field(_Reference reference) throws DException {
600       int index = GeneralPurposeStaticClass.getSelectedColumnIndex(reference, leftColumnReferences);
601       if (index == -1) {
602         return leftIterator.field(reference);
603       }
604       _Reference leftReferences = leftColumnReferences[index];
605       return leftIterator.field(leftReferences);
606    }
607
608    /**
609     * This method is responsible to display the executionPlan of a Select Query.
610     * @return _ExecutionPlan
611     * @throws DException
612     */

613    public _ExecutionPlan getExecutionPlan() throws DException {
614       _ExecutionPlan cplans[] = new _ExecutionPlan[2];
615       cplans[0] = leftIterator.getExecutionPlan();
616       cplans[1] = rightIterator.getExecutionPlan();
617       return new ExecutionPlan("ExceptAllIterator", cplans, null, null, null);
618    }
619
620    /**
621     * This method is responsible to display the iterators hierarchy of a Select Query.
622     * @return ExecutionPlanForBrowser
623     * @throws DException
624     */

625    public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException {
626       ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[2];
627       cplans[0] = leftIterator.getExecutionPlanForBrowser();
628       cplans[1] = rightIterator.getExecutionPlanForBrowser();
629       return new ExecutionPlanForBrowser("Except All", "ExceptAllIterator", cplans, null, null, null);
630    }
631
632    /**
633     * This method is used to release the resources releated with the particular
634     * parameters. For e.g comparators. The call to release resouces is delegated
635     * to both underlying iterators.
636     * @throws DException
637     */

638    public void releaseResource() throws DException {
639      leftIterator.releaseResource();
640      rightIterator.releaseResource();
641      /* commented by vibha on 21-02-2005 to solve bug no 12598 */
642    }
643
644    /**
645     * This method is used to get the lowest level iterator.
646     * @param column column corresponding to which iterator is to return.
647     * @return same iterator.
648     * @throws DException
649     */

650    public _Iterator getBaseIterator(ColumnDetails column) throws com.daffodilwoods.database.resource.DException {
651       return this;
652    }
653
654    /**
655     * The following method transfer the call to left iterator. These method
656     * perform the functioning on the left result set.
657     */

658    /**
659     * Initializes the tables corresponding to right iterator. And returns the
660     * names of the tables involved in the set operation.
661     * @return tables involved in set operaton.
662     * @throws DException
663     */

664    public TableDetails[] getTableDetails() throws com.daffodilwoods.database.
665
      resource.DException {
666     rightIterator.getTableDetails();
667     return leftIterator.getTableDetails();
668   }
669
670   public _KeyColumnInformation[] getKeyColumnInformation() throws com.
671
      daffodilwoods.database.resource.DException {
672     return leftIterator.getKeyColumnInformations();
673   }
674
675   public _KeyColumnInformation[] getKeyColumnInformations() throws DException {
676     return leftIterator.getKeyColumnInformations();
677   }
678
679   /**
680    * The following methods of this class are used a intermediate in the
681    * iterator hierarchy. These methods simply transfer the call to the
682    * underlying iterator with the same arguments.
683    */

684
685   public Object JavaDoc[] getUniqueColumnReference() throws DException {
686     return leftIterator.getUniqueColumnReference();
687   }
688
689   public boolean seek(Object JavaDoc indexKey) throws DException {
690      return GeneralPurposeStaticClass.seek(indexKey, leftIterator, rightIterator);
691   }
692
693   public _OrderCount getOrderCounts() throws com.daffodilwoods.database.
694
      resource.DException {
695     rightIterator.getOrderCounts(); // to initialize the OrderCount in RightIterator
696
return (orderCount = leftIterator.getOrderCounts());
697   }
698
699   public byte[] getByteKey() throws DException {
700     if (state == INVALIDSTATE || state == BEFOREFIRST || state == AFTERLAST)
701       throw new DException("DSE4116", null);
702      return checkInSecondIterator ? getResultantByteKeys(true) : getResultantByteKeys(false);
703
704   }
705
706   public void moveByteKey(byte[] key) throws DException {
707     short leftLen = CCzufDpowfsufs.getShortValue(key,0);
708     byte[] leftKeys = new byte[leftLen];
709     System.arraycopy(key,2,leftKeys,0,leftKeys.length);
710     leftIterator.moveByteKey(leftKeys);
711     if(key[leftKeys.length+1]!=0){
712       short rightLen = CCzufDpowfsufs.getShortValue(key,leftKeys.length+2);
713       byte[] rightKeys = new byte[rightLen];//key[leftKeys.length+2]
714
System.arraycopy(key,leftKeys.length+4,rightKeys,0,rightKeys.length);
715       rightIterator.moveByteKey(rightKeys);
716       checkInSecondIterator = true;
717     }
718     else
719       checkInSecondIterator = false;
720   }
721
722   private byte[] getResultantByteKeys(boolean flag) throws DException {
723     byte[] leftKeys = leftIterator.getByteKey();
724     byte[] rightKeys = rightIterator.getByteKey();
725     byte[] resultantKeys;
726     if (flag) {
727       resultantKeys = new byte[leftKeys.length + rightKeys.length + 4];
728       short leftLen = (short)leftKeys.length;
729       short rightLen = (short)rightKeys.length;
730       System.arraycopy(CCzufDpowfsufs.getBytes(leftLen),0 ,resultantKeys,0,2);
731       System.arraycopy(leftKeys,0,resultantKeys,2,leftLen);
732       System.arraycopy(CCzufDpowfsufs.getBytes(rightLen),0,resultantKeys,2+leftLen,2);
733       System.arraycopy(rightKeys,0,resultantKeys,leftKeys.length+4,rightKeys.length);
734     }
735     else{
736       resultantKeys = new byte[leftKeys.length + 4];
737       short leftLen =(short)leftKeys.length;
738       System.arraycopy(CCzufDpowfsufs.getBytes(leftLen),0,resultantKeys,0,2);
739       System.arraycopy(leftKeys, 0, resultantKeys, 2, leftKeys.length);
740       System.arraycopy(CCzufDpowfsufs.getBytes((short)0),0,resultantKeys,leftLen+2,2);
741       resultantKeys[leftKeys.length + 1] = 0;
742     }
743     return resultantKeys;
744   }
745
746   public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{
747     throw new java.lang.UnsupportedOperationException JavaDoc("Method setSpecificUnderlyingReferences(_Reference[]) not yet implemented.");
748       }
749
750   public String JavaDoc toString() {
751      return "ExceptAllIterator [" + leftIterator + "] [" + rightIterator + "]";
752   }
753 }
754
Popular Tags