1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.*; 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 RenameRelation extends UnaryAlgebra { 32 private static final String RCSRevision = "$Revision: 1.8 $"; 33 private static final String RCSName = "$Name: $"; 34 35 private static final char DEFAULT_PREFIX = 'r'; 36 37 private String _name = null; 38 private Set _providedTableInstances = Collections.singleton(this); 39 40 public RenameRelation(IDProvider provider) { 41 setName(provider); 42 } 43 44 public RenameRelation(Expression relation, IDProvider provider) { 45 super(relation); 46 _name = relation.getName(); 47 setName(provider); 48 } 49 50 public RenameRelation(Expression relation, String name) { 51 super(relation); 52 setName(name); 53 } 54 55 synchronized Object clone(Map clonedExprs) throws CloneNotSupportedException { 56 RenameRelation retVal = (RenameRelation) super.clone(clonedExprs); 57 retVal.setName(_name); 58 retVal._providedTableInstances = Collections.singleton(retVal); 59 60 clonedExprs.put(this, retVal); 61 return retVal; 62 } 63 64 public boolean equals(Object o) { 65 if (o == this) 66 return true; 67 if (!(o instanceof RenameRelation)) 68 return false; 69 70 RenameRelation p = (RenameRelation) o; 71 if (!getName().equals(p.getName())) 72 return false; 73 return true; 74 } 75 76 public int hashCode() { 77 return _name.hashCode(); 78 } 79 80 85 public String getName() { 86 return _name; 87 } 88 89 public String getUniqueName() { 90 return _name; 91 } 92 93 98 public void setName(String aName) { 99 _name = aName; 100 } 101 102 public void setName(IDProvider provider) { 103 if (_name == null) 105 _name = DEFAULT_PREFIX + provider.getID(); 106 else 107 _name += provider.getID(); 108 } 109 110 public List getOperands() { 111 return null; 112 } 113 114 public boolean replaceChild(Expression oldChild, Expression newChild) { 115 boolean retVal = false; 116 if (getOperand() == oldChild) { 117 setOperand(newChild); 118 retVal = true; 119 } 120 return retVal; 121 } 122 123 public Set providedTableInstances() { 124 return _providedTableInstances; 125 } 126 127 public Set visibleTableInstances() { 128 return _providedTableInstances; 129 } 130 131 public AttributeExpression findNonNullAttribute() { 132 AttributeExpression ret = ((Relation) _operand).findNonNullAttribute(); 133 if (ret != null) 134 ret.setTableInstance(this); 135 return ret; 136 } 137 138 public List getKeys() { 139 return _keys; 140 } 141 public String pprint() { 142 return "renameRelation(" + getOperand().pprint() + " AS " + getName() + ")"; 143 } 144 145 public SqlExpression accept(GenSqlVisitor visitor) throws SqlWrapperException { 146 return visitor.visit(this); 147 } 148 149 public void accept(AlgebraVisitor visitor) throws SqlWrapperException { 150 visitor.visit(this); 151 } 152 153 } 156 | Popular Tags |