01: /*
02:
03: Derby - Class org.apache.derby.impl.sql.compile.ReferencedTablesVisitor
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: import org.apache.derby.iapi.util.JBitSet;
30:
31: /**
32: * Build a JBitSet of all of the referenced tables in the tree.
33: *
34: * @author jerry
35: */
36: public class ReferencedTablesVisitor implements Visitor {
37: private JBitSet tableMap;
38:
39: public ReferencedTablesVisitor(JBitSet tableMap) {
40: this .tableMap = tableMap;
41: }
42:
43: ////////////////////////////////////////////////
44: //
45: // VISITOR INTERFACE
46: //
47: ////////////////////////////////////////////////
48:
49: /**
50: * Don't do anything unless we have a ColumnReference,
51: * Predicate or ResultSetNode node.
52: *
53: * @param node the node to process
54: *
55: * @return me
56: *
57: * @exception StandardException on error
58: */
59: public Visitable visit(Visitable node) throws StandardException {
60: if (node instanceof ColumnReference) {
61: ((ColumnReference) node).getTablesReferenced(tableMap);
62: } else if (node instanceof Predicate) {
63: Predicate pred = (Predicate) node;
64: tableMap.or(pred.getReferencedSet());
65: } else if (node instanceof ResultSetNode) {
66: ResultSetNode rs = (ResultSetNode) node;
67: tableMap.or(rs.getReferencedTableMap());
68: }
69:
70: return node;
71: }
72:
73: /**
74: * No need to go below a Predicate or ResultSet.
75: *
76: * @return Whether or not to go below the node.
77: */
78: public boolean skipChildren(Visitable node) {
79: return (node instanceof Predicate || node instanceof ResultSetNode);
80: }
81:
82: public boolean stopTraversal() {
83: return false;
84: }
85:
86: ////////////////////////////////////////////////
87: //
88: // CLASS INTERFACE
89: //
90: ////////////////////////////////////////////////
91: JBitSet getTableMap() {
92: return tableMap;
93: }
94: }
|