1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.Map ; 26 27 import org.xquark.extractor.common.SqlWrapperException; 28 import org.xquark.extractor.runtime.IDProvider; 29 import org.xquark.extractor.sql.SqlExpression; 30 31 public final class RenameItem extends UnaryAtomicOp 32 { 33 private static final String RCSRevision = "$Revision: 1.6 $"; 34 private static final String RCSName = "$Name: $"; 35 36 protected String _name; 37 private static final String ATTRIBUTE_ALIAS_PREFIX = "a"; 38 39 public RenameItem(Expression Expr, IDProvider provider) 40 { 41 super(Expr); 42 setName(getUniqueName(provider)); 43 } 44 45 public RenameItem(Expression Expr, String name) 46 { 47 super (Expr); 48 setName(name); 49 } 50 51 public RenameItem(Expression Expr, String name, IDProvider provider) 52 { 53 super (Expr); 54 setName(name, provider); 55 } 56 57 synchronized Object clone(Map clonedExprs) throws CloneNotSupportedException 58 { 59 61 RenameItem retVal = (RenameItem)super.clone(clonedExprs); 62 retVal.setName(getName()); 63 64 clonedExprs.put(this, retVal); 65 return retVal; 67 } 68 69 74 public String getName() 75 { 76 return _name; 77 } 78 79 84 public void setName(String aName) 85 { 86 _name = aName; 87 } 88 89 public void setName(String aName, IDProvider provider) 90 { 91 _name = getUniqueName(aName, provider); 92 } 93 94 public boolean replaceChild(Expression oldChild, Expression newChild) 95 { 96 98 boolean retVal = false; 99 if (getOperand() == oldChild) { 100 setOperand(newChild); 101 retVal = true; 102 } 103 104 return retVal; 106 } 107 108 public String pprint () 109 { 110 return "renameItem(" + getOperand().pprint() + " AS " + getName() + ")"; 111 } 112 113 public SqlExpression accept (GenSqlVisitor visitor) throws SqlWrapperException 114 { 115 return visitor.visit(this); 116 } 117 118 public void accept (AlgebraVisitor visitor) throws SqlWrapperException 119 { 120 visitor.visit(this); 121 } 122 123 private String getUniqueName(String name, IDProvider provider) 124 { 125 String retVal = null; 126 if (name.length() > 20) 127 retVal = name.substring(0,19) + "_" + provider.getID(); 128 else 129 retVal = name + provider.getID(); 130 131 return retVal; 132 } 133 134 private String getUniqueName(IDProvider provider) 135 { 136 return getUniqueName(ATTRIBUTE_ALIAS_PREFIX, provider); 137 } 138 139 } 142 | Popular Tags |