KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > expression > booleanvalueexpression > booleanvalueexpressionSRESERVEDWORD1206543922booleanterm


1 package com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.dql.execution.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition.*;
8 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
9 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.rowvalueexpression.*;
11 import com.daffodilwoods.daffodildb.server.sql99.token.*;
12 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
13 import com.daffodilwoods.database.resource.*;
14 import com.daffodilwoods.database.sqlinitiator.*;
15 import com.daffodilwoods.daffodildb.server.sql99.dql.execution._SingleTableCondition;
16
17 /**
18  * <p>Title: BooleanValueExpressionOrBooleanTerm</p>
19  * <p>Description:
20  * This class represents OR condition with two children boolean value expression
21  * and boolean term. Boolean value expression in turn can be BVEORBT/BT.
22  * Boolean term in turn can be BTANDBF/BF/ParenthesizedBVE/TRUE/FALSE.
23  * It provides the functionality of Bve Execution Plan and execution of the
24  * condition.
25  * </p>
26  * <p>Copyright: Copyright (c) 2003</p>
27  * <p>Company: Daffodil S/W Ltd.</p>
28  * @author SelectTeam
29  * @version 1.0
30  */

31
32 public class booleanvalueexpressionSRESERVEDWORD1206543922booleanterm extends AbstractBooleanValueExpression implements booleanvalueexpression, TypeConstants, booleanterm, ExecutionPlanConstants, JoinConditionTableGetter, _SingleTableCondition {
33
34    public booleanterm _booleanterm0;
35    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439221;
36    public booleanvalueexpression _booleanvalueexpression2;
37
38    public booleanvalueexpressionSRESERVEDWORD1206543922booleanterm() {
39    }
40
41    public booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(booleanvalueexpression bve, booleanterm bt) throws DException {
42       this._booleanvalueexpression2 = bve;
43       this._booleanterm0 = bt;
44    }
45
46    public booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(booleanvalueexpression bve, booleanterm bt, SRESERVEDWORD1206543922 reservedWord) throws DException {
47       this._booleanvalueexpression2 = bve;
48       this._booleanterm0 = bt;
49       _SRESERVEDWORD12065439221 = reservedWord;
50    }
51
52    /**
53     * Returns the cost of evaluating this condition on passed number of rows.
54     * @param rowCount
55     * @param index
56     * @return cost
57     * @throws DException
58     */

59
60    public double getCost(long rowCount, boolean index) throws DException {
61       long rowsReduced = _booleanvalueexpression2.getEstimatedRows(rowCount);
62       long rowReduced1 = _booleanterm0.getEstimatedRows(rowCount);
63       rowsReduced = rowsReduced > rowReduced1 ? rowsReduced : rowReduced1;
64       return rowsReduced;
65    }
66
67    /**
68     * This method is called from qualified join. Passed TableDetails are of
69     * Right plans in case of LOJ and of Left Table Plans in case of ROJ.
70     * With the help of this method we identify whether 'on condition' is solvable
71     * on SingleTablePlan or on Qualified Join Level.
72     * Takes the QualifiedBVE from the booleanvalueexpression and the booleanterm. If there is a
73     * match of TableName from the SingleTablePlans of the QualifiedBVEs obtained from the BVE and BT,
74     * then the SingletablePlans' condition is ORed.
75     * The QualifiedBVE with the singleTablePlans ,if any , and the OR condition is returned.
76     * @param tablePlan
77     * @return
78     * @throws DException
79     */

80
81    public _QualifiedBVE getQualifiedBVE(TableDetails[] tableDetails0) throws DException {
82       _BVESingleTablePlan[] bveSingleTablePlan1 = _booleanvalueexpression2.getQualifiedBVE(tableDetails0).getBVESingleTablePlans();
83       _BVESingleTablePlan[] bveSingleTablePlan2 = _booleanterm0.getQualifiedBVE(tableDetails0).getBVESingleTablePlans();
84       if (bveSingleTablePlan1 == null || bveSingleTablePlan2 == null) {
85          return new QualifiedBVE(null, this);
86       }
87       int length1 = bveSingleTablePlan1.length;
88       int length2 = bveSingleTablePlan2.length;
89       int count = length1 < length2 ? length1 : length2;
90       ArrayList aList = new ArrayList(count);
91       for (int i = 0; i < length2; i++) {
92          _BVESingleTablePlan stp = bveSingleTablePlan2[i];
93          TableDetails tableDetails = bveSingleTablePlan2[i].getTableDetails()[0];
94          for (int j = 0; j < length1; j++) {
95             if (tableDetails == bveSingleTablePlan1[j].getTableDetails()[0]) {
96                stp.setCondition(BVEPlanMerger.addOrConditions(stp.getCondition(), bveSingleTablePlan1[j].getCondition()));
97                aList.add(stp);
98                break;
99             }
100          }
101       }
102       QualifiedBVE qBve = new QualifiedBVE( (BVESingleTablePlan[]) aList.toArray(new BVESingleTablePlan[0]), this);
103       return qBve;
104    }
105
106    /**
107     * This method tells whether this condition can be used for seek or not.
108     * Or condition can't be used in seek.
109     * @return
110     * @throws DException
111     */

112
113    public int canUseForSeek() throws DException {
114       return TypeConstants.NOSEEK;
115    }
116
117    /**
118     * This method returns the cost of this condition based on passed order and
119     * queryColumns.
120     * @param order
121     * @param queryColumns
122     * @param session
123     * @param tableDetail
124     * @param aggregateColumns
125     * @return
126     * @throws DException
127     */

128
129    public _IndexPredicateInterface getCost(_Order order, String JavaDoc[] queryColumns, Object JavaDoc session, TableDetails tableDetail, ColumnDetails[] aggregateColumns) throws DException {
130       AllColumnPredicates allColumnPredicates = new AllColumnPredicates();
131       allColumnPredicates.setNonIndexedCondition(this);
132       IndexPredicate indexPredicate = new IndexPredicate(null, allColumnPredicates);
133       indexPredicate.setTableDetails(tableDetail);
134       indexPredicate.setOrder(order);
135       double costLeft = _booleanvalueexpression2.getCost(order, queryColumns, session, tableDetail, aggregateColumns).getCost();
136       double costRight = _booleanterm0.getCost(order, queryColumns, session, tableDetail, aggregateColumns).getCost();
137       double cost = costLeft < costRight ? costLeft : costRight;
138       indexPredicate.setCost(cost);
139       return indexPredicate;
140    }
141
142    /**
143     * This method is called from top level condition class. And that top level
144     * class represents the condition of SingleTable. Now this method separates the
145     * condition of individual predicates based on the columnName as well as
146     * the condition which can't be used in index.
147     * Or Condition can't be used in index.
148     * @param allColumnPredicates
149     * @throws DException
150     */

151
152    public void setColumnPredicates(_AllColumnPredicates allColumnPredicates) throws DException {
153       allColumnPredicates.addToNonIndex(this);
154    }
155
156    public int getConditionType() throws DException {
157       return BVEORBT;
158    }
159
160    /**
161     * This method returns the ExecutionPlan of the condition. Execution Plan
162     * contains the following information -
163     * 1. Array of BveSingleTablePlans, the condition which can be solved on
164     * single table level.
165     * 2. BveAllTablePlan which contains the condition in which two tables are
166     * involved(join condition) and it also contains remaining condition
167     * 3. BveAggregatePlan which contains the condition of aggregate columns.
168     * This condition can involve in having clause only.
169     * @return
170     * @throws DException
171     */

172
173    public _BVEPlan getExecutionPlan() throws DException {
174       _BVEPlan tablePlan1 = _booleanvalueexpression2.getExecutionPlan();
175       _BVEPlan tablePlan2 = _booleanterm0.getExecutionPlan();
176       _BVEPlan resultantPlan = BVEPlanMerger.mergeTablePlansWithOr(tablePlan1, tablePlan2, this);
177       return resultantPlan;
178    }
179
180    /**
181     * This method is called on execution time, to get the result.
182     * Passed Object is variableValues which contains -
183     * 1. Reference-Value mapping
184     * 2. Iterator.
185     * This variable values helps in retrieving the result of underlying
186     * predicates.
187     * @param object
188     * @return This method returns the result of oring of the result of
189     * underlying predicates -
190     * Zero means condition is satisfied.
191     * Non Zero means condition is not satisfied.
192     * if any of underlying result is zero then zero is returned
193     * else non zero is returned.
194     * @throws DException
195     */

196
197    public Object JavaDoc run(Object JavaDoc object) throws DException {
198       Object JavaDoc result1 = _booleanvalueexpression2.run(object);
199       if (result1.hashCode() == 0) {
200          return result1;
201       }
202       Object JavaDoc result2 = _booleanterm0.run(object);
203
204       if (result1.hashCode() == -2 || result1.hashCode() == 2) {
205          return (result2.hashCode() == -1 || result2.hashCode() == 1) ? result1 : result2;
206       }
207       return result2;
208    }
209
210    /**
211     * This method is called from Browser, when Parameterized query is fired from Browser.
212     * With the help of ParameterInfo Browser open ups daialog box(labelled by its corresponding name)
213     * for each question mark to put the values of question mark.
214     * @return
215     * @throws DException
216     */

217
218    public ParameterInfo[] getParameterInfo() throws DException {
219       ParameterInfo[] parameterInfo1 = _booleanvalueexpression2.getParameterInfo();
220       ParameterInfo[] parameterInfo2 = _booleanterm0.getParameterInfo();
221       return GeneralPurposeStaticClass.getCombinedParameterInfoArray(parameterInfo1, parameterInfo2);
222    }
223
224    /**
225     * This method is needed in insert through resultset and is called from
226     * join condition of qualified join.
227     * @param td
228     * @return
229     * @throws com.daffodilwoods.database.resource.DException
230     */

231
232    public TableDetails[] getCorrespondingTablesInvolved(TableDetails[] td) throws com.daffodilwoods.database.resource.DException {
233       ArrayList toRet = new ArrayList();
234       boolean found = false;
235       TableDetails[] td1 = null, td2 = null;
236       if (_booleanterm0 instanceof JoinConditionTableGetter) {
237          td1 = ( (JoinConditionTableGetter) _booleanterm0).getCorrespondingTablesInvolved(td);
238          if (td1 != null) {
239             toRet.addAll(Arrays.asList(td1));
240             found = true;
241          }
242       }
243       if (_booleanvalueexpression2 instanceof JoinConditionTableGetter) {
244          td2 = ( (JoinConditionTableGetter) _booleanvalueexpression2).getCorrespondingTablesInvolved(td);
245          if (td2 != null) {
246             toRet.addAll(Arrays.asList(td2));
247             found = true;
248          }
249       }
250       if (found) {
251          return (TableDetails[]) toRet.toArray(new TableDetails[0]);
252       }
253       return null;
254    }
255
256    /**
257     * This method is used to verify the values given by the user
258     * corresponding to join-condition specified.
259     * If the values given mismatchs the join condition, exception is thrown.
260     */

261
262    public void verifyValues(_VariableValueOperations vv) throws DException {
263       if (_booleanterm0 instanceof JoinConditionTableGetter) {
264          ( (JoinConditionTableGetter) _booleanterm0).verifyValues(vv);
265       }
266       if (_booleanvalueexpression2 instanceof JoinConditionTableGetter) {
267          ( (JoinConditionTableGetter) _booleanvalueexpression2).verifyValues(vv);
268       }
269    }
270
271    /**
272     * This method returns all the children of this class. It is needed in
273     * Abstract classes, so as to move common methods in Abstract class.
274     * @return
275     */

276
277    public AbstractRowValueExpression[] getChilds() {
278       AbstractRowValueExpression[] childs = new AbstractRowValueExpression[] { (AbstractRowValueExpression) (_booleanvalueexpression2), (AbstractRowValueExpression) (_booleanterm0)};
279       return childs;
280    }
281
282    /**
283     * This method tells whether null predicate is present in the condition or not.
284     * This is needed while shifting the condition to single table in case of
285     * Loj/Roj to identify whether to shift condition or not. As if null predicate
286     * is present in condition on right table of LOJ and left table of Roj, then
287     * we can't shift the condition to single table level.
288     * @return
289     * @throws DException
290     */

291
292    public boolean isNullPredicate() throws DException {
293       return _booleanvalueexpression2.isNullPredicate() || _booleanterm0.isNullPredicate();
294    }
295
296    /**
297     * This method returns the estimate of the rows remaining after the execution
298     * of this condition on passed number of rows.
299     * @param noOfRows
300     * @return
301     * @throws DException
302     */

303
304    public long getEstimatedRows(long noOfRows) throws DException {
305       return (_booleanvalueexpression2.getEstimatedRows(noOfRows)) + (_booleanterm0.getEstimatedRows(noOfRows));
306    }
307
308    public String JavaDoc toString() {
309       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
310       sb.append(" ");
311       sb.append(_booleanvalueexpression2);
312       sb.append(" ");
313       sb.append(_SRESERVEDWORD12065439221);
314       sb.append(" ");
315       sb.append(_booleanterm0);
316       return sb.toString();
317    }
318
319    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
320       booleanvalueexpressionSRESERVEDWORD1206543922booleanterm tempClass = new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm();
321       tempClass._booleanterm0 = (booleanterm) _booleanterm0.clone();
322       tempClass._SRESERVEDWORD12065439221 = (SRESERVEDWORD1206543922) _SRESERVEDWORD12065439221.clone();
323       tempClass._booleanvalueexpression2 = (booleanvalueexpression) _booleanvalueexpression2.clone();
324       try {
325          tempClass.getColumnDetails();
326       } catch (DException ex) {
327          throw new RuntimeException JavaDoc(ex.getMessage());
328       }
329       return tempClass;
330    }
331
332    public booleanvalueexpression getSingleTableCondition() throws DException {
333       return this;
334    }
335 }
336
Popular Tags