KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.ReferencedTablesVisitor
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 import org.apache.derby.iapi.util.JBitSet;
31
32 /**
33  * Build a JBitSet of all of the referenced tables in the tree.
34  *
35  * @author jerry
36  */

37 public class ReferencedTablesVisitor implements Visitor
38 {
39     private JBitSet tableMap;
40
41     public ReferencedTablesVisitor(JBitSet tableMap)
42     {
43         this.tableMap = tableMap;
44     }
45
46
47     ////////////////////////////////////////////////
48
//
49
// VISITOR INTERFACE
50
//
51
////////////////////////////////////////////////
52

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

63     public Visitable visit(Visitable node)
64         throws StandardException
65     {
66         if (node instanceof ColumnReference)
67         {
68             ((ColumnReference)node).getTablesReferenced(tableMap);
69         }
70         else if (node instanceof Predicate)
71         {
72             Predicate pred = (Predicate) node;
73             tableMap.or(pred.getReferencedSet());
74         }
75         else if (node instanceof ResultSetNode)
76         {
77             ResultSetNode rs = (ResultSetNode) node;
78             tableMap.or(rs.getReferencedTableMap());
79         }
80
81         return node;
82     }
83
84     /**
85      * No need to go below a Predicate or ResultSet.
86      *
87      * @return Whether or not to go below the node.
88      */

89     public boolean skipChildren(Visitable node)
90     {
91         return (node instanceof Predicate ||
92                 node instanceof ResultSetNode);
93     }
94
95     public boolean stopTraversal()
96     {
97         return false;
98     }
99     ////////////////////////////////////////////////
100
//
101
// CLASS INTERFACE
102
//
103
////////////////////////////////////////////////
104
JBitSet getTableMap()
105     {
106         return tableMap;
107     }
108 }
109
Popular Tags