1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.List ; 26 import java.util.Map ; 27 28 import org.xquark.extractor.common.Debug; 29 import org.xquark.extractor.common.SqlWrapperException; 30 31 public final class RemoveProjectGoUpVisitor extends DefaultAlgebraVisitor { 32 private static final String RCSRevision = "$Revision: 1.4 $"; 33 private static final String RCSName = "$Name: $"; 34 35 private RemoveProjectReplaceVisitor _rprv = new RemoveProjectReplaceVisitor(); 36 37 38 private Expression _endNode = null; 39 40 public RemoveProjectGoUpVisitor(){ 41 } 42 43 public RemoveProjectGoUpVisitor(Map replaceMap){ 44 setMap(replaceMap); 45 } 46 47 57 public void setMap(Map replaceMap) { 58 _rprv.setMap(replaceMap); 59 } 60 61 public void setEndNode(Expression endNode) { 62 _endNode = endNode; 63 } 64 65 public Expression getEndNode() { 66 return _endNode; 67 } 68 69 public void visit(Expression arg) throws SqlWrapperException { 70 Debug.assertTrue(false, "NYI!! for " + arg.toString()); 72 } 74 75 public void visit(BinaryAlgebra arg) throws SqlWrapperException { 76 78 79 if (getEndNode() != arg) { 80 arg.getFather().accept(this); 81 } 82 83 } 85 86 106 121 public void visit(BinOpOuterJoin arg) throws SqlWrapperException { 122 124 List list = arg.getPredicateList(); 125 Debug.assertTrue(null!=list,"null!=list"); 126 Expression expr = null ; 127 for (int i = 0; i < list.size(); i++) { 128 expr = (Expression)list.get(i); 129 expr.accept(_rprv); 130 } 131 132 if (getEndNode() != arg) { 133 arg.getFather().accept(this); 134 } 135 136 } 138 139 144 public void visit(FunAggregate arg) throws SqlWrapperException { 145 } 148 149 154 public void visit(Join arg) throws SqlWrapperException { 155 157 List list = arg.getPredicateList(); 158 if (list != null) { 159 Expression expr = null ; 160 for (int i = 0; i < list.size(); i++) { 161 expr = (Expression)list.get(i); 162 expr.accept(_rprv); 163 } 164 } 165 166 if (getEndNode() != arg) { 167 arg.getFather().accept(this); 168 } 169 170 } 172 173 public void visit(Literal arg) throws SqlWrapperException { 174 } 177 178 208 public void visit(RenameItem arg) throws SqlWrapperException { 209 211 } 213 214 public void visit(RenameRelation arg) throws SqlWrapperException { 215 217 218 _rprv.updateTableInstance(arg); 219 221 222 Expression father = arg.getFather(); 223 boolean replaced = father.replaceChild(arg, arg.getOperand()); 224 Debug.assertTrue(replaced , "replaced"); 225 arg.setFather(null); 226 228 if (getEndNode() != arg) { 229 father.accept(this); 230 } 231 232 } 234 235 241 246 public void visit(UnaryAtomicOp arg) throws SqlWrapperException { 247 249 if (getEndNode() != arg) { 250 arg.getFather().accept(this); 251 } 252 253 } 255 256 261 public void visit(UnOpProject arg) throws SqlWrapperException { 262 264 List list = arg.getItemList(); 265 Debug.assertTrue(null!=list,"null!=list"); 266 Expression expr = null ; 267 for (int i = 0; i < list.size(); i++) { 268 expr = (Expression)list.get(i); 269 expr.accept(_rprv); 270 } 271 272 UnOpSort sort = arg.getAssociatedSort(); 273 if (null != sort) { 274 SortSpecification spec = null; 275 list = sort.getSortSpecificationList(); 276 for (int i = 0; i < list.size(); i++) { 277 spec = (SortSpecification)list.get(i); 278 expr = spec.getSortExpression(); 279 expr.accept(_rprv); 280 } 281 } 282 283 if (getEndNode() != arg) { 284 arg.getFather().accept(this); 285 } 286 287 } 289 290 public void visit(UnOpRestrict arg) throws SqlWrapperException { 291 293 List list = arg.getPredicateList(); 294 Debug.assertTrue(null!=list,"null!=list"); 295 Expression expr = null ; 296 for (int i = 0; i < list.size(); i++) { 297 expr = (Expression)list.get(i); 298 expr.accept(_rprv); 299 } 300 301 if (getEndNode() != arg) { 302 arg.getFather().accept(this); 303 } 304 305 } 307 308 public void visit(UnOpSort arg) throws SqlWrapperException { 309 311 List list = arg.getSortSpecificationList(); 312 Debug.assertTrue(null!=list,"null!=list"); 313 SortSpecification spec = null; 314 Expression expr = null ; 315 for (int i = 0; i < list.size(); i++) { 316 spec = (SortSpecification)list.get(i); 317 expr = spec.getSortExpression(); 318 expr.accept(_rprv); 319 } 320 321 if (getEndNode() != arg) { 322 arg.getFather().accept(this); 323 } 324 325 } 327 328 public String printMap(){ 329 return _rprv.printMap(); 330 } 331 } 332 | Popular Tags |