KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > mergesystem > MergeIterator


1 package com.daffodilwoods.daffodildb.server.datasystem.mergesystem;
2
3 import com.daffodilwoods.database.resource.* ;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
6 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
7 import java.util.*;
8 import com.daffodilwoods.daffodildb.server.sql99.common._KeyColumnInformation;
9 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem._IndexInformation;
10 import com.daffodilwoods.daffodildb.utils.*;
11 import com.daffodilwoods.daffodildb.utils.field.*;
12
13 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
14
15 import com.daffodilwoods.daffodildb.server.sessionsystem.sessionversioninfo.SessionVersionHandler;
16
17
18 /**
19  *
20  * <p>Title: MergeIterator</p>
21  * <p>Description: It is required to perform operations on memory as well as
22  * file .When more than one user works on the table then each one is
23  * provided with the iterator.Every user can perform operations through
24  * their respective iterators.
25  *
26  * Requirements From MergeIterator :
27  * 1. Return the data in a desired order.
28  * 2. If a record is in memory and also in file , return it from memory.
29  */

30 public class MergeIterator extends UnionIterator implements _IndexIterator, _IndexIteratorInfo, _TableOperations {
31
32     /**
33      * Iterator which is on memorytable having index on systemFields(Rowid,transactionId,SessionId).it is
34      * used to check Record in memory,if Record having same systemFields is in memory as well as in file,
35      * then current record is in memory, so it moves Iterator on Record in memory
36      */

37
38     private _IndexIterator defaultIterator;
39     private _IndexTable mergeTable;
40     private _IndexIterator memoryIterator ;
41     private _IndexIterator fileIterator;
42     private Object JavaDoc[] fields;
43     SessionVersionHandler sessionVersionHandler;
44     /**
45      * constructs the MergeIterator with three index iterators and an indextable.
46      * @param defaultIterator0 is an index iterator that is default iterator on memory table
47      * @param fileMemoryIterator0 is an indexiterator on memory table
48      * @param fileIterator0 is an indexiterator on file table.
49      * @param mergeTable is the table that manages the operations on both the file and memory tables.
50      */

51
52     public MergeIterator(_IndexIterator defaultIterator0,_IndexIterator memoryIterator0,_IndexIterator fileIterator0,_IndexTable mergeTable0, SessionVersionHandler sessionVersionHandler0) {
53         super( new _IndexIterator[] {memoryIterator0,fileIterator0});
54         defaultIterator = defaultIterator0;
55         mergeTable = mergeTable0;
56         memoryIterator = memoryIterator0;
57         fileIterator = fileIterator0;
58         sessionVersionHandler = sessionVersionHandler0;
59         try {
60             fields = FieldUtility.getFields(mergeTable.getTableCharacteristics().getColumnTypes(),
61                     mergeTable.getTableCharacteristics().getCollator());
62         }
63         catch (DException ex) {
64         }
65     }
66
67
68       public MergeIterator(_IndexIterator memoryIterator0,_IndexIterator fileIterator0,_IndexTable mergeTable0, SessionVersionHandler sessionVersionHandler0) {
69           super( new _IndexIterator[] {memoryIterator0,fileIterator0});
70           mergeTable = mergeTable0;
71           memoryIterator = memoryIterator0;
72           fileIterator = fileIterator0;
73            sessionVersionHandler = sessionVersionHandler0;
74           try {
75               fields = FieldUtility.getFields(mergeTable.getTableCharacteristics().getColumnTypes(),
76                       mergeTable.getTableCharacteristics().getCollator());
77           }
78           catch (DException ex) {
79           }
80       }
81
82     /**
83      * it sets current key on first record on the basis of index columns order.if Record is in memory and
84      * as well as in file then alligns itself on memory Record
85      *
86      * @return true if any Record exists in table
87      */

88
89     public boolean first() throws DException{
90         recordLoaded = false;
91         if(super.first()){
92             BitSet bitset = ((UnionKey)currentKey).getBitSet();
93             if(bitset.get(0))
94                 return true;
95             else{
96                 if(!defaultIterator.seek(sessionVersionHandler.getDefaultKey(((_Key)currentKey).getKeyValue()) ) )
97                     return true;
98                 else
99                     return super.next();
100             }
101         }
102         else
103             return false;
104     }
105
106     /**
107      * it sets current key on last record on the basis of index columns order.if Record is in memory and
108      * as well as in file then alligns itself on memory Record
109      *
110      * @return true if any Record exists in table
111      */

112
113     public boolean last() throws DException{
114         recordLoaded = false;
115         if(super.last()){
116             BitSet bitset = ((UnionKey)currentKey).getBitSet();
117             if(bitset.get(0))
118                 return true;
119             else{
120                 if(!defaultIterator.seek( sessionVersionHandler.getDefaultKey(((_Key)currentKey).getKeyValue()) ) )
121                     return true;
122                 else
123                     return super.previous();
124             }
125         }
126         else
127             return false;
128     }
129
130     /**
131      * it sets current key on next key of current key on the basis of index columns order.if Record is in
132      * memory and as well as in file then alligns itself on memory Record
133      *
134      * @return true if next key of current key exists in table
135      */

136
137     public boolean next() throws DException{
138       recordLoaded = false;
139         if(status != VALIDSTATE)
140             return status == AFTERLAST ? false : first();
141         if(super.next()){
142             BitSet bitset = ((UnionKey)currentKey).getBitSet();
143             if(bitset.get(0))
144                 return true;
145             else{
146                 if(!defaultIterator.first() || !defaultIterator.seek( sessionVersionHandler.getDefaultKey(((_Key)currentKey).getKeyValue()) ) )
147                     return true;
148                 else{
149                     return super.next();
150                 }
151             }
152         }
153         else
154             return false;
155     }
156
157     /**
158      * it sets current key on previous key of current key on the basis of index columns order.if Record is
159      * in memory and as well as in file then alligns itself on memory Record
160      *
161      * @returns true if previous key of current key exists in table
162      */

163
164     public boolean previous() throws DException{
165       recordLoaded = false;
166         if(status != VALIDSTATE)
167             return status == BEFOREFIRST ? false : last();
168         if(super.previous()){
169             BitSet bitset = ((UnionKey)currentKey).getBitSet();
170             if(bitset.get(0))
171                 return true;
172             else{
173                 if(!defaultIterator.first() || !defaultIterator.seek( sessionVersionHandler.getDefaultKey(((_Key)currentKey).getKeyValue()) ) )
174                     return true;
175                 else{
176                     return super.previous();
177                 }
178             }
179         }
180         else
181             return false;
182     }
183
184     /**
185      * Inserts the record in memory and updates its current key
186      *
187      * @param values which has to insert
188      */

189
190     public void insert(Object JavaDoc values) throws DException {
191       recordLoaded = false;
192         ((_TableOperations)memoryIterator).insert(values);
193         BitSet bitset = new BitSet(2);
194         Object JavaDoc[] keys = new Object JavaDoc[2];
195         keys[0] = memoryIterator.getKey();
196         bitset.set(0);
197         currentKey = new UnionKey(bitset,keys,true);
198         status = VALIDSTATE;
199     }
200
201
202     /**
203      * If record which has to update is in file then shifts record from file to memory and updates Record in
204      * memory and updates its current key
205      *
206      * @param values new values with which record has to update
207      */

208
209     public void update(Object JavaDoc values) throws DException {
210       throw new UnsupportedOperationException JavaDoc("method update not supported ");
211
212     }
213
214     /**
215      * If record which has to update is in file then shifts record from file to memory and updates specified
216      * column values in memory and updates its current key
217      *
218      * @param columns columns whose values has to update
219      * @param values new values with which record has to update
220      */

221
222     public void update(int[] columns, Object JavaDoc[] values) throws DException {
223         if ( ( (UnionKey) currentKey).getBitSet().get(1) &&
224             (! ( (UnionKey) currentKey).getBitSet().get(0))) {
225           transferRecord(columns, values);
226         }
227         else {
228           ( (_TableOperations) memoryIterator).update(columns, values);
229         }
230         BitSet bitset = new BitSet(2);
231         Object JavaDoc[] keys = new Object JavaDoc[2];
232         keys[0] = memoryIterator.getKey();
233         bitset.set(0);
234         currentKey = new UnionKey(bitset,keys,((UnionKey)currentKey).getDirection());
235         status = VALIDSTATE;
236         recordLoaded = false;
237
238     }
239
240     private void transferRecord(int[] columns, Object JavaDoc[] vals) throws DException{
241         Object JavaDoc[] values = (Object JavaDoc[])getColumnValues();
242         values = clone(values);
243         for (int i = 0; i < columns.length; i++) {
244           values[columns[i]] = vals[i];
245         }
246         ((_TableOperations)memoryIterator).insert(values);
247         BitSet bitset = new BitSet(2);
248         Object JavaDoc[] keys = new Object JavaDoc[2];
249         keys[0] = fileIterator.getKey();
250         keys[1] = memoryIterator.getKey();
251         bitset.set(0);
252         currentKey = new UnionKey(bitset, keys, true);
253     }
254
255     private Object JavaDoc[] clone(Object JavaDoc[] values) throws DException{
256       FieldBase fb;
257         for (int i = 0; i < values.length; i++) {
258            fb = (FieldBase)values[i];
259             fb.setBufferRange(fb.getNull() ? FieldUtility.NULLBUFFERRANGE : new BufferRange(fb.getBufferRange().getBytes()));
260         }
261         return values;
262     }
263
264     public int getBtreeIndex() throws DException{
265         return ((_IndexIteratorInfo)memoryIterator).getBtreeIndex();
266     }
267
268     /**
269      * If record which has to delete is in file then shifts record from file to memory and deletes Record in
270      * memory and updates its current key
271      *
272      */

273
274     public void delete() throws DException {
275       throw new UnsupportedOperationException JavaDoc("method delete not supported ");
276     }
277
278     public Object JavaDoc getColumnValues() throws com.daffodilwoods.database.resource.DException {
279         try{
280             if(recordLoaded){
281                 return fields;
282             }
283             Object JavaDoc[] values = (Object JavaDoc[])super.getColumnValues();
284             setFields(values);
285             recordLoaded = true;
286             return values;
287         }
288         catch (DException ex) {
289             if(ex.getDseCode().equalsIgnoreCase("DSE2004")){
290                 if(((UnionKey)currentKey).getBitSet().get(0)){
291                     Object JavaDoc key = ((_Key)currentKey).getKeyValue();
292                     if(fileIterator.seek(key))
293                         return fields = (Object JavaDoc[])fileIterator.getColumnValues();
294                 }
295             }
296             throw ex;
297         }
298     }
299
300     public _Record getRecord() throws DException {
301         Record record = new Record(mergeTable.getTableCharacteristics(),null);
302         if(recordLoaded)
303             record.setObject(fields);
304         else
305             record.setObject((Object JavaDoc[])getColumnValues());
306         return record;
307     }
308
309     /**
310      * Returns values of columns set in references,if index is set in reference then it gets column Index
311      * from reference otherwise gets column index from tablecharacteristics by getting column name from
312      * reference and sets column index in reference
313      *
314      * @param reference It contains column index for which value is required
315      *
316      * @return values of columns set in references
317      *
318      * @throws DException if iterator is on invalid state
319      */

320
321     public Object JavaDoc getColumnValues(_Reference[] reference) throws DException{
322             _TableCharacteristics tc = mergeTable.getTableCharacteristics();
323             int[] columns = new int[reference.length];
324             for (int i = 0; i < columns.length; i++) {
325                 columns[i] = getColumn(reference[i],tc);
326             }
327             return getColumnValues(columns);
328     }
329
330
331     public _TableCharacteristics getTableCharacteristics() throws DException{
332         return mergeTable.getTableCharacteristics();
333     }
334
335     public _IndexInformation[] getUniqueInformation() throws DException{
336         return mergeTable.getIndexInformations();
337     }
338
339     /**
340      * Returns values of column set in reference,if index is set in reference then it gets column Index
341      * from reference otherwise gets column index from tablecharacteristics by getting column name from
342      * reference and sets column index in reference
343      *
344      * @param reference It contains column index for which value is required
345      *
346      * @return values of column set in references
347      *
348      * @throws DException if iterator is on invalid state
349      */

350
351     public Object JavaDoc getColumnValues(_Reference reference) throws com.daffodilwoods.database.resource.DException {
352             return getColumnValues(getColumn(reference,mergeTable.getTableCharacteristics()));
353     }
354
355     public boolean seekFromTopRelative(Object JavaDoc indexKey1) throws DException {
356       Object JavaDoc indexKey = getBytesOfIndexKey(indexKey1) ;
357       recordLoaded = false;
358         if(status == AFTERLAST)
359             return false;
360         if(currentKey == null)
361             return locateKey(indexKey,true);
362         Object JavaDoc currentKeyValue = ((_Key)currentKey).getKeyValue();
363         if(comparator.compare(indexKey,currentKeyValue) < 0)
364             return false;
365         BitSet bitSet = ((UnionKey)currentKey).getBitSet();
366         int length = iterators.length;
367         _Key[] keys = new _Key[length];
368         int num = 0;
369         for (int i = 0; i < length; i++) {
370             boolean seekResult = iterators[i].getKey() != null;
371             if(bitSet.get(i))
372                 seekResult = iterators[i].seekFromTopRelative(indexKey);
373             else{
374                 _Key otherKey = (_Key)iterators[i].getKey();
375                 Object JavaDoc otherKeyValue = otherKey == null ? null : otherKey.getKeyValue();
376                 if(compareToGetLowest(indexKey,otherKeyValue) > 0 || comparator.compare(currentKeyValue,otherKeyValue) == 0 ){
377                     seekResult = iterators[i].seekFromTopRelative(indexKey);
378                 }
379             }
380             if(seekResult){
381                 keys[i] = (_Key)iterators[i].getKey();
382                 num++;
383             }
384         }
385         return num == 0 ? setKeyAndStatus(AFTERLAST,null,false) : setKeyAndStatus(VALIDSTATE,new UnionKey(getLowestKey(keys),keys,true),true);
386 }
387
388     public boolean seekFromBottomRelative(Object JavaDoc indexKey1) throws DException {
389         if(status == BEFOREFIRST){
390          ;//// Removed By Program ** System.out.println("status == BEFOREFIRST");
391
return false;
392       }
393       Object JavaDoc indexKey = getBytesOfIndexKey(indexKey1) ;
394       recordLoaded = false;
395       if(currentKey == null){
396         return locateKey(indexKey, false);
397       }
398       Object JavaDoc currentKeyValue = ((_Key)currentKey).getKeyValue();
399       if(comparator.compare(indexKey,currentKeyValue) > 0){
400           return false;
401       }
402       BitSet bitSet = ((UnionKey)currentKey).getBitSet();
403       int length = iterators.length;
404       _Key[] keys = new _Key[length];
405       int num = 0;
406       boolean seekResult;
407       for (int i = 0; i < length; i++) {
408        seekResult = iterators[i].getKey() != null;
409           if(bitSet.get(i)){
410          ;//// Removed By Program ** System.out.println(" seekResult if ");
411
seekResult = iterators[i].seekFromBottomRelative(indexKey);
412           }
413           else{
414          ;//// Removed By Program ** System.out.println(" seekResult else ");
415
_Key otherKey = (_Key)iterators[i].getKey();
416               Object JavaDoc otherKeyValue = otherKey == null ? null : otherKey.getKeyValue();
417               int cmp = compareToGetHighest(indexKey,otherKeyValue);
418               if( cmp < 0 || comparator.compare(otherKeyValue,currentKeyValue) == 0){
419                   seekResult = iterators[i].seekFromBottomRelative(indexKey);
420               }
421           }
422           if(seekResult){
423          ;//// Removed By Program ** System.out.println(" seekResult ");
424
keys[i] = (_Key)iterators[i].getKey();
425               num++;
426           }
427       }
428       return num == 0 ? setKeyAndStatus(BEFOREFIRST,null,false) : setKeyAndStatus(VALIDSTATE,new UnionKey(getHighestKey(keys),keys,false),true);
429
430     }
431
432     public Object JavaDoc getBytesOfIndexKey(Object JavaDoc indexKey)throws DException{
433         int[] columnIndexes = (int[])memoryIterator.getUniqueColumnReference()[0];
434         _TableCharacteristics tableCharacteristics = mergeTable.getTableCharacteristics();
435         if(columnIndexes.length == 1){
436             if(!(indexKey instanceof BufferRange) && !(indexKey instanceof BufferRange[])){
437                 try {
438                     indexKey = tableCharacteristics.getBufferRange(columnIndexes[0],indexKey);
439                 }
440                 catch (ClassCastException JavaDoc ex) {
441                     indexKey = tableCharacteristics.getBufferRange(columnIndexes[0],((Object JavaDoc[])indexKey)[0]);
442                 }
443             }
444         }
445         else{
446             Object JavaDoc[] key = (Object JavaDoc[])indexKey;
447             int[] seekColumns = new int[key.length];
448             for(int i = 0 ; i < key.length ; i++)
449                 seekColumns[i] = columnIndexes[i];
450                 if(!(key[0] instanceof BufferRange))
451                     indexKey = tableCharacteristics.getBufferRange(seekColumns,(Object JavaDoc[])indexKey);
452         }
453         return indexKey;
454     }
455
456     public FieldBase field(_Reference reference) throws com.daffodilwoods.database.resource.DException {
457         if(status != VALIDSTATE)
458             throw new DException("DSE2019",new Object JavaDoc[] {new Integer JavaDoc(status)});
459         boolean flag = false;
460         int columnIndex = -1;
461         try{
462             columnIndex = reference.getIndex();
463         }
464         catch(DException e){
465             if(!e.getDseCode().equalsIgnoreCase("DSE565"))
466                 throw e;
467             reference.setIndex(columnIndex = mergeTable.getTableCharacteristics().getIndexForColumnName(reference.getColumn()));
468         }
469         return field(columnIndex);
470     }
471
472     public FieldBase[] fields(_Reference[] references) throws com.daffodilwoods.database.resource.DException {
473         if(status != VALIDSTATE)
474             throw new DException("DSE2019",new Object JavaDoc[] {new Integer JavaDoc(status)});
475         boolean flag = false;
476         int[] values = new int [references.length];
477         for(int i =0,index ; i < references.length ; i++){
478            index = -1;
479             try{
480                 index = references[i].getIndex();
481             }
482             catch(DException e){
483                 if(!e.getDseCode().equalsIgnoreCase("DSE565"))
484                     throw e;
485                 references[i].setIndex(index = mergeTable.getTableCharacteristics().getIndexForColumnName(references[i].getColumn()));
486             }
487             values[i] = index;
488         }
489         return fields(values);
490     }
491
492     public FieldBase[] fields(int[] columns) throws com.daffodilwoods.database.resource.DException {
493             if(recordLoaded == false){
494                 Object JavaDoc[] values = (Object JavaDoc[])getColumnValues();
495                 setFields(values);
496                 recordLoaded = true;
497             }
498             FieldBase[] array = new FieldBase[columns.length];
499             for (int i = 0; i < columns.length; i++) {
500                 array[i] = (FieldBase)fields[columns[i]];
501             }
502             return array;
503     }
504
505     public FieldBase field(int column) throws DException {
506           return recordLoaded ? (FieldBase)fields[column] :
507                   (FieldBase)getColumnValues(column);
508     }
509
510     public Object JavaDoc getColumnValues(int column) throws com.daffodilwoods.database.resource.DException {
511         try {
512             if(recordLoaded){
513                 return fields[column];
514             }
515             Object JavaDoc[] values = (Object JavaDoc[])super.getColumnValues();
516             setFields(values);
517             recordLoaded = true;
518             return values[column];
519         }
520         catch (DException ex) {
521             if(ex.getDseCode().equalsIgnoreCase("DSE2004")){
522                 if(((UnionKey)currentKey).getBitSet().get(0)){
523                     Object JavaDoc key = ((_Key)currentKey).getKeyValue();
524                     if(fileIterator.seek(key))
525                         return fileIterator.getColumnValues(column);
526                 }
527             }
528             throw ex;
529         }
530     }
531
532     public Object JavaDoc getColumnValues(int[] columns) throws com.daffodilwoods.database.resource.DException {
533         try{
534             if(recordLoaded == false){
535                 Object JavaDoc[] values = (Object JavaDoc[])super.getColumnValues();
536                 setFields(values);
537                 recordLoaded = true;
538             }
539             int len = columns.length;
540             Object JavaDoc[] vals = new Object JavaDoc[len];
541             for (int i = 0; i < len ; i++) {
542                 vals[i] = fields[columns[i]];
543             }
544             return vals;
545         }
546         catch (DException ex) {
547             if(ex.getDseCode().equalsIgnoreCase("DSE2004")){
548                 if(((UnionKey)currentKey).getBitSet().get(0)){
549                     Object JavaDoc key = ((_Key)currentKey).getKeyValue();
550                     if(fileIterator.seek(key))
551                         return fileIterator.getColumnValues(columns);
552                 }
553             }
554             throw ex;
555         }
556     }
557
558 /*
559     private Object duplicate(int[] columns) throws DException{
560         FieldBase[] newValues;
561         _TableCharacteristics tc = mergeTable.getTableCharacteristics();
562         if( columns == null ){
563             newValues = FieldUtility.getFields(tc.getColumnTypes(),
564                     tc.getCollator() != null);
565             for (int i = 0; i < fields.length; i++) {
566                 if( tc.isBlobClob(i) )
567                     newValues[i] = fields[i];
568                 else
569                     newValues[i].setBufferRange(fields[i].getBufferRange());
570             }
571
572         }
573         else{
574             newValues = FieldUtility.getFields(tc.getColumnTypes(columns),
575                     tc.getCollator() != null);
576             for (int i = 0; i < columns.length; i++) {
577                 if( tc.isBlobClob(columns[i]) )
578                     newValues[i] = fields[columns[i]];
579                 else
580                     newValues[i].setBufferRange(fields[columns[i]].getBufferRange());
581
582
583             }
584         }
585         return newValues;
586     }
587 */

588     private void setFields(Object JavaDoc[] values) throws DException{
589         fields = values;
590     }
591     public boolean hasAnyRecords() throws DException {
592       throw new UnsupportedOperationException JavaDoc("method hasAnyRecords not supported for this class");
593    }
594    public Object JavaDoc[] getUniqueColumnReference() throws DException {
595        return fileIterator.getUniqueColumnReference();
596    }
597    public boolean seekFromBottom(_IndexPredicate[] condition) throws DException {
598        recordLoaded = false;
599        if(!memoryIterator.seekFromBottom(condition)){
600            boolean flagOfSecondIterator = fileIterator != null ? fileIterator.seekFromBottom(condition) : false;
601            if(!flagOfSecondIterator)
602                return false;
603            Object JavaDoc key = ((_Key)fileIterator.getKey()).getKeyValue();
604            Object JavaDoc keyToLocate = getKeyToLocate(key,condition);
605            ((_IndexIteratorInfo)memoryIterator).locateKey(keyToLocate,false);
606        }
607        else {
608            Object JavaDoc key = ((_Key)memoryIterator.getKey()).getKeyValue();
609            Object JavaDoc keyToLocate = getKeyToLocate(key,condition);
610            ((_IndexIteratorInfo)fileIterator).locateKey(keyToLocate,false);
611        }
612        setHighestKey();
613        status = VALIDSTATE;
614        return true;
615    }
616
617    public _KeyColumnInformation[] getKeyColumnInformations() throws DException {
618          try{
619              return fileIterator.getKeyColumnInformations() ;
620          }
621          catch(NullPointerException JavaDoc npe){
622              return memoryIterator.getKeyColumnInformations() ;
623          }
624      }
625
626      public boolean seek(Object JavaDoc indexKey) throws DException {
627          recordLoaded = false;
628          if(!memoryIterator.seek(indexKey)){
629              boolean flagOfSecondIterator = fileIterator != null ? fileIterator.seek(indexKey) : false;
630              if(!flagOfSecondIterator)
631                  return false;
632              ((_IndexIteratorInfo)memoryIterator).locateKey(indexKey,true);
633          }
634          else if(fileIterator != null)
635              ((_IndexIteratorInfo)fileIterator).locateKey(indexKey,true);
636          setLowestKey();
637          status = VALIDSTATE;
638          return true;
639      }
640
641      public boolean seekFromTop(_IndexPredicate[] condition) throws DException {
642          recordLoaded = false;
643          if(!memoryIterator.seekFromTop(condition)){
644              boolean flagOfSecondIterator = fileIterator != null ? fileIterator.seekFromTop(condition) : false;
645              if(!flagOfSecondIterator)
646                  return false;
647              Object JavaDoc key = ((_Key)fileIterator.getKey()).getKeyValue();
648              Object JavaDoc keyToLocate = getKeyToLocate(key,condition);
649              ((_IndexIteratorInfo)memoryIterator).locateKey(keyToLocate,true);
650          }
651          else if(fileIterator != null){
652              Object JavaDoc key = ((_Key)memoryIterator.getKey()).getKeyValue();
653              Object JavaDoc keyToLocate = getKeyToLocate(key,condition);
654              ((_IndexIteratorInfo)fileIterator).locateKey(keyToLocate,true);
655          }
656          setLowestKey();
657          status = VALIDSTATE;
658          return true;
659      }
660
661      public void ensureRecordInMemory() throws DException{
662          UnionKey key = (UnionKey)currentKey;
663          if(key.getBitSet().get(1) && !key.getBitSet().get(0)){
664             Object JavaDoc indexKey = key.getKeyValue();
665            if(sessionVersionHandler.recordFound(memoryIterator,fileIterator,indexKey, comparator)){
666                ((_IndexIteratorInfo)fileIterator).locateKey(indexKey,true);
667                setLowestKey();
668                status = VALIDSTATE;
669             }
670          }
671          recordLoaded = false;
672      }
673
674      public void setFieldsValue(int[] columns, FieldBase[] values) throws DException {
675          if(status != VALIDSTATE)
676              throw new DException("DSE2019",new Object JavaDoc[] {new Integer JavaDoc(status)});
677          BitSet bitSet = ((UnionKey)currentKey).getBitSet();
678          for(int i = 0 ; i < LENGTH ; i++){
679              if(bitSet.get(i)){
680                  iterators[i].setFieldsValue(columns,values);
681                  return;
682              }
683          }
684      }
685
686      public void setFieldValue(int column, FieldBase value) throws DException {
687          if(status != VALIDSTATE)
688              throw new DException("DSE2019",new Object JavaDoc[] {new Integer JavaDoc(status)});
689          BitSet bitSet = ((UnionKey)currentKey).getBitSet();
690          for(int i = 0 ; i < LENGTH ; i++){
691              if(bitSet.get(i)){
692                  iterators[i].setFieldValue(column,value);
693                  return;
694              }
695          }
696      }
697
698      public boolean locateKey(Object JavaDoc key, boolean top) throws DException {
699           recordLoaded = false;
700           _Key[] keys = new _Key[LENGTH];
701           int num = 0;
702           for (int i = 0; i < LENGTH ; i++) {
703               if(((_IndexIteratorInfo)iterators[i]).locateKey(key,top)){
704                   keys[i] = (_Key)iterators[i].getKey();
705                   num++;
706               }
707           }
708           return num == 0 ? setKeyAndStatus(top ? AFTERLAST : BEFOREFIRST,null,false)
709                       : setKeyAndStatus(VALIDSTATE,new UnionKey(getLowestKey(keys),keys,top),true);
710       }
711
712       public boolean seekKeyAddress(Object JavaDoc parm1) throws com.daffodilwoods.database.resource.DException {
713            BitSet bitSet = ((UnionKey)currentKey).getBitSet();
714            for(int i = 0 ; i < iterators.length ; i++)
715                if(bitSet.get(i))
716                    return ((_IndexIteratorInfo)iterators[i]).seekKeyAddress(parm1);
717            return false;
718        }
719
720        public Object JavaDoc getPhysicalAddress() throws com.daffodilwoods.database.resource.DException {
721            BitSet bitSet = ((UnionKey)currentKey).getBitSet();
722            for(int i = 0 ; i < iterators.length ; i++)
723                if(bitSet.get(i))
724                    return ((_IndexIteratorInfo)iterators[i]).getPhysicalAddress();
725            return null;
726        }
727
728        public SuperComparator getObjectComparator() throws DException{
729              return getComparator();
730          }
731
732          public SuperComparator getComparator() {
733         return comparator;
734     }
735     public void deleteBlobClobRecord(_DatabaseUser user) throws DException {
736         throw new UnsupportedOperationException JavaDoc("method deleteBlobClobRecord not supported ");
737       }
738
739
740
741 }
742
Popular Tags