KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition;
2
3 /*
4  * @(#)BVEPlanMerger.java 1.130 06/03/2003
5  *
6  * Copyright 2001-2003 Daffodil Software Ltd. All Rights Reserved.
7  *
8  * This software is the proprietary information of Daffodil Software Ltd.
9  * Use is subject to license terms.
10  *
11  */

12 import com.daffodilwoods.daffodildb.server.sql99.common.*;
13 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
14 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*;
15 import com.daffodilwoods.daffodildb.server.sql99.token.*;
16 import com.daffodilwoods.database.resource.*;
17
18 /**
19  * The <code><b>BVEPlanMerger</b></code> provides functions for merging of two
20  * <code><b>booleanvlaueexpression</b></code> objects, merging of two
21  * <code><b>_BVEPlan</b></code> objects and two <code><b>BVESingleTablePlan
22  * </b></code> objects.
23  * <p>All function of this class are static. The merging operation are
24  * available for <code><b>AND</b></code> and <code><b>OR</b></code> operation
25  * on two objects.
26  * @author Pardeep Sharma
27  * @version 1.0
28  */

29 public class BVEPlanMerger implements ExecutionPlanConstants, BVEConstants {
30
31    /**
32     * It provides functionality of merging two condition with AND logical operator.
33     * two condition can be either predicate ,combination of predicate combined
34     * with logical AND and combination of predicate combined with logical OR.
35     * Returns a <code>booleanvalueexpression</code> wrapped on the <code>
36     * booleantermSRESERVEDWORD1206543922booleanfactor</code> object.
37     * This method accepts two <code>booleanvalueexpression</code> objects
38     * for their merging with <code>AND</code> operator.
39     * The both objects can be of <code>ExecutionPlanConstants.PREDICATE</code>
40     * or <code>ExecutionPlanConstants.BVEORBT</code> or
41     * <code>ExecutionPlanConstants.BTANDBF</code> type only.
42     * <p><pre>
43     * SQL Grammer used for merging operation.
44     * BVE
45     * |
46     * +- BT / BVE OR BT
47     * |
48     * +-BF / BT AND BF
49     * |
50     * +-[NOT] booleantest
51     * |
52     * +-booleanprimary [IS [NOT] truthvalue]
53     * |
54     * +-paranthesized BVE / non paranthesized BVE / Predicate
55     *--------------------------------------------------------------------------
56     * Original Type of Converted To Type
57     * First Operand Second Operand First Oprand Second Oprand
58     *--------------------------------------------------------------------------
59     * PREDICATE PREDICATE BT BF
60     * - BT_AND_BF BF BT
61     * - BVE_OR_BT BT BF(PBVE)
62     * BT_AND_BF PREDICATE BT BF
63     * - BT_AND_BF BT BF(PBVE)
64     * - BVE_OR_BT BT BF(PBVE)
65     * BVE_OR_BT PREDICATE BF(PBVE) BT
66     * - BT_AND_BF BF BT
67     * - BVE_OR_BT BF(PBVE) BF(PBVE)
68     *--------------------------------------------------------------------------
69     *</pre>
70     *
71     *
72     * @param bve1 booleanvalueexpression
73     * @param bve2 booleanvalueexpression
74     * @return <code>booleanvalueexpression<code> Merged bve1 and bve2 as
75     * <code>booleantermSRESERVEDWORD1206543922booleanfactor</code> wrapped in
76     * <code>booleanvalueexpression</code>.
77     * @throws DException
78     */

79    public static booleanvalueexpression addAndConditions(booleanvalueexpression bve1, booleanvalueexpression bve2) throws DException {
80                 SRESERVEDWORD1206543922 sRES = new SRESERVEDWORD1206543922();
81                 sRES._SRESERVEDWORD12065439220 = "AND";
82                 if (bve1 == null)
83                         return bve2;
84                 if (bve2 == null)
85                         return bve1;
86                 int type1 = bve1.getConditionType ();
87                 int type2 = bve2.getConditionType ();
88                 if(type1 == CONTAINS){
89                   return bve1;
90                 }
91                 if(type2 == CONTAINS){
92                   return bve2;
93                 }
94                 if(type1 == PREDICATE){
95                         if(type2 == PREDICATE){
96                                 return new booleantermSRESERVEDWORD1206543922booleanfactor((booleanterm)bve1,(booleanfactor)bve2 ,sRES);/*getBooleanFactor(*/
97                         }
98                         if(type2 == BTANDBF)
99                                 return new booleantermSRESERVEDWORD1206543922booleanfactor((booleanterm)bve2,(booleanfactor)bve1 , sRES);
100                         if(type2 == BVEORBT)
101                                 return new booleantermSRESERVEDWORD1206543922booleanfactor((booleanterm) bve1 ,getBooleanFactor(new parenthesizedbooleanvalueexpression(bve2)) , sRES );
102                         throw new DException("DSE527", new Object JavaDoc[]{new Integer JavaDoc(type2)});
103                 }
104                 if(type1 == BTANDBF){
105                         if(type2 == PREDICATE)
106                                 return new booleantermSRESERVEDWORD1206543922booleanfactor((booleanterm) bve1,(booleanfactor)bve2 , sRES );
107                         if(type2 == BTANDBF)
108                                 return new booleantermSRESERVEDWORD1206543922booleanfactor ((booleanterm)bve1,getBooleanFactor((booleanprimary)(new parenthesizedbooleanvalueexpression(bve2))) , sRES );
109                         if(type2 == BVEORBT)
110                                 return new booleantermSRESERVEDWORD1206543922booleanfactor ((booleanterm)bve1,getBooleanFactor((booleanprimary)(new parenthesizedbooleanvalueexpression(bve2)) ) , sRES);
111                         throw new DException("DSE527", new Object JavaDoc[]{new Integer JavaDoc(type2)});
112                 }
113                 if(type1 == BVEORBT){
114                         if(type2 == PREDICATE)
115                                 return new booleantermSRESERVEDWORD1206543922booleanfactor ((booleanterm)bve2,getBooleanFactor((booleanprimary)(new parenthesizedbooleanvalueexpression(bve1))) , sRES);
116                         if(type2 == BTANDBF)
117                                 return new booleantermSRESERVEDWORD1206543922booleanfactor ((booleanterm)bve2 , getBooleanFactor((booleanprimary)(new parenthesizedbooleanvalueexpression(bve1)) ) , sRES);
118                         if(type2 == BVEORBT)
119                                 return new booleantermSRESERVEDWORD1206543922booleanfactor (getBooleanFactor(new parenthesizedbooleanvalueexpression(bve1)) , getBooleanFactor(new parenthesizedbooleanvalueexpression(bve2)) , sRES);
120                         throw new DException("DSE527", new Object JavaDoc[]{new Integer JavaDoc(type2)});
121                 }
122                 throw new DException("DSE527", new Object JavaDoc[]{new Integer JavaDoc(type1)});
123    } //end of addAndConditions
124

125    /**
126     * It provides functionality of merging two condition with OR logical operator.
127     * two condition can be either predicate ,combination of predicate combined
128     * with logical AND and combination of predicate combined with logical OR.
129     * Returns a <code>booleanvalueexpression</code> wrapped on the <code>
130     * booleanvalueexpressionSRESERVEDWORD1206543922booleanterm</code> object.
131     * This method accepts two <code>booleanvalueexpression</code> objects
132     * for their merging with <code>OR</code> operator.
133     * The both objects can be of <code>ExecutionPlanConstants.PREDICATE</code>
134     * or <code>ExecutionPlanConstants.BVEORBT</code> or
135     * <code>ExecutionPlanConstants.BTANDBF</code> type only.
136     * <p><pre>
137     * SQL Grammer used for merging operation.
138     * BVE
139     * |
140     * +- BT / BVE OR BT
141     * |
142     * +-BF / BT AND BF
143     * |
144     * +-[NOT] booleantest
145     * |
146     * +-booleanprimary [IS [NOT] truthvalue]
147     * |
148     * +-paranthesized BVE / non paranthesized BVE / Predicate
149     *--------------------------------------------------------------------------
150     * Original Type of Converted To Type
151     * First Operand Second Operand First Oprand Second Oprand
152     *--------------------------------------------------------------------------
153     * PREDICATE PREDICATE BVE BT
154     * - BT_AND_BF BT BVE
155     * - BVE_OR_BT BT BVE
156     * BT_AND_BF PREDICATE BVE BT
157     * - BT_AND_BF BVE BT
158     * - BVE_OR_BT BT BVE
159     * BVE_OR_BT PREDICATE BVE BT
160     * - BT_AND_BF BVE BT
161     * - BVE_OR_BT BVE BF(PBVE)
162     *--------------------------------------------------------------------------
163     *</pre>
164     *
165     * @param bve1 booleanvalueexpression
166     * @param bve2 booleanvalueexpression
167     * @return <code>booleanvalueexpression<code> - Merged bve1 and bve2 as
168     * <code>booleanvalueexpressionSRESERVEDWORD1206543922booleanterm</code>
169     * wrapped in <code>booleanvalueexpression</code>.
170     * @throws DException
171     */

172    public static booleanvalueexpression addOrConditions(booleanvalueexpression bve1, booleanvalueexpression bve2) throws DException {
173       SRESERVEDWORD1206543922 sRES = new SRESERVEDWORD1206543922();
174       sRES._SRESERVEDWORD12065439220 = "OR";
175       if (bve1 == null) {
176          return bve2;
177       }
178       if (bve2 == null) {
179          return bve1;
180       }
181       int type1 = bve1.getConditionType();
182       int type2 = bve2.getConditionType();
183       if (type1 == PREDICATE) {
184          if (type2 == PREDICATE) {
185             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm( (booleanterm) bve1, (booleanterm) bve2, sRES);
186          }
187          if (type2 == BTANDBF) {
188             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve2, (booleanterm) bve1, sRES);
189          }
190          if (type2 == BVEORBT) {
191             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve2, (booleanterm) bve1, sRES);
192          }
193          throw new DException("DSE527", new Object JavaDoc[] {new Integer JavaDoc(type2)});
194       }
195       if (type1 == BTANDBF) {
196          if (type2 == PREDICATE) {
197             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve1, (booleanterm) bve2, sRES);
198          }
199          if (type2 == BTANDBF) {
200             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm( (booleanvalueexpression) bve1, (booleanterm) bve2, sRES);
201          }
202          if (type2 == BVEORBT) {
203             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve2, (booleanterm) bve1, sRES);
204          }
205          throw new DException("DSE527", new Object JavaDoc[] {new Integer JavaDoc(type2)});
206       }
207       if (type1 == BVEORBT) {
208          if (type2 == PREDICATE) {
209             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve1, (booleanterm) bve2, sRES);
210          }
211          if (type2 == BTANDBF) {
212             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve1, (booleanterm) bve2, sRES);
213          }
214          if (type2 == BVEORBT) {
215             return new booleanvalueexpressionSRESERVEDWORD1206543922booleanterm(bve1, getBooleanFactor( (booleanprimary) (new parenthesizedbooleanvalueexpression(bve2))), sRES);
216          }
217          throw new DException("DSE527", new Object JavaDoc[] {new Integer JavaDoc(type2)});
218       }
219       throw new DException("DSE527", new Object JavaDoc[] {new Integer JavaDoc(type1)});
220    } //end of addOrConditions
221

