KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

47   public boolean alignLocationForward() throws DException {
48     Object JavaDoc[] fpkValues = setValues();
49     setLocationIteratorsForward();
50     Object JavaDoc value = locationIndex[0].getColumnValues(locationColumn);
51     int startIndex = 0;
52     boolean aligned = true;
53     for (int i = 1; i < locationIndex.length; i++) {
54       Object JavaDoc nValue = locationIndex[i].getColumnValues(locationColumn);
55       int cmp = compare(nValue, value);
56       if (cmp > (i-startIndex)) {
57         startIndex = i;
58         value = nValue;
59       }
60       else if (cmp < (i-startIndex)) {
61         aligned = false;
62       }
63     }
64     if (aligned && startIndex == 0)
65       return true;
66     return alignSuccesiveLocationForward(fpkValues,startIndex);
67   }
68
69   /**
70    * This method is called when iterator's last and previous methods are called.
71    * Checks, all the words must be included in the document and must be in the
72    * same sequence as that of search string with successive locations.
73    * @return true if locations are aligned, false otherwise.
74    * @throws DException
75    */

76   public boolean alignLocationBackward() throws DException {
77     Object JavaDoc[] fpkValues = setValues();
78     setLocationIteratorsBackward();
79     int length = locationIndex.length;
80     Object JavaDoc value = locationIndex[length-1].getColumnValues(locationColumn);
81     int startIndex = length-1;
82     boolean aligned = true;
83     for (int i = length-2; i >= 0; i--) {
84       Object JavaDoc nValue = locationIndex[i].getColumnValues(locationColumn);
85       int cmp = compare(nValue, value);
86       if (cmp > (i-startIndex)) {
87         aligned = false;
88       }
89       else if (cmp < (i-startIndex)){
90         startIndex = i;
91         value = nValue;
92       }
93     }
94     if (aligned && startIndex == length-1)
95       return true;
96     return alignSuccesiveLocationBackward(fpkValues,startIndex);
97   }
98
99   /**
100    * This method handles the navigation while moving upwards. This method
101    * alignes all the token iterators at their corresponding first record.
102    * @throws DException if location iterator have no last record
103    * i.e. impossible case
104    */

105   private void setLocationIteratorsForward() throws DException {
106     for (int i = 0; i < locationIndex.length; i++) {
107       if(!locationIndex[i].first())
108         throw new DException("DSE0", new Object JavaDoc[]{"Illegal happening"});
109     }
110   }
111
112   /**
113    * This method handles the navigation while moving downwards. This method
114    * alignes all the token iterators at their corresponding last record.
115    * @throws DException if location iterator have no last record
116    * i.e. impossible case
117    */

118   private void setLocationIteratorsBackward() throws DException{
119     for (int i = 0; i < locationIndex.length; i++) {
120       if(!locationIndex[i].last())
121         throw new DException("DSE0", new Object JavaDoc[]{"Illegal happening"});
122     }
123   }
124
125   public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{
126       }
127
128   public String JavaDoc toString(){
129       String JavaDoc str = "Rank1FTIterator";
130       str += "[FullTextIndex"+fullTextIndex[0]
131           + "][locationIndex"+locationIndex[0]
132           +"]";
133       return str;
134   }
135 }
136
Popular Tags