KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > fulltext > dql > condition > NotFullTextPredicate


1 package com.daffodilwoods.daffodildb.server.sql99.fulltext.dql.condition;
2
3 import com.daffodilwoods.database.resource.DException;
4 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition._AllColumnPredicates;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator._Iterator;
6 import com.daffodilwoods.daffodildb.server.sql99.fulltext.dml._FullTextIndexInformation;
7 import com.daffodilwoods.database.sqlinitiator._Order;
8 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._IndexTable;
9 import com.daffodilwoods.daffodildb.server.datadictionarysystem.information._IndexInformation;
10 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set.ExceptAllIterator;
11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set.ExceptDistinctIterator;
12 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
13 import com.daffodilwoods.daffodildb.server.sql99.common.ColumnDetails;
14 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes;
15 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.ByteComparator;
16 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
17 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
18 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass;
19 import com.daffodilwoods.daffodildb.utils.comparator.CKpjoDpnqbsbups;
20
21 /**
22  * This class represents plan which is generated when attribute NOT is appended
23  * in front of search pattern.It provides functionality to get ResultSet which
24  * provides those documents in which that serach pattern is not present.
25  * <p>Title: </p>
26  * <p>Description: </p>
27  * <p>Copyright: Copyright (c) 2003</p>
28  * <p>Company: </p>
29  * @author not attributable
30  * @version 1.0
31  */

32
33 public class NotFullTextPredicate
34     implements _FullTextPredicate {
35
36   _FullTextPredicate fullTextPredicate;
37   String JavaDoc columnName;
38   private _Order order;
39
40   public NotFullTextPredicate(_FullTextPredicate fullTextPredicate0) {
41     fullTextPredicate = fullTextPredicate0;
42   }
43
44   /**
45    * This method is used to get type of plan which is required to merged two
46    * plan either with Logically AND and OR Operator.
47    * @return type of plan
48    * @throws DException
49    */

50   public int getType() throws DException {
51     return PredicateConstant.notFullTextPredicate;
52   }
53
54   /**
55    * It is required to get columnName of searched column against which search
56    * pattern is searched.
57    * @return columnName
58    * @throws DException
59    */

60   public String JavaDoc getColumn() throws DException {
61     return columnName;
62   }
63
64   /**
65    * It is used to set columnName of searched column against which search
66    * pattern is searched.
67    * @param colName
68    * @throws DException
69    */

70   public void setColumn(String JavaDoc colName) throws DException {
71     fullTextPredicate.setColumn(colName);
72     columnName = colName;
73   }
74
75   /**
76    * It provides functionality of plan execution which gives resultset.
77    * Resultset provides all documents except those in which search pattern is
78    * present.
79    * @param session
80    * @return
81    * @throws DException
82    */

83   public _Iterator execute(Object JavaDoc session) throws DException {
84     _FullTextIndexInformation[] fullTextIndexInfo = ( (_IndexTable) session).
85         getFullTextIndexInformation();
86     _Iterator iter = fullTextPredicate.executeForSortedResult(session); //iter = fullTextPredicate.execute(session);
87
for (int i = 0; i < fullTextIndexInfo.length; i++) {
88     String JavaDoc[] columnNames = fullTextIndexInfo[i].getColumnName();
89     if ((columnName.equalsIgnoreCase(fullTextIndexInfo[i].getIndexName()))
90         || (columnNames.length ==1 &&
91             (columnName.equalsIgnoreCase(columnNames[0])))){
92         _Iterator tokenIterator = getTokenIterator(fullTextIndexInfo[i],
93             session);
94         return getExceptIterator(tokenIterator, iter);
95       }
96     }
97     throw new DException("DSE0", new Object JavaDoc[] {"Invalid ColumnName - " + columnName});
98   }
99
100   /**
101    * It is required to get Resultset,which provides all documents except those in
102    * which serach pattern is present.
103    * @param tokenIterator
104    * @param underlyingIterator
105    * @return _Iterator
106    * @throws DException
107    */

108   private _Iterator getExceptIterator(_Iterator tokenIterator,
109                                       _Iterator underlyingIterator) throws
110       DException {
111     _Reference[] leftReferences = new _Reference[] {
112         GeneralPurposeStaticClass.getColumnDetails("documentId")};
113     _Reference[] rightReferences = new _Reference[] {
114         GeneralPurposeStaticClass.getColumnDetails("documentId")};
115     SuperComparator comparator = GetByteComparator.getComparator(Datatypes.LONG, true, null);
116     CKpjoDpnqbsbups joincomparator = new CKpjoDpnqbsbups(new SuperComparator[] {
117         comparator});
118     _Reference[] orderLeftColumnDetails = new _Reference[] {
119         GeneralPurposeStaticClass.getColumnDetails("documentId")};
120     _Reference[] orderRightColumnDetails = new _Reference[] {
121         GeneralPurposeStaticClass.getColumnDetails("documentId")};
122     return new ExceptDistinctIterator(tokenIterator, underlyingIterator,
123                                       leftReferences, rightReferences,
124                                       joincomparator, orderLeftColumnDetails,
125                                       orderRightColumnDetails, joincomparator,
126                                       joincomparator);
127   }
128
129   /**
130    * It is required to get Resultset on token table. which provide all documents.
131    * @param fullTextIndexInfo
132    * @param session
133    * @return
134    * @throws DException
135    */

136   private _Iterator getTokenIterator(_FullTextIndexInformation fullTextIndexInfo,
137                                     Object JavaDoc session) throws DException {
138     _IndexTable token = (_IndexTable) ( (_IndexTable) session).getDatabase().
139         getTable(fullTextIndexInfo.getTokenTableName());
140     com.daffodilwoods.daffodildb.server.datasystem.indexsystem.
141
        _IndexInformation[] indexInfo = token.getIndexInformations();
142     for (int i = 0; i < indexInfo.length; i++) {
143       String JavaDoc[] cName = indexInfo[i].getColumns();
144       if (cName[0].equalsIgnoreCase("documentId")) { // use static constant
145
return token.getIterator(i);
146       }
147     }
148     throw new DException("DSE0",
149                          new Object JavaDoc[] {"Invalid FullTextIndex - " + fullTextIndexInfo});
150   }
151
152   public double getCost() throws DException {
153     return 0.0;
154   }
155
156   public double getCost(Object JavaDoc session) throws DException {
157     return 0.0;
158   }
159
160   public double getEstimatedRow() throws DException {
161     return 1;
162   }
163
164   public void setOrder(_Order order) throws DException {
165     this.order = order;
166   }
167
168   public _Order getOrder() throws DException {
169     return order;
170   }
171
172   /**
173    * This method required to get Resultset which contains those documents in which
174    * search pattern is present.
175    * @param session
176    * @return _Iterator
177    * @usage OptimizedNotPredicate.
178    * @throws DException
179    */

180   public _Iterator getWordIterator(Object JavaDoc session) throws DException {
181     return fullTextPredicate.execute(session);
182   }
183
184   /**
185    * It is required to get ResultSet which provide documents in which search
186    * pattern is not present.
187    * @param indexTable
188    * @return
189    * @throws DException
190    */

191   public _Iterator executeForSortedResult(Object JavaDoc indexTable) throws DException {
192     return execute(indexTable);
193   }
194
195 }
196
Popular Tags