KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > plan > condition > RangePredicate


1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition;
2
3 import com.daffodilwoods.daffodildb.server.sql99.common.*;
4 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
5 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*;
6 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
7 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
8 import com.daffodilwoods.database.resource.*;
9
10 /**
11  * This class represents predicate of like A<10 and A>20.usage of this predicate
12  * are in TablePlanMerger when single column predicate are merged.this predicate
13  * are made when one is of type lessthan or lessthanequalto and other is of type
14  * greater than and greaterthanequalto.
15  * Title:
16  * Description:
17  * Copyright: Copyright (c) 2002
18  * Company:
19  * @author
20  * @version 1.0
21  */

22 public class RangePredicate extends PredicateAbstract implements booleanvalueexpression, predicate {
23   /**
24    * It represents predicate of type lessthan or lessthanequalto
25    * e.g a<10,a<=10
26    */

27   public predicate topPredicate;
28   /**
29    * It represents predicate of type greater than or greaterthanequalto.
30    */

31   public predicate bottomPredicate; // a >2 , a >=2
32

33    public RangePredicate(predicate topPredicate1, predicate bottomPredicate1) {
34       bottomPredicate = bottomPredicate1;
35       topPredicate = topPredicate1;
36    }
37    /**
38     * This method is used to getbottompredicate
39     * @return
40     * @throws DException
41     */

42    public predicate getBottomPredicate() throws DException {
43       return bottomPredicate;
44    }
45    /**
46     * This method is used to get TopPredicate.
47     * @return
48     * @throws DException
49     */

50    public predicate getTopPredicate() throws DException {
51       return topPredicate;
52    }
53
54    public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws DException {
55       throw new DException("DSE565", new Object JavaDoc[] {"execute()"});
56    }
57
58    public ParameterInfo[] getParameterInfo() throws DException {
59       throw new DException("DSE565", new Object JavaDoc[] {"getParameterInfo()"});
60    }
61    public com.daffodilwoods.daffodildb.server.sql99.utils._Reference[] checkSemantic(com.daffodilwoods.daffodildb.server.serversystem._ServerSession parent) throws DException {
62       throw new DException("DSE565", new Object JavaDoc[] {"checkSemantic(queryspecification parent)"});
63    }
64
65    public Object JavaDoc run(Object JavaDoc object) throws DException {
66       Object JavaDoc cmp = bottomPredicate.run(object);
67       if (cmp.hashCode() == 0) {
68          Object JavaDoc o = topPredicate.run(object);
69          return o;
70       }
71       return cmp;
72    }
73
74    public String JavaDoc toString() {
75       return bottomPredicate + " AND " + topPredicate;
76    }
77    /**
78     * Computes Cost of solving predicate for rows passed, boolean is passed to
79     * indicate whether predicate is solvable by index or not.
80     */

81    public double getCost(long rowCount, boolean index) throws DException {
82       long rowsReduced = topPredicate.getEstimatedRows(rowCount);
83       rowsReduced = bottomPredicate.getEstimatedRows(rowsReduced);
84       if (index) {
85          return rowsReduced * CostFactorConstants.INDEXPREDICATE / 100;
86       }
87       return rowsReduced;
88    }
89    /**
90     * This method returns all the children of this class. It is needed in
91     * Abstract classes, so as to move common methods in Abstract class.
92     * @return
93     */

94    public AbstractRowValueExpression[] getChilds() {
95       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {};
96       return childs;
97    }
98
99    public void setDefaultValues(_VariableValueOperations variableValueOperations) throws DException {
100    }
101
102    /**
103     * This method returns the estimate number of the rows remaining after the execution
104     * of this condition on passed number of rows.
105     * @param noOfRows
106     * @return
107     * @throws DException
108     */

109
110    public long getEstimatedRows(long noOfRows) throws DException {
111       long rowCount = topPredicate.getEstimatedRows(noOfRows);
112       return bottomPredicate.getEstimatedRows(rowCount);
113    }
114    /**
115     * This method is used to get type of predicate.
116     * @return
117     * @throws DException
118     */

119
120    public int getPredicateType() throws DException {
121       return OperatorConstants.RANGE_PREDICATE;
122    }
123 }
124
Popular Tags