222    /**
223     * Merges two <code><b>BVESingleTablePlan</code></b> plans using OR Operator,
224     * both of same table and returns combined <code><b>BVESingleTablePlan
225     * </code></b> wrapped in <code><b>_BVEPlan</code></b>. Clone of condition
226     * is used for the purpose when condition belongs to view and same condition
227     * is solved at the top of view as well as under the view.
228     * @param tablePlan1 BVESingleTablePlan
229     * @param tablePlan2 BVESingleTablePlan
230     * @return _BVEPlan having two OR operator merged BVESingleTablePlan.
231     * @throws DException
232     */

233    public static _BVEPlan mergeSamePlanWithOr(_BVESingleTablePlan tablePlan1, _BVESingleTablePlan tablePlan2) throws DException {
234       try {
235          booleanvalueexpression bve = addOrConditions( (booleanvalueexpression) tablePlan1.getCondition().clone(), (booleanvalueexpression) tablePlan2.getCondition().clone());
236          tablePlan1.setCondition(bve);
237          return (_BVEPlan) tablePlan1;
238       } catch (CloneNotSupportedException JavaDoc ex) {
239          throw new DException("DSE0", new Object JavaDoc[] {"Clone Not Supported"});
240       }
241    } //end of mergeSamePlanWithOr
242

