KickJava   Java API By Example, From Geeks To Geeks.

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


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 THREE RETRIEVAL CONDITION i.e. ALL WORDS + SEQUENCE MUST NOT BE SAME
13  * All commonly used navigation methods are implemented in its super class i.e.
14  * <B>RankAbstractNavigation</B>. This Class overrides the Rank3 specific
15  * checking of the locations of the all the parsed words in search criterion.
16  * <p>Title: Rank3FTIterator</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 Rank3FTIterator extends RankAbstractNavigation {
25
26   public Rank3FTIterator(_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 with random order
39    * provided sequence must not be same as that of search string.
40    * @return
41    * @throws DException
42    */

43   public boolean alignLocationForward() throws DException {
44     Object JavaDoc[] fpkValues = setValues();
45     setLocationIteratorsForward();
46     Object JavaDoc value = locationIndex[0].getColumnValues(locationColumn);
47     for (int ii = 1; ii < locationIndex.length; ii++) {
48         if(!locationIndex[ii].seekFromTopRelative(new Object JavaDoc[] {fpkValues[ii], value}))
49               return true;
50         value = locationIndex[ii].getColumnValues(locationColumn);
51     }
52     return false;
53   }
54   /**
55    * This method is called when iterator's last and previous methods are called.
56    * Checks, all the words must be included in the document with random order
57    * provided sequence must not be same as that of search string.
58    * @return
59    * @throws DException
60    */

61   public boolean alignLocationBackward() throws DException {
62     Object JavaDoc[] fpkValues = setValues();
63     setLocationIteratorsBackward();
64      int length = locationIndex.length;
65      Object JavaDoc value = locationIndex[length - 1].getColumnValues(locationColumn);
66      for (int ii = length - 2; ii >= 0 ; ii--) {
67          if(!locationIndex[ii].seekFromBottomRelative(new Object JavaDoc[] {fpkValues[ii], value}))
68                return true;
69          value = locationIndex[ii].getColumnValues(locationColumn);
70      }
71      return false;
72   }
73
74   /**
75    * This method handles the navigation while moving downwards. This method
76    * alignes first token iterator at their corresponding first record and
77    * makes a provision for all the remaining iterators to set them before first.
78    * @throws DException if first location iterator have no record
79    * i.e. impossible case
80    */

81   private void setLocationIteratorsForward() throws DException {
82     if(!locationIndex[0].first())
83       throw new DException("DSE0", new Object JavaDoc[]{"Illegal happening"});
84     for (int i = 1; i < locationIndex.length; i++) { // To avoid problem of mixed fetching calling after last
85
if(locationIndex[i].first())
86           locationIndex[i].previous();
87     }
88   }
89
90   /**
91    * This method handles the navigation while moving upwards. This method
92    * alignes first token iterator at their corresponding last record and
93    * makes a provision for all the remaining iterators to set them after last.
94    * @throws DException if last location iterator has no record
95    * i.e. impossible case
96    */

97   private void setLocationIteratorsBackward() throws DException{
98     int length = locationIndex.length;
99     if(!locationIndex[length-1].last())
100       throw new DException("DSE0", new Object JavaDoc[]{"Illegal happening"});
101     for (int i = length - 2 ; i >= 0; i--) {// To avoid problem of mixed fetching calling before first
102
if(locationIndex[i].last())
103           locationIndex[i].next();
104     }
105   }
106
107   public void setSpecificUnderlyingReferences(_Reference[] specificUnderlyingReferences) throws DException{
108       }
109
110   public String JavaDoc toString(){
111       String JavaDoc str = "Rank3FTIterator";
112       str += "[FullTextIndex"+fullTextIndex[0]
113           + "][locationIndex"+locationIndex[0]
114           +"]";
115       return str;
116   }
117 }
118
Popular Tags