KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > execution > RightIndexed


1 package com.daffodilwoods.daffodildb.server.sql99.dql.execution;
2
3 import com.daffodilwoods.daffodildb.server.serversystem.*;
4 import com.daffodilwoods.daffodildb.server.sql99.common.*;
5 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
7 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
9 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
10 import com.daffodilwoods.daffodildb.utils.comparator.*;
11 import com.daffodilwoods.database.resource.*;
12 import com.daffodilwoods.database.sqlinitiator.*;
13
14 /**
15  * It represents the condition of comparison predicate when index is used on
16  * the column of right side of operator. It helps in evaluating condition from
17  * right side. e.g original condition is 5 > b then when we solve it from right
18  * side, it becomes b < 5. It is required to take the advantage of index in
19  * evaluation of this condition.
20  * <p>Title: </p>
21  * <p>Description: </p>
22  * <p>Copyright: Copyright (c) 2003</p>
23  * <p>Company: </p>
24  * @author unascribed
25  * @version 1.0
26  */

27
28 public class RightIndexed extends PredicateAbstract implements predicate, OperatorConstants, _ComparisonPredicate {
29
30    /**
31     * Represents the comparison predicate for which index is present on right
32     * hand side of operator.
33     */

34
35    comparisonpredicate bve;
36
37    /**
38     * Represents the operator of condition.
39     */

40
41    int Operator;
42
43    /**
44     * Used in comparing the values of left and right side of operator.
45     */

46
47    SuperComparator comparator;
48
49    public RightIndexed() {
50    }
51
52    /**
53     * It initializes the operator as it seems from right hand side of condition.
54     * @param bveArg
55     * @param OperatorArg
56     * @throws DException
57     */

58
59    public RightIndexed(comparisonpredicate bveArg, int OperatorArg) throws DException {
60       bve = bveArg;
61       ColumnDetails[] columnDetails1 = bve._rowvalueexpressionwithoutboolean2.getColumnDetails();
62       ColumnDetails[] columnDetails2 = bve._valueexpressionwithoutboolean0.getColumnDetails();
63       switch (OperatorArg) {
64          case LESSTHAN:
65             Operator = GREATERTHAN;
66             break;
67          case LESSTHANEQUALTO:
68             Operator = GREATERTHANEQUALTO;
69             break;
70          case GREATERTHAN:
71             Operator = LESSTHAN;
72             break;
73          case GREATERTHANEQUALTO:
74             Operator = LESSTHANEQUALTO;
75             break;
76          default:
77             Operator = OperatorArg;
78       }
79    }
80
81    /**
82     * This method returns the result of the condition when solved from right
83     * side. Firstly value of right hand side is retrieved and then value of
84     * left hand side is retrieved. After that result of right side is compared
85     * with left side based on the operator.
86     * @param object
87     * @return int, 0 represents value of right side = value of left side.
88     * -1 represents value of right side < value of left side.
89     * -2 represents value of right side is null.
90     * 1 represents value of right side > value of left side.
91     * 2 represents value of left side is null.
92     * @throws DException
93     */

94
95    public Object JavaDoc run(Object JavaDoc object) throws DException {
96       Object JavaDoc fieldBase2 = bve._rowvalueexpressionwithoutboolean2.run(object);
97       Object JavaDoc fieldBase1 = bve._valueexpressionwithoutboolean0.run(object);
98
99       _VariableValues variableValue = (_VariableValues) object;
100       int cmp;
101       try {
102          cmp = comparator.compare(fieldBase1, fieldBase2);
103       } catch (NullPointerException JavaDoc ex) {
104          ByteComparison bc1 = bve._rowvalueexpressionwithoutboolean2.getByteComparison(object);
105          ByteComparison bc2 = bve._valueexpressionwithoutboolean0.getByteComparison(object);
106          comparator = bve.getAppropriateComparator(bc1, bc2, fieldBase1, fieldBase2, null);
107          cmp = comparator.compare(fieldBase1, fieldBase2);
108       }
109       return booleanResult[Operator - 1][cmp + 2];
110    }
111
112    /**
113     * All the following methods belong to condition, so for documentation of
114     * these methods refer to documentation of booleanvalueexpression.
115     */

116
117    public String JavaDoc toString() {
118       return bve.toString();
119    }
120
121    public Object JavaDoc getValue() throws DException {
122       return bve.getValue();
123    }
124
125    public int getPredicateType() throws DException {
126       return bve.getPredicateType();
127    }
128
129    public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws DException {
130       return bve.getQualifiedBVE(tableDetails);
131    }
132
133    public double getCost(long rowCount, boolean index) throws DException {
134       return bve.getCost(rowCount, index);
135    }
136
137    public _IndexPredicateInterface getCost(_Order order, String JavaDoc[] queryColumns, Object JavaDoc session, TableDetails tableDetails) throws DException {
138       throw new UnsupportedOperationException JavaDoc("Method not supported");
139    }
140
141    public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws DException {
142       bve.setColumnPredicates(allColumnPredicates);
143    }
144
145    public ParameterInfo[] getParameterInfo() throws DException {
146       return bve.getParameterInfo();
147    }
148
149    public AbstractRowValueExpression[] getChilds() {
150       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {bve};
151       return childs;
152    }
153
154    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
155       return bve.checkSemantic(parent);
156    }
157
158    public long getEstimatedRows(long noOfRows) throws DException {
159       return bve.getEstimatedRows(noOfRows);
160    }
161
162    public int canUseForSeek() throws DException {
163       return bve.canUseForSeek();
164    }
165
166    public int getConditionType() throws com.daffodilwoods.database.resource.DException {
167       return bve.getConditionType();
168    }
169
170    public _BVEPlan getExecutionPlan() throws com.daffodilwoods.database.resource.DException {
171       return bve.getExecutionPlan();
172    }
173
174    public boolean isNullPredicate() throws DException {
175       return bve.isNullPredicate();
176    }
177
178    public void setOperator(int Type) throws DException {
179       Operator = Type;
180    }
181 }
182
Popular Tags