01: /*
02:
03: Derby - Class org.apache.derby.impl.sql.compile.RemapCRsVisitor
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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: package org.apache.derby.impl.sql.compile;
23:
24: import org.apache.derby.iapi.sql.compile.Visitable;
25: import org.apache.derby.iapi.sql.compile.Visitor;
26:
27: import org.apache.derby.iapi.error.StandardException;
28:
29: /**
30: * Remap/unremap the CRs to the underlying
31: * expression.
32: *
33: * @author jerry
34: */
35: public class RemapCRsVisitor implements Visitor {
36: private boolean remap;
37:
38: public RemapCRsVisitor(boolean remap) {
39: this .remap = remap;
40: }
41:
42: ////////////////////////////////////////////////
43: //
44: // VISITOR INTERFACE
45: //
46: ////////////////////////////////////////////////
47:
48: /**
49: * Don't do anything unless we have a ColumnReference
50: * node.
51: *
52: * @param node the node to process
53: *
54: * @return me
55: *
56: * @exception StandardException on error
57: */
58: public Visitable visit(Visitable node) throws StandardException {
59: /*
60: * Remap all of the ColumnReferences in this expression tree
61: * to point to the ResultColumn that is 1 level under their
62: * current source ResultColumn.
63: * This is useful for pushing down single table predicates.
64: */
65: if (node instanceof ColumnReference) {
66: ColumnReference cr = (ColumnReference) node;
67: if (remap) {
68: cr.remapColumnReferences();
69: } else {
70: cr.unRemapColumnReferences();
71: }
72: }
73:
74: return node;
75: }
76:
77: /**
78: * No need to go below a SubqueryNode.
79: *
80: * @return Whether or not to go below the node.
81: */
82: public boolean skipChildren(Visitable node) {
83: return (node instanceof SubqueryNode);
84: }
85:
86: public boolean stopTraversal() {
87: return false;
88: }
89:
90: ////////////////////////////////////////////////
91: //
92: // CLASS INTERFACE
93: //
94: ////////////////////////////////////////////////
95:
96: }
|