1 | /* |
2 | |
3 | Derby - Class org.apache.derby.iapi.sql.dictionary.AliasDescriptor |
4 | |
5 | Copyright 1999, 2004 The Apache Software Foundation or its licensors, as applicable. |
6 | |
7 | Licensed under the Apache License, Version 2.0 (the "License"); |
8 | you may not use this file except in compliance with the License. |
9 | You may obtain a copy of the License at |
10 | |
11 | http://www.apache.org/licenses/LICENSE-2.0 |
12 | |
13 | Unless required by applicable law or agreed to in writing, software |
14 | distributed under the License is distributed on an "AS IS" BASIS, |
15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | See the License for the specific language governing permissions and |
17 | limitations under the License. |
18 | |
19 | */ |
20 | |
21 | package org.apache.derby.iapi.sql.dictionary; |
22 | |
23 | import org.apache.derby.iapi.sql.depend.Provider; |
24 | |
25 | import org.apache.derby.iapi.error.StandardException; |
26 | import org.apache.derby.iapi.services.sanity.SanityManager; |
27 | |
28 | import org.apache.derby.catalog.AliasInfo; |
29 | |
30 | import org.apache.derby.catalog.UUID; |
31 | |
32 | import org.apache.derby.catalog.AliasInfo; |
33 | import org.apache.derby.catalog.DependableFinder; |
34 | import org.apache.derby.catalog.Dependable; |
35 | import org.apache.derby.catalog.UUID; |
36 | import org.apache.derby.iapi.services.io.StoredFormatIds; |
37 | |
38 | /** |
39 | * This class represents an Alias Descriptor. |
40 | * The public methods for this class are: |
41 | * |
42 | * <ol> |
43 | * <li>getUUID</li> |
44 | * <li>getJavaClassName</li> |
45 | * <li>getAliasType</li> |
46 | * <li>getNameSpace</li> |
47 | * <li>getSystemAlias</li> |
48 | * <li>getAliasId</li> |
49 | * </ol> |
50 | * |
51 | * @author Jerry Brenner |
52 | */ |
53 | |
54 | public final class AliasDescriptor |
55 | extends TupleDescriptor |
56 | implements UniqueTupleDescriptor, Provider |
57 | { |
58 | private UUID aliasID; |
59 | private String aliasName; |
60 | private UUID schemaID; |
61 | private String javaClassName; |
62 | private char aliasType; |
63 | private char nameSpace; |
64 | private boolean systemAlias; |
65 | private AliasInfo aliasInfo; |
66 | private String specificName; |
67 | |
68 | /** |
69 | * Constructor for a AliasDescriptor |
70 | * |
71 | * @param dataDictionary The data dictionary that this descriptor lives in |
72 | * @param aliasID The UUID for this alias |
73 | * @param aliasName The name of the method alias |
74 | * @param schemaID The UUID for this alias's schema |
75 | * @param javaClassName The java class name of the alias |
76 | * @param aliasType The alias type |
77 | * @param nameSpace The alias name space |
78 | * @param aliasInfo The AliasInfo for the alias |
79 | * |
80 | */ |
81 | |
82 | public AliasDescriptor( DataDictionary dataDictionary, UUID aliasID, |
83 | String aliasName, UUID schemaID, String javaClassName, |
84 | char aliasType, char nameSpace, boolean systemAlias, |
85 | AliasInfo aliasInfo, String specificName) |
86 | { |
87 | super( dataDictionary ); |
88 | |
89 | this.aliasID = aliasID; |
90 | this.aliasName = aliasName; |
91 | this.schemaID = schemaID; |
92 | this.javaClassName = javaClassName; |
93 | this.aliasType = aliasType; |
94 | this.nameSpace = nameSpace; |
95 | this.systemAlias = systemAlias; |
96 | this.aliasInfo = aliasInfo; |
97 | if (specificName == null) |
98 | specificName = dataDictionary.getSystemSQLName(); |
99 | this.specificName = specificName; |
100 | } |
101 | |
102 | // Interface methods |
103 | |
104 | /** |
105 | * Gets the UUID of the method alias. |
106 | * |
107 | * @return The UUID String of the method alias. |
108 | */ |
109 | public UUID getUUID() |
110 | { |
111 | return aliasID; |
112 | } |
113 | |
114 | /** |
115 | * Gets the UUID of the schema for this method alias. |
116 | * |
117 | * @return The UUID String of the schema id. |
118 | */ |
119 | public UUID getSchemaUUID() |
120 | { |
121 | return schemaID; |
122 | } |
123 | |
124 | /** |
125 | * Gets the java class name of the alias. |
126 | * |
127 | * @return The java class name of the alias. |
128 | */ |
129 | public String getJavaClassName() |
130 | { |
131 | return javaClassName; |
132 | } |
133 | |
134 | |
135 | /** |
136 | * Gets the type of the alias. |
137 | * |
138 | * @return The type of the alias. |
139 | */ |
140 | public char getAliasType() |
141 | { |
142 | return aliasType; |
143 | } |
144 | |
145 | /** |
146 | * Gets the name space of the alias. |
147 | * |
148 | * @return The name space of the alias. |
149 | */ |
150 | public char getNameSpace() |
151 | { |
152 | return nameSpace; |
153 | } |
154 | |
155 | /** |
156 | * Gets whether or not the alias is a system alias. |
157 | * |
158 | * @return Whether or not the alias is a system alias. |
159 | */ |
160 | public boolean getSystemAlias() |
161 | { |
162 | return systemAlias; |
163 | } |
164 | |
165 | /** |
166 | * Gests the AliasInfo for the alias. |
167 | * |
168 | * @return The AliasInfo for the alias. |
169 | */ |
170 | public AliasInfo getAliasInfo() |
171 | { |
172 | return aliasInfo; |
173 | } |
174 | |
175 | |
176 | // /** |
177 | // * Sets the ID of the method alias |
178 | // * |
179 | // * @param aliasID The UUID of the method alias to be set in the descriptor |
180 | // * |
181 | // * @return Nothing |
182 | // */ |
183 | // public void setAliasID(UUID aliasID) |
184 | // { |
185 | // this.aliasID = aliasID; |
186 | // } |
187 | |
188 | /** |
189 | * Convert the AliasDescriptor to a String. |
190 | * |
191 | * @return A String representation of this AliasDescriptor |
192 | */ |
193 | |
194 | public String toString() |
195 | { |
196 | if (SanityManager.DEBUG) |
197 | { |
198 | return "aliasID: " + aliasID + "\n" + |
199 | "aliasName: " + aliasName + "\n" + |
200 | "schemaID: " + schemaID + "\n" + |
201 | "javaClassName: " + javaClassName + "\n" + |
202 | "aliasType: " + aliasType + "\n" + |
203 | "nameSpace: " + nameSpace + "\n" + |
204 | "systemAlias: " + systemAlias + "\n" + |
205 | "aliasInfo: " + aliasInfo + "\n"; |
206 | } |
207 | else |
208 | { |
209 | return ""; |
210 | } |
211 | } |
212 | |
213 | // Methods so that we can put AliasDescriptors on hashed lists |
214 | |
215 | /** |
216 | * Determine if two AliasDescriptors are the same. |
217 | * |
218 | * @param otherObject other descriptor |
219 | * |
220 | * @return true if they are the same, false otherwise |
221 | */ |
222 | |
223 | public boolean equals(Object otherObject) |
224 | { |
225 | if (!(otherObject instanceof AliasDescriptor)) |
226 | { return false; } |
227 | |
228 | AliasDescriptor other = (AliasDescriptor) otherObject; |
229 | |
230 | return aliasID.equals( other.getUUID() ); |
231 | } |
232 | |
233 | /** |
234 | * Get a hashcode for this AliasDescriptor |
235 | * |
236 | * @return hashcode |
237 | */ |
238 | public int hashCode() |
239 | { |
240 | return aliasID.hashCode(); |
241 | } |
242 | |
243 | // |
244 | // Provider interface |
245 | // |
246 | |
247 | /** |
248 | @return the stored form of this provider |
249 | representation |
250 | |
251 | @see Dependable#getDependableFinder |
252 | */ |
253 | public DependableFinder getDependableFinder() |
254 | { |
255 | return getDependableFinder(StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID); |
256 | } |
257 | |
258 | /** |
259 | * Return the name of this Provider. (Useful for errors.) |
260 | * |
261 | * @return String The name of this provider. |
262 | */ |
263 | public String getObjectName() |
264 | { |
265 | return aliasName; |
266 | } |
267 | |
268 | /** |
269 | * Get the provider's UUID |
270 | * |
271 | * @return String The provider's UUID |
272 | */ |
273 | public UUID getObjectID() |
274 | { |
275 | return aliasID; |
276 | } |
277 | |
278 | /** |
279 | * Get the provider's type. |
280 | * |
281 | * @return String The provider's type. |
282 | */ |
283 | public String getClassType() |
284 | { |
285 | return Dependable.ALIAS; |
286 | } |
287 | |
288 | /** @see TupleDescriptor#getDescriptorType */ |
289 | public String getDescriptorType() |
290 | { |
291 | return getAliasType(aliasType); |
292 | } |
293 | |
294 | public static final String getAliasType(char nameSpace) |
295 | { |
296 | switch (nameSpace) |
297 | { |
298 | case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: |
299 | return "PROCEDURE"; |
300 | case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: |
301 | return "FUNCTION"; |
302 | case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: |
303 | return "SYNONYM"; |
304 | } |
305 | return null; |
306 | } |
307 | |
308 | /** @see TupleDescriptor#getDescriptorName */ |
309 | public String getDescriptorName() |
310 | { |
311 | return aliasName; |
312 | } |
313 | |
314 | |
315 | /** |
316 | Return the specific name for this object. |
317 | */ |
318 | public String getSpecificName() |
319 | { |
320 | return specificName; |
321 | } |
322 | } |