243    /**
244     * Merges two <code><b>BVESingleTablePlan</code></b> plans using AND Operator,
245     * both of same table and returns combined <code><b>BVESingleTablePlan
246     * </code></b> wrapped in <code><b>_BVEPlan</code></b>.
247     * @param tablePlan1 BVESingleTablePlan
248     * @param tablePlan2 BVESingleTablePlan
249     * @return _BVEPlan having two OR operator merged BVESingleTablePlan.
250     * @throws DException
251     */

252    public static _BVEPlan mergeSamePlanWithAnd(_BVESingleTablePlan tablePlan1, _BVESingleTablePlan tablePlan2) throws DException {
253       booleanvalueexpression bve = addAndConditions(tablePlan1.getCondition(), tablePlan2.getCondition());
254       tablePlan1.setCondition(bve);
255       return tablePlan1;
256    } // end of mergeSamePlanWithAnd
257

258    /**
259     * Merges two <code><b>_BVEPlan</code></b> belonging to different tables
260     * using <code><b>AND</code></b> Operator and returns merged <code><b>
261     * _BVEPlan</code></b> object.
262     * <p>The both arguments can be of type <code><b>
263     * BVEConstants.BVESINGLETABLEPLAN</code></b> or <code><b>
264     * BVEConstants.BVEALLTABLEPLAN</code></b> or <code><b>
265     * BVEConstants.BVEAGGREGATEPLAN</code></b> only.
266     * <p>Because this method is for <code><b>AND</code></b>ing the two plans,
267     * conditions in the merged plan will be result of <code><b>AND</code></b>
268     * operation.
269     * @param tablePlan1 _BVEPlan
270     * @param tablePlan2 _BVEPlan
271     * @return _BVEPlan
272     * @throws DException
273     */

