KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > extractor > algebra > RenameRelation


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

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 JavaDoc RCSRevision = "$Revision: 1.8 $";
33     private static final String JavaDoc RCSName = "$Name: $";
34
35     private static final char DEFAULT_PREFIX = 'r';
36
37     private String JavaDoc _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 JavaDoc name) {
51         super(relation);
52         setName(name);
53     }
54
55     synchronized Object JavaDoc clone(Map clonedExprs) throws CloneNotSupportedException JavaDoc {
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 JavaDoc 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     /**
81      * Access method for the _name property.
82      *
83      * @return the current value of the _name property
84      */

85     public String JavaDoc getName() {
86         return _name;
87     }
88
89     public String JavaDoc getUniqueName() {
90         return _name;
91     }
92
93     /**
94      * Sets the value of the _name property.
95      *
96      * @param aName the new value of the _name property
97      */

98     public void setName(String JavaDoc aName) {
99         _name = aName;
100     }
101
102     public void setName(IDProvider provider) {
103         // Note: no need to synchronize since private per thread alias
104
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 JavaDoc 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     // NOTE; Expression#deepEquals(Object) not overridden cause alias names should
154
// not be considered for expression equality
155
}
156
Popular Tags