KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > ReplaceAggregatesWithCRVisitor


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.ReplaceAggregatesWithCRVisitor
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22
23 package org.apache.derby.impl.sql.compile;
24
25 import org.apache.derby.iapi.sql.compile.Visitable;
26 import org.apache.derby.iapi.sql.compile.Visitor;
27
28 import org.apache.derby.iapi.error.StandardException;
29
30 /**
31  * Replace all aggregates with result columns.
32  *
33  * @author jamie
34  */

35 public class ReplaceAggregatesWithCRVisitor implements Visitor
36 {
37     private ResultColumnList rcl;
38     private Class JavaDoc skipOverClass;
39     private int tableNumber;
40
41     /**
42      * Replace all aggregates with column references. Add
43      * the reference to the RCL. Delegates most work to
44      * AggregateNode.replaceAggregatesWithColumnReferences(rcl, tableNumber).
45      *
46      * @param rcl the result column list
47      * @param tableNumber The tableNumber for the new CRs
48      */

49     public ReplaceAggregatesWithCRVisitor(ResultColumnList rcl, int tableNumber)
50     {
51         this.rcl = rcl;
52         this.tableNumber = tableNumber;
53     }
54
55     /**
56      * Replace all aggregates with column references. Add
57      * the reference to the RCL. Delegates most work to
58      * AggregateNode.replaceAggregatesWithColumnReferences(rcl).
59      * Doesn't traverse below the passed in class.
60      *
61      * @param rcl the result column list
62      * @param nodeToSkip don't examine anything below nodeToSkip
63      */

64     public ReplaceAggregatesWithCRVisitor(ResultColumnList rcl, Class JavaDoc nodeToSkip)
65     {
66         this.rcl = rcl;
67         this.skipOverClass = nodeToSkip;
68     }
69
70
71     ////////////////////////////////////////////////
72
//
73
// VISITOR INTERFACE
74
//
75
////////////////////////////////////////////////
76

77     /**
78      * Don't do anything unless we have an aggregate
79      * node.
80      *
81      * @param node the node to process
82      *
83      * @return me
84      *
85      * @exception StandardException on error
86      */

87     public Visitable visit(Visitable node)
88         throws StandardException
89     {
90         if (node instanceof AggregateNode)
91         {
92             /*
93             ** Let aggregateNode replace itself.
94             */

95             node = ((AggregateNode)node).replaceAggregatesWithColumnReferences(rcl, tableNumber);
96         }
97
98         return node;
99     }
100
101     /**
102      * Don't visit childen under the skipOverClass
103      * node, if it isn't null.
104      *
105      * @return true/false
106      */

107     public boolean skipChildren(Visitable node)
108     {
109         return (skipOverClass == null) ?
110                 false:
111                 skipOverClass.isInstance(node);
112     }
113     
114     public boolean stopTraversal()
115     {
116         return false;
117     }
118 }
119
Popular Tags