274    public static _BVEPlan mergeTablePlansWithAnd(_BVEPlan tablePlan1, _BVEPlan tablePlan2) throws DException {
275       /*dst*/
276       if (tablePlan1 == null) {
277          return tablePlan2;
278       }
279       if (tablePlan2 == null) {
280          return tablePlan1;
281       }
282       int type1 = tablePlan1.getType();
283       int type2 = tablePlan2.getType();
284       if (type1 == BVEConstants.BVESINGLETABLEPLAN) {
285          if (type2 == BVEConstants.BVESINGLETABLEPLAN) {
286             return mergeTwoBveSingleTablePlan( (_BVESingleTablePlan) tablePlan1, (_BVESingleTablePlan) tablePlan2);
287          }
288          if (type2 == BVEConstants.BVEALLTABLEPLAN) {
289             ( (BVEAllTablePlan) tablePlan2).andBVESingleTablePlan(new BVESingleTablePlan[] { (BVESingleTablePlan) tablePlan1});
290             return tablePlan2;
291          }
292          if (type2 == BVEConstants.BVEAGGREGATEPLAN) {
293             BVEAllTablePlan bveAllTablePlan = new BVEAllTablePlan(new _BVESingleTablePlan[] { (BVESingleTablePlan) tablePlan1}
294                 , null, null);
295             bveAllTablePlan.andAggregateCondition( ( (BVEAggregatePlan) tablePlan2).getAggregateCondition());
296             return bveAllTablePlan;
297          }
298       }
299
300       if (type1 == BVEConstants.BVEALLTABLEPLAN) {
301          if (type2 == BVEConstants.BVESINGLETABLEPLAN) {
302             ( (BVEAllTablePlan) tablePlan1).andBVESingleTablePlan(new BVESingleTablePlan[] { (BVESingleTablePlan) tablePlan2});
303             return tablePlan1;
304          }
305          if (type2 == BVEConstants.BVEALLTABLEPLAN) {
306             return mergeTwoAllTablePlan(tablePlan1, tablePlan2);
307          }
308          if (type2 == BVEConstants.BVEAGGREGATEPLAN) {
309             return mergeAllTableAndAggregateCondition(tablePlan1, tablePlan2);
310          }
311       }
312       if (type1 == BVEConstants.BVEAGGREGATEPLAN) {
313          if (type2 == BVEConstants.BVESINGLETABLEPLAN) {
314             BVEAllTablePlan bveAllTablePlan = new BVEAllTablePlan(new _BVESingleTablePlan[] { (BVESingleTablePlan) tablePlan2}
315                 , null, null);
316             bveAllTablePlan.andAggregateCondition( ( (BVEAggregatePlan) tablePlan1).getAggregateCondition());
317             return bveAllTablePlan;
318          }
319          if (type2 == BVEConstants.BVEALLTABLEPLAN) {
320             return mergeAllTableAndAggregateCondition(tablePlan2, tablePlan1);
321          }
322          if (type2 == BVEConstants.BVEAGGREGATEPLAN) {
323             return mergeAggregatePlanAndAggregatePlan(tablePlan1, tablePlan2);
324          }
325          /*dend*/
326       }
327       throw new DException("DSE527", new Object JavaDoc[] {new Integer JavaDoc(type1)});
328    }
329
330    /**
331     * Merges two <code><b>_BVEPlan</code></b> belonging to different tables
332     * using <code><b>OR</code></b> Operator and returns merged <code><b>
333     * _BVEPlan</code></b> object.
334     * <p>The both arguments can be of type <code><b>
335     * BVEConstants.BVESINGLETABLEPLAN</code></b> or <code><b>
336     * BVEConstants.BVEALLTABLEPLAN</code></b> or <code><b>
337     * BVEConstants.BVEAGGREGATEPLAN</code></b> only.
338     * <p>Because this method is for <code><b>OR</code></b>ing the two plans,
339     * conditions in the merged plan will be result of <code><b>OR</code></b>
340     * operation.
341     * @param tablePlan1 _BVEPlan
342     * @param tablePlan2 _BVEPlan
343     * @param bve booleanvalueexpression
344     * @return _BVEPlan
345     * @throws DException
346     */

