1 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 import org.apache.derby.iapi.util.JBitSet; 27 28 import org.apache.derby.iapi.error.StandardException; 29 import org.apache.derby.iapi.services.sanity.SanityManager; 30 31 39 public class BaseTableNumbersVisitor implements Visitor 40 { 41 private JBitSet tableMap; 43 44 50 public BaseTableNumbersVisitor(JBitSet tableMap) 51 { 52 this.tableMap = tableMap; 53 } 54 55 61 protected void setTableMap(JBitSet tableMap) 62 { 63 this.tableMap = tableMap; 64 } 65 66 72 75 public Visitable visit(Visitable node) 76 throws StandardException 77 { 78 ResultColumn rc = null; 79 if (node instanceof ColumnReference) 80 { 81 rc = ((ColumnReference)node).getSource(); 85 86 if (rc == null) { 87 return node; 96 } 97 } 98 else if (node instanceof ResultColumn) 99 rc = (ResultColumn)rc; 100 else if (node instanceof SelectNode) 101 { 102 ((SelectNode)node).getFromList().accept(this); 105 } 106 else if (node instanceof FromBaseTable) { 107 tableMap.set(((FromBaseTable)node).getTableNumber()); 109 } 110 111 if (rc != null) 112 { 113 122 int baseTableNumber = rc.getTableNumber(); 123 if (baseTableNumber >= 0) { 124 131 ValueNode rcExpr = rc.getExpression(); 132 while (rcExpr instanceof VirtualColumnNode) { 133 rc = ((VirtualColumnNode)rcExpr).getSourceColumn(); 134 rcExpr = rc.getExpression(); 135 } 136 137 if (rcExpr instanceof ColumnReference) 138 rcExpr.accept(this); 140 else { 141 tableMap.set(baseTableNumber); 146 } 147 } 148 else if (node instanceof ColumnReference) { 149 ((ColumnReference)node).getTablesReferenced(tableMap); 153 } 154 } 155 156 return node; 157 } 158 159 162 public boolean skipChildren(Visitable node) 163 { 164 181 return (node instanceof FromBaseTable) || 182 (node instanceof SelectNode) || 183 (node instanceof PredicateList); 184 } 185 186 189 public boolean stopTraversal() 190 { 191 return false; 192 } 193 194 } 195 | Popular Tags |