KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > fulltext > dql > iterator > Rank2FTIterator


1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.iterator;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator;
5 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass;
6 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
7 import com.daffodilwoods.database.utility.*;
8 import com.daffodilwoods.daffodildb.utils.field.FieldBase;
9
10 /**
11  * This class handles the navigation of the rows that are returned by applying
12  * the RANK TWO RETRIEVAL CONDITION i.e. ALL WORDS + SAME SEQUENCE + GAP<>ZERO
13  * All commonly used navigation methods are implemented in its super class i.e.
14  * <B>RankAbstractNavigation</B>. This Class overrides the Rank2 specific
15  * checking of the locations of the all the parsed words in search criterion.
16  * <p>Title: Rank2FTIterator</p>
17  * <p>Description: </p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author not attributable
21  * @version 1.0
22  */

23
24 public class Rank2FTIterator extends RankSuccesiveLocation {
25
26   public Rank2FTIterator(_Iterator[] fullTextIndex0, _Iterator[] locationIndex0,_Reference[] fpkReference0,FieldBase[] keyWords0) throws DException {
27     fullTextIndex = fullTextIndex0;
28     locationIndex = locationIndex0;
29     pkColumn = GeneralPurposeStaticClass.getColumnDetails("pk");
30     documentIdColumn = GeneralPurposeStaticClass.getColumnDetails("documentId");
31     locationColumn = GeneralPurposeStaticClass.getColumnDetails("location");
32     fpkReference = fpkReference0;
33     keyWords =keyWords0;
34   }
35
36   /**
37    * This method is called when iterator's first and next methods are called.
38    * Checks, all the words must be included in the document must be in the
39    * same sequence as that of search string with increasing and not successive
40    * locations.
41    * @return
42    * @throws DException
43    */

44   public boolean alignLocationForward() throws DException {
45     Object JavaDoc[] fpkValues = setValues();
46     setLocationIteratorsForward();
47     Object JavaDoc value = locationIndex[0].getColumnValues(locationColumn);
48       Object JavaDoc oldValue = value;
49       boolean areSuccesive = true;
50       for(int ii = 1 ; ii < locationIndex.length; ii++){
51         boolean flag = locationIndex[ii].seekFromTopRelative(new Object JavaDoc[] {fpkValues[ii], value});
52         if(!flag)
53           return false;
54         value = locationIndex[ii].getColumnValues(locationColumn);
55         if( compare(value,oldValue) > 1)
56           areSuccesive = false;
57       }
58       if(areSuccesive)
59         return false;
60       return !alignSuccesiveLocationForward(fpkValues, locationIndex.length -1);
61   }
62
63   /**
64    * This method is called when iterator's last and previous methods are called.
65    * Checks, all the words must be included in the documentmust be in the
66    * same sequence as that of search string with increasing and not successive
67    * locations.
68    * @return
69    * @throws DException
70    */

71   public boolean alignLocationBackward() throws DException {
72     Object JavaDoc[] fpkValues = setValues();
73     setLocationIteratorsBackward();
74     int length = locationIndex.length;
75     Object JavaDoc value = locationIndex[length-1]
76         .getColumnValues(locationColumn);
77       Object JavaDoc oldValue = value;
78       boolean isSuccessive = true;
79       for(int ii = length-2 ; ii >= 0; ii--){
80         if(!locationIndex[ii].seekFromBottomRelative(new Object JavaDoc[] {fpkValues[ii], value}))
81           return false;
82         value = locationIndex[ii].getColumnValues(locationColumn);
83         if( compare(oldValue,value) > 1)
84           isSuccessive = false;
85       }
86       if(isSuccessive)
87         return false;
88       return !alignSuccesiveLocationBackward(fpkValues, length -1);
89   }
90
91   /**
92    * This method handles the navigation while moving downwards. This method
93    * alignes first token iterator at their corresponding first record and
94    * makes a provision for all the remaining iterators to set them before first.
95    * @throws DException if first location iterator has no record
96    * i.e. impossible case
97    */

98   private void setLocationIteratorsForward() throws DException {
99     if(!locationIndex[0].first())
100       throw new DException("DSE0", new Object JavaDoc[]{"Illegal happening"});
101     for (int i = 1; i < locationIndex.length; i++) { // To avoid problem of mixed fetching calling after last
102
if(locationIndex[i].first())
103           locationIndex[i].previous();
104     }
105   }
106
107   /**
108    * This method handles the navigation while moving upwards. This method
109    * alignes first token iterator at their corresponding last record and
110    * makes a provision for all the remaining iterators to set them after last.
111    * @throws DException if last location iterator have no record
112    * i.e. impossible case
113    */

114   private void setLocationIteratorsBackward() throws com.daffodilwoods.database.resource.DException{
115     int length = locationIndex.length;
116     if(!locationIndex[length-1].last())
117       throw new DException("DSE0", new Object JavaDoc[]{"Illegal happening"});
118     for (int i = length - 2 ; i >= 0; i--) {// To avoid problem of mixed fetching calling before first
119
if(locationIndex[i].last())
120           locationIndex[i].next();
121     }
122   }
123
124   public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{
125       }
126
127   public String JavaDoc toString(){
128       String JavaDoc str = "Rank2FTIterator";
129       str += "[FullTextIndex"+fullTextIndex[0]
130           + "][locationIndex"+locationIndex[0]
131           +"]";
132       return str;
133   }
134 }
135
Popular Tags