347    public static _BVEPlan mergeTablePlansWithOr(_BVEPlan tablePlan1, _BVEPlan tablePlan2, booleanvalueexpression bve) throws DException {
348       int type1 = tablePlan1.getType();
349       int type2 = tablePlan2.getType();
350       if (type1 == BVEConstants.BVESINGLETABLEPLAN) {
351          if (type2 == BVEConstants.BVESINGLETABLEPLAN) {
352             TableDetails table1 = ( (BVESingleTablePlan) tablePlan1).getTableDetails()[0];
353             TableDetails table2 = ( (BVESingleTablePlan) tablePlan2).getTableDetails()[0];
354             if (table1 == table2) {
355                return mergeSamePlanWithOr( (BVESingleTablePlan) tablePlan1, (BVESingleTablePlan) tablePlan2);
356             } else {
357                ( (BVESingleTablePlan) tablePlan1).setCondition(null);
358                ( (BVESingleTablePlan) tablePlan2).setCondition(null);
359                return (_BVEPlan)new BVEAllTablePlan(null, null, bve);
360             }
361          }
362          if (type2 == BVEConstants.BVEALLTABLEPLAN) {
363             ( (BVEAllTablePlan) tablePlan2).orBVESingleTablePlan(new BVESingleTablePlan[] { (BVESingleTablePlan) tablePlan1});
364             ( (BVEAllTablePlan) tablePlan2).orRelation(null);
365             ( (BVEAllTablePlan) tablePlan2).setRemainingCondition(bve);
366             return tablePlan2;
367          }
368          if (type2 == BVEConstants.BVEAGGREGATEPLAN) {
369             ( (BVEAggregatePlan) tablePlan2).setAggregateCondition(bve);
370             return tablePlan2;
371          }
372       }
373       if (type1 == BVEConstants.BVEALLTABLEPLAN) {
374          if (type2 == BVEConstants.BVESINGLETABLEPLAN) {
375             ( (BVEAllTablePlan) tablePlan1).orBVESingleTablePlan(new BVESingleTablePlan[] { (BVESingleTablePlan) tablePlan2});
376             ( (BVEAllTablePlan) tablePlan1).orRelation(null);
377             ( (BVEAllTablePlan) tablePlan1).setRemainingCondition(bve);
378             return tablePlan1;
379          }
380          if (type2 == BVEConstants.BVEALLTABLEPLAN) {
381             ( (BVEAllTablePlan) tablePlan1).orBVESingleTablePlan( ( (BVEAllTablePlan) tablePlan2).getBVESingleTablePlans());
382             ( (BVEAllTablePlan) tablePlan1).orRelation( ( (BVEAllTablePlan) tablePlan2).getAllTableJoinRelation());
383             ( (BVEAllTablePlan) tablePlan1).setRemainingCondition(bve);
384             return tablePlan1;
385          }
386          if (type2 == BVEConstants.BVEAGGREGATEPLAN) {
387             ( (BVEAggregatePlan) tablePlan2).setAggregateCondition(bve);
388             return tablePlan2;
389          }
390       }
391       if (type1 == BVEConstants.BVEAGGREGATEPLAN) {
392          ( (BVEAggregatePlan) tablePlan1).setAggregateCondition(bve);
393          return tablePlan1;
394
395       }
396       throw new DException("DSE527", new Object JavaDoc[] {new Integer JavaDoc(type1)});
397    }
398
399    /**
400     * Returns a <code><b>booleanfactor</code></b> object wrapped to the given
401     * <code><b>booleanprimary</code></b> object.
402     * @param bp booleanprimary
403     * @return booleanfactor
404     * @throws DException
405     */

