KickJava   Java API By Example, From Geeks To Geeks.

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


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.dql.tableexpression.fromclause.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*;
9 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
10 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
11 import com.daffodilwoods.daffodildb.utils.*;
12 import com.daffodilwoods.daffodildb.utils.comparator.*;
13 import com.daffodilwoods.database.resource.*;
14 import com.daffodilwoods.database.sqlinitiator.*;
15
16 /**
17  * It represents the condition of natural join when index is used on the column
18  * of right side of operator. It helps in evaluating condition from right side.
19  * e.g original condition is 5 = b then when we solve it from right side, it
20  * becomes b = 5. It is required to take the advantage of index in evaluation of
21  * this condition.
22  * <p>Title: </p>
23  * <p>Description: </p>
24  * <p>Copyright: Copyright (c) 2003</p>
25  * <p>Company: </p>
26  * @author unascribed
27  * @version 1.0
28  */

29
30 public class NaturalRightIndexed extends PredicateAbstract implements predicate, OperatorConstants, _ComparisonPredicate {
31
32    /**
33     * Represents the condition of natural join.
34     */

35
36    NaturalJoinPredicate bve;
37
38    /**
39     * Represents the 'equals to' operator of condition.
40     */

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

47
48    SuperComparator comparator;
49
50    /**
51     * Represents the columns present in condition.
52     */

53
54    private ColumnDetails[] columns;
55
56    public NaturalRightIndexed() {
57    }
58
59    public NaturalRightIndexed(NaturalJoinPredicate bveArg, int OperatorArg) throws
60        DException {
61       bve = bveArg;
62       Operator = OperatorArg;
63       columns = bveArg.getColumnDetails();
64    }
65
66    /**
67     * This method returns the result of the condition when solved from right
68     * side. Firstly value of right hand side is retrieved and then value of
69     * left hand side is retrieved. After that result of right side is compared
70     * with left side based on the operator.
71     * @param object
72     * @return int, 0 represents value of right side = value of left side.
73     * -1 represents value of right side < value of left side.
74     * -2 represents value of right side is null.
75     * 1 represents value of right side > value of left side.
76     * 2 represents value of left side is null.
77     * @throws DException
78     */

79
80    public Object JavaDoc run(Object JavaDoc object) throws DException {
81       _VariableValues variableValues = (_VariableValues) object;
82       Object JavaDoc rightValue = variableValues.getColumnValues(columns[0]);
83       Object JavaDoc leftValue = variableValues.getColumnValues(columns[1]);
84       int cmp = -1;
85       try {
86          cmp = comparator.compare(leftValue, rightValue);
87       } catch (NullPointerException JavaDoc ex) {
88          comparator = GetByteComparator.getComparator(columns[0].getDatatype(), false, columns[0].getTable().cc.getCollator());
89          cmp = comparator.compare(leftValue, rightValue);
90       }
91       return booleanResult[Operator - 1][cmp + 2];
92    }
93
94    /**
95     * All the following methods belong to condition, so for documentation of
96     * these methods refer to documentation of booleanvalueexpression.
97     */

98
99    public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails) throws DException {
100       /*dst*/
101       return bve.getQualifiedBVE(tableDetails);
102       /*dend*/
103    }
104
105    public double getCost(long rowCount, boolean index) throws DException {
106       return bve.getCost(rowCount, index);
107    }
108
109    public _IndexPredicateInterface getCost(_Order order, String JavaDoc[] queryColumns, Object JavaDoc session, TableDetails tableDetails) throws DException {
110       /*dst*/
111       throw new UnsupportedOperationException JavaDoc("Method not supported");
112          /*dend*/
113    }
114
115    public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws DException {
116       /*dst*/
117       bve.setColumnPredicates(allColumnPredicates);
118       /*dend*/
119    }
120
121    public int getPredicateType() throws DException {
122       return bve.getPredicateType();
123    }
124
125    public ParameterInfo[] getParameterInfo() throws DException {
126       /*dst*/
127       return bve.getParameterInfo();
128       /*dend*/
129    }
130
131    public String JavaDoc toString() {
132       return bve.toString();
133    }
134
135    public Object JavaDoc getValue() throws DException {
136       throw new DException("DSE0", new Object JavaDoc[] {"getValue() method not supposed to be called"});
137    }
138
139    public AbstractRowValueExpression[] getChilds() {
140       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] {bve};
141       return childs;
142    }
143
144    public _Reference[] checkSemantic(_ServerSession parent) throws DException {
145       return bve.checkSemantic(parent);
146    }
147
148    public long getEstimatedRows(long noOfRows) throws DException {
149       return bve.getEstimatedRows(noOfRows);
150    }
151
152    public int canUseForSeek() throws DException {
153       return bve.canUseForSeek();
154    }
155
156    public int getConditionType() throws com.daffodilwoods.database.resource.DException {
157       return bve.getConditionType();
158    }
159
160    public _BVEPlan getExecutionPlan() throws com.daffodilwoods.database.resource.DException {
161       return bve.getExecutionPlan();
162    }
163
164    public boolean isNullPredicate() throws DException {
165       return bve.isNullPredicate();
166    }
167
168    public void setOperator(int Type) throws DException {
169       Operator = Type;
170    }
171 }
172
Popular Tags