KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > iterator > table > SemiJoinIteratorWithoutCondition


1 package com.daffodilwoods.daffodildb.server.sql99.dql.iterator.table;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.client.*;
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.utils.*;
10 import com.daffodilwoods.daffodildb.utils.*;
11 import com.daffodilwoods.daffodildb.utils.field.*;
12 import com.daffodilwoods.database.resource.*;
13 import com.daffodilwoods.daffodildb.utils.byteconverter.CCzufDpowfsufs;
14
15 /**
16  * <p>Title: SemiJoinIteratorWithoutCondition </p>
17  * <p>Description: This Class is responsible for retrieving LEFT OUTER JOIN AND
18  * RIGHT OUTER JOIN results in which 'on Condition' is single table condition
19  * of right table. And it is shifted to the right table. Left outer Joins results
20  * in all the records from the left table. If no records results from right
21  * resultset, then NULL value is appended for the values of right table. The
22  * Iterator maintains the basic propertiy of any Iterator, however it also
23  * possesses couple of other attributes required.
24  * Right Outer Joins are just antisymmetric to the Left Outer Join in nature.
25  * A variable rightNull is used to indicate whether values corresponding to the
26  * right Iterator be valid value from the right Iterators or NULL 'll be appended
27  * instead. Initially it is set to false. </p>
28  * <p>Copyright: Copyright (c) 2003</p>
29  * <p>Company: </p>
30  * @author unascribed
31  * @version 1.0
32  */