406    public static booleanfactor getBooleanFactor(booleanprimary bp) throws DException {
407       return new booleanfactor(new booleantest(bp));
408    }
409    /**
410     * Return booleanfactor object wrapped to given predicate.
411     * @param predicate0
412     * @return
413     * @throws DException
414     */

415    public static booleanfactor getBooleanFactor(predicate predicate0) throws DException {
416       return new booleanfactor(new booleantest(predicate0));
417    }
418    /**
419     * This method is used to merge two single table plan of same table with AND
420     * logical operator.
421     * @param tablePlan1
422     * @param tablePlan2
423     * @return _Bvesingletableplan
424     * @throws DException
425     */

426    public static _BVESingleTablePlan mergeSameSinglePlanWithAnd(_BVESingleTablePlan tablePlan1, _BVESingleTablePlan tablePlan2) throws DException {
427       booleanvalueexpression bve = addAndConditions(tablePlan1.getCondition(), tablePlan2.getCondition());
428       tablePlan1.setCondition(bve);
429       return tablePlan1;
430    }
431    /**
432     * This method is required to merge two singletable plan.Two single table plan
433     * may or may not belong to same table.when two single table plan belong to same
434     * table we merge both plan with AND logical operator and resultant plan will
435     * also be _BveSingletablePlan.(means resultant condition shifted to single
436     * table level) when both plan belong to different table then resultant plan
437     * will be BVEAllTablePlan which contains both single table plan.
438     * @param tablePlan1
439     * @param tablePlan2
440     * @return
441     * @throws DException
442     */

