--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.ReferencedTablesVisitor\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.sql.compile.Visitable; \r
+import org.apache.derby.iapi.sql.compile.Visitor;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+\r
+import org.apache.derby.iapi.util.JBitSet;\r
+\r
+/**\r
+ * Build a JBitSet of all of the referenced tables in the tree.\r
+ *\r
+ */\r
+public class ReferencedTablesVisitor implements Visitor \r
+{\r
+ private JBitSet tableMap;\r
+\r
+ public ReferencedTablesVisitor(JBitSet tableMap)\r
+ {\r
+ this.tableMap = tableMap;\r
+ }\r
+\r
+\r
+ ////////////////////////////////////////////////\r
+ //\r
+ // VISITOR INTERFACE\r
+ //\r
+ ////////////////////////////////////////////////\r
+\r
+ /**\r
+ * Don't do anything unless we have a ColumnReference,\r
+ * Predicate or ResultSetNode node.\r
+ *\r
+ * @param node the node to process\r
+ *\r
+ * @return me\r
+ *\r
+ * @exception StandardException on error\r
+ */\r
+ public Visitable visit(Visitable node)\r
+ throws StandardException\r
+ {\r
+ if (node instanceof ColumnReference)\r
+ {\r
+ ((ColumnReference)node).getTablesReferenced(tableMap);\r
+ }\r
+ else if (node instanceof Predicate)\r
+ {\r
+ Predicate pred = (Predicate) node;\r
+ tableMap.or(pred.getReferencedSet());\r
+ }\r
+ else if (node instanceof ResultSetNode)\r
+ {\r
+ ResultSetNode rs = (ResultSetNode) node;\r
+ tableMap.or(rs.getReferencedTableMap());\r
+ }\r
+\r
+ return node;\r
+ }\r
+\r
+ /**\r
+ * No need to go below a Predicate or ResultSet.\r
+ *\r
+ * @return Whether or not to go below the node.\r
+ */\r
+ public boolean skipChildren(Visitable node)\r
+ {\r
+ return (node instanceof Predicate ||\r
+ node instanceof ResultSetNode);\r
+ }\r
+\r
+ public boolean stopTraversal()\r
+ {\r
+ return false;\r
+ }\r
+ ////////////////////////////////////////////////\r
+ //\r
+ // CLASS INTERFACE\r
+ //\r
+ ////////////////////////////////////////////////\r
+ JBitSet getTableMap()\r
+ {\r
+ return tableMap;\r
+ }\r
+} \r