KickJava   Java API By Example, From Geeks To Geeks.

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


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.dql.iterator.set.IntersectAllIterator;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.set.IntersectDistinctIterator;
8 import com.daffodilwoods.daffodildb.utils.GetByteComparator;
9 import com.daffodilwoods.daffodildb.server.sql99.utils._Reference;
10 import com.daffodilwoods.daffodildb.server.sql99.common.GeneralPurposeStaticClass;
11 import com.daffodilwoods.daffodildb.server.sql99.common.Datatypes;
12 import com.daffodilwoods.daffodildb.utils.comparator.SuperComparator;
13 import com.daffodilwoods.daffodildb.utils.comparator.CKpjoDpnqbsbups;
14
15 /**
16  * This class represents plan which generated when search pattern is combination
17  * of two search pattern combined with logical AND operator.It provides functionality
18  * to get resultset on execution of plan.plan generated will not be optimized.
19  * optimized plan:-plan is optimized if it will provide resultset based on
20  * Rank iterator.so in this,Resultset gives common record of underlying two
21  * resultset.
22  * <p>Title: </p>
23  * <p>Description: </p>
24  * <p>Copyright: Copyright (c) 2003</p>
25  * <p>Company: </p>
26  * @author not attributable
27  * @version 1.0
28  */

29
30 public class AndFullTextPredicate implements _FullTextPredicate {
31    /**
32     * This represents plan of first serach pattern.
33     */

34    _FullTextPredicate leftPredicate ;
35    /**
36     * This represents paln of second search pattern.
37     */

38    _FullTextPredicate rightPredicate ;
39    /**
40     * columnName against which search pattern is searched
41     */

42    String JavaDoc columnName;
43    _Order order;
44
45    public AndFullTextPredicate(_FullTextPredicate leftPredicate,_FullTextPredicate rightPredicate) {
46       this.leftPredicate = leftPredicate;
47       this.rightPredicate = rightPredicate;
48    }
49    /**
50     * This method is used to get type of plan which is required plan merger to merged
51     * 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.andFullTextPredicate;
57    }
58    /**
59     * It is required to get columnName of searched column against which search
60     * pattern is searched.
61     * @return columnName
62     * @throws DException
63     */

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

74    public void setColumn(String JavaDoc colName) throws DException{
75       leftPredicate.setColumn(colName);
76       rightPredicate.setColumn(colName);
77    }
78    public double getCost() throws DException {
79       return 0.0;
80    }
81    public double getCost(Object JavaDoc session) throws DException {
82       return 0.0;
83    }
84    /**
85     * It allows for execution of plan,which gives a resultset.ResultSet used for
86     * navigating records.Resultset contains records which is common in
87     * underlying resultset.
88     * @param session
89     * @return _Iterator
90     * @throws DException
91     */

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

106    private _Iterator getIntersectDistinctIterator(_Iterator leftIterator,_Iterator rightIterator) throws DException{
107       _Reference[] leftReferences = new _Reference[]{GeneralPurposeStaticClass.getColumnDetails("documentId")};
108       _Reference[] rightReferences = new _Reference[]{GeneralPurposeStaticClass.getColumnDetails("documentId")};
109       SuperComparator comparator = GetByteComparator.getComparator(Datatypes.LONG,true,null);
110       CKpjoDpnqbsbups joinComparator = new CKpjoDpnqbsbups(new SuperComparator[]{comparator});
111       _Reference[] orderLeftColumnDetails = new _Reference[]{GeneralPurposeStaticClass.getColumnDetails("documentId")};
112       _Reference[] orderRightColumnDetails = new _Reference[]{GeneralPurposeStaticClass.getColumnDetails("documentId")};
113       return new IntersectDistinctIterator(leftIterator,rightIterator,leftReferences,rightReferences,joinComparator,orderLeftColumnDetails,orderRightColumnDetails);
114    }
115
116    public double getEstimatedRow() throws DException {
117       return 1;
118    }
119    public void setOrder(_Order order) throws DException {
120       this.order = order;
121    }
122    public _Order getOrder() throws DException {
123       return order;
124    }
125
126    /**
127     * It allows for execution of plan,which gives a resultset.ResultSet used for
128     * navigating records.Resultset contains records which is common in
129     * underlying resultset.
130     * @param session
131     * @return _Iterator
132     * @throws DException
133     */

134    public _Iterator executeForSortedResult(Object JavaDoc indexTable) throws DException{
135       return execute(indexTable);
136    }
137
138 }
139
Popular Tags