443    private static _BVEPlan mergeTwoBveSingleTablePlan(_BVESingleTablePlan tablePlan1, _BVESingleTablePlan tablePlan2) throws DException {
444       TableDetails table1 = tablePlan1.getTableDetails()[0];
445       TableDetails table2 = tablePlan2.getTableDetails()[0];
446       if (table1 == table2) {
447          return mergeSamePlanWithAnd( (_BVESingleTablePlan) tablePlan1, (_BVESingleTablePlan) tablePlan2);
448       }
449       return new BVEAllTablePlan(new _BVESingleTablePlan[] { (_BVESingleTablePlan) tablePlan1, (_BVESingleTablePlan) tablePlan2}
450                                  , null, null);
451    }
452    /**
453     * This method is required to merge two AllTablePlan Which belongs to same table
454     * with AND logical operator. It performs the following function
455     * 1. Merging of single table plans.
456     * 2. Merging of remaining condition.
457     * 3. Merging of join relations.
458     * 4. Merging of aggregate condition.
459     * @param tablePlan1
460     * @param tablePlan2
461     * @return _Bveplan
462     * @throws DException
463     */

464    private static _BVEPlan mergeTwoAllTablePlan(_BVEPlan tablePlan1, _BVEPlan tablePlan2) throws DException {
465       ( (BVEAllTablePlan) tablePlan1).andBVESingleTablePlan( ( (BVEAllTablePlan) tablePlan2).getBVESingleTablePlans());
466       ( (BVEAllTablePlan) tablePlan1).andRemainingCondition( ( (BVEAllTablePlan) tablePlan2).getRemainingCondition());
467       ( (BVEAllTablePlan) tablePlan1).andRelation( ( (BVEAllTablePlan) tablePlan2).getAllTableJoinRelation());
468       ( (BVEAllTablePlan) tablePlan1).andAggregateCondition( ( (BVEAllTablePlan) tablePlan2).aggregateCondition);
469       return tablePlan1;
470    }
471    /**
472     * This method is required to merge aggregatecondition of two BveAllTablePlans.
473     * @param tablePlan1
474     * @param tablePlan2
475     * @return
476     * @throws DException
477     */

478    private static _BVEPlan mergeAllTableAndAggregateCondition(_BVEPlan tablePlan1, _BVEPlan tablePlan2) throws DException {
479       ( (BVEAllTablePlan) tablePlan1).andAggregateCondition( ( (BVEAggregatePlan) tablePlan2).getAggregateCondition());
480       return tablePlan1;
481    }
482    /**
483     * This method is required to merge two Aggregate plan with AND logical operator
484     * belonging to same table
485     * @param tablePlan1
486     * @param tablePlan2
487     * @return
488     * @throws DException
489     */

490    private static _BVEPlan mergeAggregatePlanAndAggregatePlan(_BVEPlan tablePlan1, _BVEPlan tablePlan2) throws DException {
491       ( (BVEAggregatePlan) tablePlan1).addAggregateCondition( ( (BVEAggregatePlan) tablePlan2).getAggregateCondition());
492       return tablePlan1;
493    }
494 }
495
Popular Tags