KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql99.utils._Reference;
6 import com.daffodilwoods.database.utility.*;
7 import com.daffodilwoods.daffodildb.utils.field.*;
8 import com.daffodilwoods.daffodildb.utils.*;
9 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
10
11 /**
12  * <p>Title: RankSuccesiveLocation</p>
13  * <p>Description: The purpose of this Class to find out a sequence of successive
14  * locations during navigation of Rank1 and Rank2 iterators. For Rank-1 : If a
15  * record with successive location is found, record is retruned.
16  * For Rank2 : This class is used to skip a record that have the given search
17  * criterion in succesive locations.</p>
18  * <p>Copyright: Copyright (c) 2003</p>
19  * <p>Company: </p>
20  * @author not attributable
21  * @version 1.0
22  */

23
24 public abstract class RankSuccesiveLocation extends RankAbstractNavigation {
25
26   /**
27    * This method is called when iterator's first and next methods are called.
28    * Checks, all the words must be included in the document and must be in the
29    * same sequence as that of search string with successive locations.
30    * @return true if a record having parsed words in succesive locations are
31    * found, false otherwise.
32    * @throws DException
33    */

34   public boolean alignSuccesiveLocationForward(Object JavaDoc[] fpkValues, int startIndex) throws DException {
35     Object JavaDoc value = locationIndex[startIndex].getColumnValues(locationColumn);
36     int satisfied;
37     do {
38       satisfied = 0;
39       for (int i = 0; i < locationIndex.length; i++) {
40         if (i == startIndex) {
41           satisfied++;
42           continue;
43         }
44         Object JavaDoc cValue = locationIndex[i].getColumnValues(locationColumn);
45         int cmp = compare(cValue, value);
46         if (cmp == i - startIndex) {
47           satisfied++;
48         }
49         else if (cmp > i - startIndex) {
50           startIndex = i;
51           satisfied = 1;
52           value = cValue;
53           break;
54         }
55         else {
56           long longVal = ( (Long JavaDoc) ( (FieldLong) value).getObject()).longValue() +
57               (i - startIndex);
58           FieldBase val = FieldUtility.getField(Datatype.LONG, new Long JavaDoc(longVal));
59           if (!locationIndex[i].seekFromTopRelative(new Object JavaDoc[] {fpkValues[i], val})) {
60             return false;
61           }
62           cValue = locationIndex[i].getColumnValues(locationColumn);
63           cmp = compare(cValue, value);
64           if (cmp == i - startIndex)
65             satisfied++;
66           else {
67             startIndex = i;
68             satisfied = 1;
69             value = cValue;
70             break;
71           }
72         }
73       }
74       if(satisfied == locationIndex.length)
75         return true;
76     }while (true);
77   }
78
79   /**
80    * This method is called when iterator's last and previous methods are called.
81    * Checks, all the words must be included in the document and must be in the
82    * same sequence as that of search string with successive locations.
83    * @return true if a record having parsed words in succesive locations are
84    * found, false otherwise.
85    * @throws DException
86    */

87   public boolean alignSuccesiveLocationBackward(Object JavaDoc[] fpkValues, int startIndex) throws DException {
88     Object JavaDoc value = locationIndex[startIndex].getColumnValues(locationColumn);
89     int satisfied;
90     do {
91       satisfied = 0;
92       for (int i = locationIndex.length-1 ; i >= 0 ; i--) {
93         if (i == startIndex) {
94           satisfied++;
95           continue;
96         }
97         Object JavaDoc cValue = locationIndex[i].getColumnValues(locationColumn);
98         int cmp = compare(cValue, value);
99         if (cmp == i - startIndex) {
100           satisfied++;
101         }
102         else if (cmp < i - startIndex) {
103           startIndex = i;
104           satisfied = 1;
105           value = cValue;
106           break;
107         }
108         else {
109           long longVal = ( (Long JavaDoc) ( (FieldLong) value).getObject()).longValue() +
110               (i - startIndex);
111           FieldBase val = FieldUtility.getField(Datatype.LONG, new Long JavaDoc(longVal));
112           if (!locationIndex[i].seekFromBottomRelative(new Object JavaDoc[] {fpkValues[i], val})) {
113             return false;
114           }
115           cValue = locationIndex[i].getColumnValues(locationColumn);
116           cmp = compare(cValue, value);
117           if (cmp == i - startIndex)
118             satisfied++;
119           else {
120             startIndex = i;
121             satisfied = 1;
122             value = cValue;
123             break;
124           }
125         }
126       }
127       if(satisfied == locationIndex.length)
128         return true;
129     }while (true);
130   }
131 }
132
Popular Tags