33 public class SemiJoinIteratorWithoutCondition extends AbstractQualifiedJoinIterator implements _HasRecordIterator, SimpleConstants {
34
35    /**
36     * Variable representing the count of key Columns for left iterator.
37     */

38
39    private int leftCount = -1; //to be Used for Counting the keyColumnInformation from leftIterator.
40

41    public SemiJoinIteratorWithoutCondition(_Iterator leftIterator, _Iterator rightIterator, _KeyColumnInformation[] leftKeyColumnInformation0, _KeyColumnInformation[] rightKeyColumnInformation0, ColumnDetails[] hasRecordReferences0) {
42       super(leftIterator, rightIterator, leftKeyColumnInformation0, rightKeyColumnInformation0, hasRecordReferences0);
43       leftCount = leftKeyColumnInformation0.length;
44    }
45
46    /**
47     * This method is responsible to retrieve the first record from iterator.
48     * 1. If there are no records in left iterator, return false.
49     * 2. First record is retrieved from right iterator. If there are no records
50     * in right iterator, variable rightNull is set to true indicating that for
51     * the current record from left iterator, right iterator has no records,
52     * otherwise it is set to false. Return true.
53     *
54     * DETAILED DOCUMENTATION
55     *
56     * This is the method that is used to align both the iterators in such a
57     * fashion that actually points to the first valid record of the Left Join
58     * Iterator.
59     * Algo :
60     * i. Left Iterator get aligned to its valid first position. If returned
61     * false then Iterator's <state> 'll be set AFTERLAST and LeftJoinIterator
62     * 'll return false indicating that there are no valid records and End.
63     * ii. first() of Right Iterator 'll be called .
64     * iii. If returned false then rightNull flag 'll be set to true. otherwise
65     * rightNull flag 'll become false and LeftJoinIteraotor 'll return
66     * true after setting the state to a VALIDSTATE.
67     *
68     * @return true if record found, false otherwise.
69     * @throws DException
70     */

71    public boolean first() throws DException {
72       rightNull = false;
73       if (!leftIterator.first()) {
74          state = AFTERLAST;
75          return false;
76       }
77       rightNull = !rightIterator.first();
78       state = VALIDSTATE;
79       return true;
80    }
81
82    /**
83     * This method is responsible to retrieve the last record from iterator.
84     * 1. If there are no records in left iterator, return false.
85     * 2. Last record is retrieved from right iterator. If there are no records
86     * in right iterator, variable rightNull is set to true indicating that for
87     * the current record from left iterator, right iterator has no records,
88     * otherwise it is set to false. Return true.
89     *
90     * DETAILED DOCUMENTATION
91     *
92     * This is the method that is used to align both the iterators in such a fashion
93     * that actually points to the last valid record of the Left Join Iterator.
94     * Algo :
95     * i. Left Iterator get aligned to its valid last position. If returned
96     * false then Iterator's <state> 'll be set BEFOREFIRST and LeftJoin
97     * Iterator 'll return false indicating that there are no valid records
98     * and End.
99     * ii. last() of Right Iterator 'll be called .
100     * iii. If returned false then rightNull flag 'll be set to true.
101     * otherwise rightNull flag 'll become false and LeftJoinIteraotor 'll
102     * return true after setting the state to a VALIDSTATE.
103     *
104     * @return true if record found, false otherwise.
105     * @throws DException
106     */

107    public boolean last() throws DException {
108       rightNull = false;
109       if (!leftIterator.last()) {
110          state = BEFOREFIRST;
111          return false;
112       }
113       rightNull = !rightIterator.last();
114       state = VALIDSTATE;
115       return true;
116    }
117
118    /**
119     * This method is responsible to retrieve the NEXT record from iterator.
120     * 1. If variable rightNull is false it means there are some records in right
121     * iterator, thus, right iterator is checked for more records.
122     * 2. Next record is retrieved from right iterator. If record found, variable
123     * rightNull remains set to false indicating that there are more records in
124     * right iterator. Return true, Else Goto step 4.
125     * 3. Otherwise, variable rightNull is false, means, for the current record
126     * from left iterator, there are no records in right iterator. Goto step4.
127     * 4. Next record is retrieved from left iterator, if record not found return false.
128     * 5. First record is retrieved from right iterator. If there are no records
129     * in right iterator, variable rightNull is set to true indicating that for
130     * the current record from left iterator there are no records in right iterator,
131     * otherwise it is set to false. Return true.
132     *
133     * DETAILED DOCUMENTATION
134     *
135     * This is the method that is used to align both the iterators in such a fashion
136     * that actually points to the next valid record of the Left Join Iterator from
137     * its current position.
138     * Algo :
139     * i. If previous state is INVALIDSTATE,
140     * through Invalid State Exception.
141     * Else If previous state is AFTERLAST,
142     * return false.
143     * Else If previous state is BEFOREFIRST,
144     * call and return its first() .
145     *
146     * ii. If rightNull flag is true then (indicating that no more valid records
147     * are left corresponding to current value from left Iterator)
148     *
149     * iii. 1. Left Iterator get aligned to its valid next position. If
150     * returned false then Iterator's <state> 'll be set AFTERLAST
151     * and LeftJoinIterator 'll return false indicating that there
152     * are no more valid records and method 'll return false.
153     *
154     * 2. first() of Right Iterator 'll be called.
155     *
156     * 3. If returned false then rightNull flag 'll be set to true.
157     * otherwise rightNull flag 'll become false and LeftJoinIteraotor
158     * 'll return true after setting the state to a VALIDSTATE.
159     *
160     * iv. Else (i.e rightNull flag is false indicating that there may
161     * be more records valid left corresponding to current value from left
162     * Iterator)right Iterator 'll be iterated to its valid next position.
163     * If returned true then state 'll set to VALIDSTATE and true 'll be
164     * returned.else (step iii) 'll be called and state 'll set to VALIDSTATE
165     * and true 'll be returned.
166     * @return true if record found, false otherwise.
167     * @throws DException
168     */

169    public boolean next() throws DException {
170       switch (state) {
171          case INVALIDSTATE:
172             throw new DException("DSE4116", null);
173          case AFTERLAST:
174             return false;
175          case BEFOREFIRST:
176             return first();
177          default: {
178             if (rightNull) {
179                if (!leftIterator.next()) {
180                   state = AFTERLAST;
181                   return false;
182                }
183             } else {
184                if (!rightIterator.next()) {
185                   if (!leftIterator.next()) {
186                      state = AFTERLAST;
187                      return false;
188                   }
189                   rightIterator.first();
190                }
191             }
192             state = VALIDSTATE;
193             return true;
194          }
195       }
196    }
197
198    /**
199     * This method is responsible to retrieve the PREVIOUS record from iterator.
200     * 1. If variable rightNull is false it means there are some records in right
201     * iterator, thus, right iterator is checked for more records.
202     * 2. Previous record is retrieved from right iterator. If record found, variable
203     * rightNull remains set to false indicating that there are more records in
204     * right iterator. Return true, Else Goto step 4.
205     * 3. Otherwise, variable rightNull is false, means, for the current record
206     * from left iterator, there are no records in right iterator. Goto step4.
207     * 4. Previous record is retrieved from left iterator, if record not found return false.
208     * 5. Last record is retrieved from right iterator. If there are no records
209     * in right iterator, variable rightNull is set to true indicating that for
210     * the current record from left iterator there are no records in right iterator,
211     * otherwise it is set to false. Return true.
212     *
213     * DETAILED DOCUMENTATION
214     *
215     * <p>This is the method that is used to align both the iterators in such a
216     * fashion that actually points to the previous valid record of the Left Join
217     * Iterator from its current position. Boolean <b>rightNull</b> indicates no
218     * more valid records are left corresponding to current value from left Iterator
219     * <br>
220     * <b>Algo :</b><br>
221     * <ol>
222     * <li> If previous <state> is INVALIDSTATE, through Invalid State Exception.</li>
223     * <li> If previous state is AFTERLAST,call and return its first() </li>
224     * <li> If previous state is BEFOREFIRST,return false.</li>
225     * <li>. If rightNull flag is true then
226     * <ol>
227     * <li> Left Iterator get aligned to its valid next position. If
228     * returned false then Iterator's <state> 'll be set BEFOREFIRST
229     * and LeftJoinIterator 'll return false indicating that there
230     * are no more valid records and method 'll return false.</li>
231     * <li> If returned false then rightNull flag 'll be set to true.
232     * otherwise rightNull flag 'll become false and LeftJoinIteraotor
233     * 'll return true after setting the state to a
234     * VALIDSTATE.</li>
235     * </ol><br>
236     * <b>ELSE</b><br>
237     * <p> Right Iterator 'll be iterated to its valid previous position.
238     * If returned true then state 'll set to VALIDSTATE and true
239     * 'll be returned. otherwise step 3 will be called and state 'll
240     * set to VALIDSTATE and true 'll be returned.</p>
241     * @return true if record found, false otherwise.
242     * @throws DException
243     */

244    public boolean previous() throws DException {
245       switch (state) {
246          case INVALIDSTATE:
247             throw new DException("DSE4117", null);
248          case BEFOREFIRST:
249             return false;
250          case AFTERLAST:
251             return last();
252          default: {
253             if (rightNull) {
254                if (!leftIterator.previous()) {
255                   state = BEFOREFIRST;
256                   return false;
257                }
258             } else {
259                if (!rightIterator.previous()) {
260                   if (!leftIterator.previous()) {
261                      state = BEFOREFIRST;
262                      return false;
263                   }
264                   rightIterator.last();
265                }
266             }
267             state = VALIDSTATE;
268             return true;
269          }
270       }
271    }
272
273    /**
274     * This method returns the key by concating the key of underlying Iterator.
275     * if rightNull is true then null is appended as key of Right Iterator.
276     * @return key of left join iterator
277     * @throws DException
278     */

279    public Object JavaDoc getKey() throws DException {
280       ArrayList list = new ArrayList();
281       Object JavaDoc[] leftKeys = (Object JavaDoc[]) leftIterator.getKey();
282       list.addAll(java.util.Arrays.asList(leftKeys));
283       this.leftCount = leftKeys.length;
284       if (rightNull) {
285          list.add(null);
286       } else {
287          Object JavaDoc[] rightKeys = (Object JavaDoc[]) rightIterator.getKey();
288          list.addAll(java.util.Arrays.asList(rightKeys));
289       }
290       return list.toArray();
291    }
292
293    /**
294     * This method is responsible to align both underlying iterator acc. to key
295     * pasesed. It is used for a LOJ Iterator created for query having groupby
296     * clause. If any of the iterator's key length is zero, its first record is
297     * retrieved, since for this group, aggregates will be computed for all the
298     * records belonging to that group. Otherwise, key for left/right iterators
299     * are extracted from passed keys and move both the iterators to its corresponding keys.
300     * @param keys represents key where to align, underling iterators. keys
301     * have the values of group by columns.
302     * @throws DException
303     */

304    private void moveAcctoGroupKey(Object JavaDoc[] keys) throws DException {
305      if (leftKeyCount == 0) {
306         leftIterator.first();
307      } else {
308         Object JavaDoc[] leftKeys = new Object JavaDoc[leftKeyCount];
309         System.arraycopy(keys, 0, leftKeys, 0, leftKeyCount);
310         leftIterator.move(leftKeys);
311      }
312      if (rightKeyCount == 0) {
313         rightNull = !rightIterator.first();
314      } else {
315         int rightLength = keys.length - leftKeyCount;
316         Object JavaDoc[] rightKeys = new Object JavaDoc[rightLength];
317         System.arraycopy(keys, leftKeyCount, rightKeys, 0, rightLength);
318         if (isKeyNull(rightKeys)) {
319            rightNull = true;
320         } else {
321            rightNull = false;
322            rightIterator.move(rightKeys);
323         }
324      }
325      state = VALIDSTATE;
326    }
327
328    /**
329     * This method is responsible to align both underlying iterator acc. to key
330     * pasesed. For a left Join Iterator created on query having group by clause,
331     * call is transfered to moveAcctoGroupKey method.
332     * For a non-group by Join Query, left iterator keys are extracted from the
333     * passed key. Left iterator is aligned acc. to the left iterator key. If the
334     * keys corresponding to right iterator are null, the variable rightNull is
335     * set to true, indicating that for current row of left iterator, the right
336     * iterator has no records, Otherwise, right Iterator is aligned to
337     * non-null keys of right iterator extracted from passed key.
338     * @param keys key where to point to Left Join iterator
339     * @throws DException
340     */

341    public void move(Object JavaDoc keys) throws DException {
342       if (leftKeyCount != 0 || rightKeyCount != 0) {
343          moveAcctoGroupKey( (Object JavaDoc[]) keys);
344          return;
345       }
346       Object JavaDoc[] leftKeys = new Object JavaDoc[leftCount];
347       Object JavaDoc[] rightKeys = new Object JavaDoc[ ( (Object JavaDoc[]) keys).length - leftCount];
348       System.arraycopy(keys, 0, leftKeys, 0, leftCount);
349       System.arraycopy(keys, leftCount, rightKeys, 0, rightKeys.length);
350       leftIterator.move(leftKeys);
351       if (isKeyNull(rightKeys)) {
352          rightNull = true;
353       } else {
354          rightNull = false;
355          rightIterator.move(rightKeys);
356       }
357       state = VALIDSTATE;
358    }
359
360    /**
361     * The following methods are used for getting values of current record.
362     * All retrival methods use the following logic.
363     * The retrival method checks passed column, if the column corresponds to LEFT
364     * table, values are retrived from left iterator, otherwise if rightNull flag
365     * is true, Null value is returned corresponding to that column reference of right
366     * iterator, otherwise values are retrived from right iterator.
367     */

368    /**
369     * This method is used to retrieve the values of passed references.
370     * @param leftColumnReferences reference for which values are to be retrived.
371     * Reference may be column or parameter.
372     * @return NonShared FieldBases denoting the value of References. Non Shared
373     * FieldBases are those for which BufferRange is not shared with some other
374     * FieldBase.
375     * @throws DException
376     */

377    public Object JavaDoc getColumnValues(_Reference[] leftColumnReferences) throws DException {
378       int len = leftColumnReferences.length;
379       Object JavaDoc[] values = new Object JavaDoc[len];
380       for (int i = 0; i < len; i++) {
381          ColumnDetails refColumnDetail = (ColumnDetails) leftColumnReferences[i];
382          TableDetails tDetails = refColumnDetail.getTable();
383          if (searchInMapping(tDetails) == SimpleConstants.LEFT) {
384             values[i] = leftIterator.getColumnValues(leftColumnReferences[i]);
385          } else
386          if (!rightNull) {
387             values[i] = rightIterator.getColumnValues(leftColumnReferences[i]);
388          } else {
389             values[i] = new FieldLiteral(FieldUtility.NULLBUFFERRANGE, ( (ColumnDetails) leftColumnReferences[i]).getDatatype());
390          }
391       }
392       return values;
393    }
394
395    /**
396     * This method is used to retrieve all the values from the join query.
397     * This method retrives all the values from the left iterator and values from
398     * right iterator and merge these values to return the valid record of join iterator.
399     * @return NonShared FieldBases denoting the values of all columns of join query.
400     * Non Shared FieldBases are those for which BufferRange is not shared with
401     * some other FieldBase.
402     * @throws DException
403     */

404    public Object JavaDoc getColumnValues() throws DException {
405       ArrayList aList = new ArrayList();
406       Object JavaDoc obj1 = leftIterator.getColumnValues();
407       aList.addAll(Arrays.asList( (Object JavaDoc[]) obj1));
408       Object JavaDoc[] obj2 = null;
409       if (rightNull) {
410         obj2=makeNullFieldLiteralArray(rightColumnCount);
411       } else {
412          obj2 = (Object JavaDoc[]) rightIterator.getColumnValues();
413       }
414       aList.addAll(Arrays.asList(obj2));
415       return aList.toArray();
416    }
417
418    /**
419     * This method returns the value of passed columnreferences. If the passed
420     * columnreference belong to right Iterator and rightNull flag is true, then
421     * null value is returned corresponding to that column reference.
422     * @param references for which value is to be retrieved
423     * @return NonShared FieldBase denoting the value of passed column reference.
424     * Non Shared FieldBases are those for which BufferRange is not shared with
425     * some other FieldBase.
426     * @throws DException
427     */

428    public Object JavaDoc getColumnValues(_Reference references) throws DException {
429       field(references);
430       Object JavaDoc values = null;
431       ColumnDetails refColumnDetail = (ColumnDetails) references;
432       TableDetails tDetails = refColumnDetail.getTable();
433       int index = searchInMapping(tDetails);
434       if (index == -1) {
435          return GeneralPurposeStaticClass.getColumnValuesFromQualified(leftIterator, rightIterator, references, rightNull);
436       }
437       if (index == SimpleConstants.LEFT) {
438          values = leftIterator.getColumnValues(references);
439       } else if (rightNull) {
440          values = new FieldLiteral(FieldUtility.NULLBUFFERRANGE, ( (ColumnDetails) references).getDatatype());
441       } else {
442          values = rightIterator.getColumnValues(references);
443       }
444       return values;
445    }
446
447    /**
448     * This method return the shared FieldBase for the passed reference. By Shared
449     * FieldBase we mean, BufferRange of FieldBase is shared with other FieldBase
450     * objects.
451     * @param references reference for which value is to be retrived
452     * @return shared field base correspondition to passed column reference
453     * @throws DException
454     */

455    public FieldBase field(_Reference references) throws DException {
456       FieldBase values = null;
457       ColumnDetails refColumnDetail = (ColumnDetails) references;
458       TableDetails tDetails = refColumnDetail.getTable();
459       int index = searchInMapping(tDetails);
460       if (index == -1) {
461          return GeneralPurposeStaticClass.getFieldFromQualified(leftIterator, rightIterator, references, rightNull);
462       }
463       if (index == SimpleConstants.LEFT) {
464          values = leftIterator.field(references);
465       } else if (rightNull) {
466          values = new FieldLiteral(null, ( (ColumnDetails) references).getDatatype());
467          ( (FieldLiteral) values).setBufferRange(FieldUtility.NULLBUFFERRANGE);
468       } else {
469          values = rightIterator.field(references);
470       }
471       return values;
472    }
473
474    /**
475     * This method return the shared FieldBases for the passed references. By Shared
476     * FieldBase we mean, BufferRange of FieldBase is shared with other FieldBase
477     * objects.
478     * @param leftColumnReferences reference for which values are to be retrived
479     * @return shared field base correspondition to passed column reference
480     * @throws DException
481     */

482    public FieldBase[] fields(_Reference[] leftColumnReferences) throws DException {
483       int len = leftColumnReferences.length;
484       FieldBase[] values = new FieldBase[len];
485       for (int i = 0; i < len; i++) {
486          values[i] = field(leftColumnReferences[i]);
487       }
488       return values;
489    }
490
491    /**
492     * This method returns the byte key by concating the byte keys of both
493     * underlying Iterator. If rightNull is true then -1 is put corresponding to
494     * byte key of Right Iterator.
495     * @return Array of Object having the key
496     * @throws DException
497     */

498   public byte[] getByteKey() throws DException {
499     byte[] leftKeys = leftIterator.getByteKey();
500     if (rightNull) {
501       short leftLen = (short)leftKeys.length;
502       byte[] result = new byte[leftLen + 4];
503       System.arraycopy(CCzufDpowfsufs.getBytes(leftLen),0,result,0,2);
504       System.arraycopy(leftKeys, 0, result, 2, leftKeys.length);
505       System.arraycopy(CCzufDpowfsufs.getBytes((short)-1),0,result,leftLen+2,2);
506       return result;
507
508     }
509     else{
510       byte[] rightKeys = rightIterator.getByteKey();
511       byte[] resultantKeys = new byte[leftKeys.length + rightKeys.length + 4];
512       short leftLen = (short)leftKeys.length;
513       System.arraycopy(CCzufDpowfsufs.getBytes(leftLen),0,resultantKeys,0,2);
514       System.arraycopy(leftKeys, 0, resultantKeys, 2, leftKeys.length);
515       short rightLen = (short)rightKeys.length;
516       System.arraycopy(CCzufDpowfsufs.getBytes(rightLen),0,resultantKeys,leftLen+2,2);
517       System.arraycopy(rightKeys, 0, resultantKeys, leftKeys.length + 4,
518                        rightKeys.length);
519       return resultantKeys;
520     }
521   }
522
523   /**
524    * This method is responsible to align both underlying iterator acc. to key
525    * pasesed. It is used for a LOJ Iterator created for query having groupby
526    * clause. If any of the iterator's key length is zero, its first record is
527    * retrieved, since for this group, aggregates will be computed for all the
528    * records belonging to that group. Otherwise, key for left/right iterators
529    * are extracted from passed keys and move both the iterators to its corresponding keys.
530    * @param keys where to align the underling iterators
531    * @throws DException
532    */

533   private void moveAcctoGroupByteKey(byte[] keys) throws DException {
534     int k = 0, index = 0;
535     int[] t = null;
536     if (leftKeyCount == 0)
537       throw new DException("DSE0", new Object JavaDoc[] {"Left Key Count can not be null"});
538     else {
539       index = moveBytes(leftTableDetails, leftIterator, index, keys);
540     }
541     if (rightKeyCount == 0)
542       rightIterator.first();
543     else {
544       index = moveBytes(rightTableDetails, rightIterator, index, keys);
545     }
546     state = VALIDSTATE;
547   }
548
549   /**
550    * This method is used to move left or right iterator acc. to passed key.
551    * @param td left or right side tables
552    * @param iter left or right side iterators
553    * @param index it is 0
554    * @param keys where to move left or right iterator
555    * @return total keys length including all the tables of left/right hand side
556    * @throws DException
557    */

558   private int moveBytes(TableDetails[] td, _Iterator iter, int index,
559                         byte[] keys) throws DException {
560     int length = 0;
561     for (int j = 0; j < td.length; j++) {
562       short len = CCzufDpowfsufs.getShortValue(keys,index);
563       length +=len;
564       index = length + 2;
565     }
566     byte[] resultantKeys = new byte[length];
567     System.arraycopy(keys, 0, resultantKeys, 0, resultantKeys.length);
568     iter.move(resultantKeys);
569     rightNull = isKeyNull(resultantKeys);
570     return index;
571
572   }
573
574   public void moveByteKey(byte[] key) throws DException {
575     /** @todo group by iterator work */
576     if (leftKeyCount != 0 || rightKeyCount != 0) {
577       moveAcctoGroupByteKey(key);
578       return;
579     }
580     short leftLength = CCzufDpowfsufs.getShortValue(key,0);
581     byte[] leftKeys = new byte[leftLength];
582     System.arraycopy(key, 2, leftKeys, 0, leftKeys.length);
583     leftIterator.moveByteKey(leftKeys);
584     short rightLength =CCzufDpowfsufs.getShortValue(key,leftKeys.length+2);
585     if (rightLength < 0)
586       rightNull = true;
587     else {
588       rightNull = false;
589       byte[] rightKeys = new byte[rightLength];
590       System.arraycopy(key, leftKeys.length + 4, rightKeys, 0, rightLength);
591       rightIterator.moveByteKey(rightKeys);
592     }
593     state = 0;
594
595   }
596
597
598
599
600    /**
601     * This method is responsible to check whether the passed tables
602     * corresponds to left iterator or right iterator.
603     * @param tDetails table to check
604     * @return table belongs to LEFT or RIGHT iterator.
605     * @throws DException
606     */

607    private int searchInMapping(TableDetails tDetails) throws DException {
608       for (int i = 0; i < tableDetailsMapping.length; i++) {
609          if (tableDetailsMapping[i][0] == tDetails) {
610             return ( (Integer JavaDoc) tableDetailsMapping[i][1]).intValue();
611          }
612       }
613       return -1;
614    }
615
616    /**
617     * This method is used to get the lowest level iterator of the passed column.
618     * For the passed column, Base iterator can not be either of the underlying
619     * iterator, since the column may correspond to either of the table. The value
620     * of passed column are retrieved by checking the variable rightNull. Since,
621     * if rightNull is true and column corresponds to right iterator, NULL will
622     * be returned, otherwise, value is retrived from corresponding iterator.
623     * @param column corresponding to which, iterator has to return
624     * @return base table iterator corresponding to column passed
625     * @throws DException
626     */

627    public _Iterator getBaseIterator(ColumnDetails column) throws DException {
628       return this;
629    }
630
631    /**
632     * This method is responsible to display the executionPlan of a Select Query.
633     * @return _ExecutionPlan
634     * @throws DException
635     */

636    public _ExecutionPlan getExecutionPlan() throws DException {
637       _ExecutionPlan plan = leftIterator.getExecutionPlan();
638       _ExecutionPlan plan1 = rightIterator.getExecutionPlan();
639       _ExecutionPlan cplans[] = new _ExecutionPlan[] {plan, plan1};
640       return new ExecutionPlan("SemiJoinIteratorWithoutCondition", cplans, null, null, null);
641    }
642
643    /**
644     * This method is responsible to display the iterators hierarchy of a Select Query.
645     * @return ExecutionPlanForBrowser
646     * @throws DException
647     */

648    public ExecutionPlanForBrowser getExecutionPlanForBrowser() throws DException {
649       int length = 2;
650       ExecutionPlanForBrowser cplans[] = new ExecutionPlanForBrowser[length];
651       cplans[0] = leftIterator.getExecutionPlanForBrowser();
652       cplans[1] = rightIterator.getExecutionPlanForBrowser();
653       String JavaDoc refer = "";
654       return new ExecutionPlanForBrowser("Nested Join/Left Join" + refer, "Left Join Iterator", cplans, null, null, null);
655    }
656
657    public String JavaDoc toString() {
658       return "SemiJoinIteratorWithoutCondition[" + leftIterator + "]\n\n\n[" + rightIterator + "]";
659    }
660 }
661
Popular Tags