KickJava   Java API By Example, From Geeks To Geeks.

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


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.iterator._Iterator;
5 import com.daffodilwoods.database.sqlinitiator._Order;
6 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
7 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass;
8 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
9 import com.daffodilwoods.daffodildb.utils.comparator.CKpjoDpnqbsbups;
10 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
11 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set.IntersectDistinctIterator;
12 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes;
13
14 /**
15  * This class represents a plan ,which is generated when search pattern is
16  * combination of two search pattern combined with logical AND operator and
17  * underlying plan's resultset are not able to give documents in sorted order.
18  * It provides functionality to get resultset in which all search patterns are
19  * present and resultant documents are in sorted order.
20  * <p>Title: </p>
21  * <p>Description: </p>
22  * <p>Copyright: Copyright (c) 2003</p>
23  * <p>Company: </p>
24  * @author not attributable
25  * @version 1.0
26  */

27
28 public class AllKeyWordSortedPredicate implements _FullTextPredicate {
29   /**
30    * This represents plan of first search pattern.
31    */

32   _FullTextPredicate leftPredicate;
33   /**
34    * This represents plan of second search pattern.
35    */

36   _FullTextPredicate rightPredicate;
37   /**
38    * columnName against which search pattern is searched
39    */

40   String JavaDoc columnName;
41   _Order order;
42
43   public AllKeyWordSortedPredicate(_FullTextPredicate leftPredicate0,
44                                    _FullTextPredicate rightPredicate0) {
45     leftPredicate = leftPredicate0;
46     rightPredicate = rightPredicate0;
47   }
48
49   /**
50    * This method is used to get type of plan which is required by planmerger to
51    * merged two plan either with Logically AND and OR Operator.
52    * @return type of plan
53    * @throws DException
54    */

55   public int getType() throws DException {
56     return PredicateConstant.allKeyWordSortedPredicate;
57   }
58
59   /**
60    * It is required to get columnName of searched column against which search
61    * pattern is searched.
62    * @return columnName
63    * @throws DException
64    */

65   public String JavaDoc getColumn() throws DException {
66     columnName = leftPredicate.getColumn();
67     return columnName;
68   }
69
70   /**
71    * It is used to set columnName of searched column against which search
72    * pattern is searched.
73    * @param colName
74    * @throws DException
75    */

76   public void setColumn(String JavaDoc colName) throws DException {
77     leftPredicate.setColumn(colName);
78     rightPredicate.setColumn(colName);
79   }
80
81   public double getCost() throws DException {
82     return 0.0;
83   }
84
85   public double getCost(Object JavaDoc session) throws DException {
86     return 0.0;
87   }
88   /**
89    * It provides functionality of plan execution which gives resultset. Resultset
90    * contains documents which are common in underlying resultset.
91    * @param session
92    * @return _Iterator
93    * @throws DException
94    */

95   public _Iterator execute(Object JavaDoc session) throws DException {
96     _Iterator leftIterator = leftPredicate.executeForSortedResult(session);
97     _Iterator rightIterator = rightPredicate.executeForSortedResult(session);
98     return getIntersectDistinctIterator(leftIterator, rightIterator);
99   }
100   /**
101    * It is required to get resultant resultset which contains common record of
102    * underlying resultset.
103    * @param leftIterator
104    * @param rightIterator
105    * @return _Iterator
106    * @throws DException
107    */

108   private _Iterator getIntersectDistinctIterator(_Iterator leftIterator,
109                                                  _Iterator rightIterator) throws
110       DException {
111     _Reference[] leftReferences = new _Reference[] {
112         GeneralPurposeStaticClass.getColumnDetails("documentId")};
113     _Reference[] rightReferences = new _Reference[] {
114         GeneralPurposeStaticClass.getColumnDetails("documentId")};
115     SuperComparator comparator = new CKpjoDpnqbsbups(new SuperComparator[] {
116         GetByteComparator.getComparator(Datatypes.LONG, true, null)});
117     _Reference[] orderLeftColumnDetails = new _Reference[] {
118         GeneralPurposeStaticClass.getColumnDetails("documentId")};
119     _Reference[] orderRightColumnDetails = new _Reference[] {
120         GeneralPurposeStaticClass.getColumnDetails("documentId")};
121     return new IntersectDistinctIterator(leftIterator, rightIterator,
122                                          leftReferences, rightReferences,
123                                          comparator, orderLeftColumnDetails,
124                                          orderRightColumnDetails);
125   }
126
127   public double getEstimatedRow() throws DException {
128     return 1;
129   }
130
131   public void setOrder(_Order order0) throws DException {
132     this.order = order0;
133   }
134
135   public _Order getOrder() throws DException {
136     return order;
137   }
138
139   /**
140    * It provides functionality of plan execution which gives resultset. Resultset
141    * contains documents which are common in underlying resultset.
142    * @param session
143    * @return _Iterator
144    * @throws DException
145    */

146   public _Iterator executeForSortedResult(Object JavaDoc indexTable) throws DException {
147     return execute(indexTable);
148   }
149
150 }
151
Popular Tags