KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.RemapCRsVisitor
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  * Remap/unremap the CRs to the underlying
32  * expression.
33  *
34  * @author jerry
35  */

36 public class RemapCRsVisitor implements Visitor
37 {
38     private boolean remap;
39
40     public RemapCRsVisitor(boolean remap)
41     {
42         this.remap = remap;
43     }
44
45
46     ////////////////////////////////////////////////
47
//
48
// VISITOR INTERFACE
49
//
50
////////////////////////////////////////////////
51

52     /**
53      * Don't do anything unless we have a ColumnReference
54      * node.
55      *
56      * @param node the node to process
57      *
58      * @return me
59      *
60      * @exception StandardException on error
61      */

62     public Visitable visit(Visitable node)
63         throws StandardException
64     {
65         /*
66          * Remap all of the ColumnReferences in this expression tree
67          * to point to the ResultColumn that is 1 level under their
68          * current source ResultColumn.
69          * This is useful for pushing down single table predicates.
70          */

71         if (node instanceof ColumnReference)
72         {
73             ColumnReference cr = (ColumnReference) node;
74             if (remap)
75             {
76                 cr.remapColumnReferences();
77             }
78             else
79             {
80                 cr.unRemapColumnReferences();
81             }
82         }
83
84         return node;
85     }
86
87     /**
88      * No need to go below a SubqueryNode.
89      *
90      * @return Whether or not to go below the node.
91      */

92     public boolean skipChildren(Visitable node)
93     {
94         return (node instanceof SubqueryNode);
95     }
96
97     public boolean stopTraversal()
98     {
99         return false;
100     }
101
102     ////////////////////////////////////////////////
103
//
104
// CLASS INTERFACE
105
//
106
////////////////////////////////////////////////
107

108 }
109
Popular Tags