KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > sql > dictionary > AliasDescriptor


1 /*
2
3    Derby - Class org.apache.derby.iapi.sql.dictionary.AliasDescriptor
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.iapi.sql.dictionary;
23
24 import org.apache.derby.iapi.sql.depend.Provider;
25
26 import org.apache.derby.iapi.error.StandardException;
27 import org.apache.derby.iapi.services.sanity.SanityManager;
28
29 import org.apache.derby.catalog.AliasInfo;
30
31 import org.apache.derby.catalog.UUID;
32
33 import org.apache.derby.catalog.AliasInfo;
34 import org.apache.derby.catalog.DependableFinder;
35 import org.apache.derby.catalog.Dependable;
36 import org.apache.derby.catalog.UUID;
37 import org.apache.derby.iapi.services.io.StoredFormatIds;
38
39 /**
40  * This class represents an Alias Descriptor.
41  * The public methods for this class are:
42  *
43  * <ol>
44  * <li>getUUID</li>
45  * <li>getJavaClassName</li>
46  * <li>getAliasType</li>
47  * <li>getNameSpace</li>
48  * <li>getSystemAlias</li>
49  * <li>getAliasId</li>
50  * </ol>
51  *
52  * @author Jerry Brenner
53  */

54
55 public final class AliasDescriptor
56     extends TupleDescriptor
57     implements UniqueTupleDescriptor, Provider
58 {
59     private final UUID aliasID;
60     private final String JavaDoc aliasName;
61     private final UUID schemaID;
62     private final String JavaDoc javaClassName;
63     private final char aliasType;
64     private final char nameSpace;
65     private final boolean systemAlias;
66     private final AliasInfo aliasInfo;
67     private final String JavaDoc specificName;
68
69     /**
70      * Constructor for a AliasDescriptor
71      *
72      * @param dataDictionary The data dictionary that this descriptor lives in
73      * @param aliasID The UUID for this alias
74      * @param aliasName The name of the method alias
75      * @param schemaID The UUID for this alias's schema
76      * @param javaClassName The java class name of the alias
77      * @param aliasType The alias type
78      * @param nameSpace The alias name space
79      * @param aliasInfo The AliasInfo for the alias
80      *
81      */

82
83     public AliasDescriptor( DataDictionary dataDictionary, UUID aliasID,
84                               String JavaDoc aliasName, UUID schemaID, String JavaDoc javaClassName,
85                               char aliasType, char nameSpace, boolean systemAlias,
86                               AliasInfo aliasInfo, String JavaDoc specificName)
87     {
88         super( dataDictionary );
89
90         this.aliasID = aliasID;
91         this.aliasName = aliasName;
92         this.schemaID = schemaID;
93         this.javaClassName = javaClassName;
94         this.aliasType = aliasType;
95         this.nameSpace = nameSpace;
96         this.systemAlias = systemAlias;
97         this.aliasInfo = aliasInfo;
98         if (specificName == null)
99             specificName = dataDictionary.getSystemSQLName();
100         this.specificName = specificName;
101     }
102
103     // Interface methods
104

105     /**
106      * Gets the UUID of the method alias.
107      *
108      * @return The UUID String of the method alias.
109      */

110     public UUID getUUID()
111     {
112         return aliasID;
113     }
114
115     /**
116      * Gets the UUID of the schema for this method alias.
117      *
118      * @return The UUID String of the schema id.
119      */

120     public UUID getSchemaUUID()
121     {
122         return schemaID;
123     }
124
125     /**
126      * Gets the java class name of the alias.
127      *
128      * @return The java class name of the alias.
129      */

130     public String JavaDoc getJavaClassName()
131     {
132         return javaClassName;
133     }
134
135
136     /**
137      * Gets the type of the alias.
138      *
139      * @return The type of the alias.
140      */

141     public char getAliasType()
142     {
143         return aliasType;
144     }
145
146     /**
147      * Gets the name space of the alias.
148      *
149      * @return The name space of the alias.
150      */

151     public char getNameSpace()
152     {
153         return nameSpace;
154     }
155
156     /**
157      * Gets whether or not the alias is a system alias.
158      *
159      * @return Whether or not the alias is a system alias.
160      */

161     public boolean getSystemAlias()
162     {
163         return systemAlias;
164     }
165
166     /**
167      * Gests the AliasInfo for the alias.
168      *
169      * @return The AliasInfo for the alias.
170      */

171     public AliasInfo getAliasInfo()
172     {
173         return aliasInfo;
174     }
175
176
177 // /**
178
// * Sets the ID of the method alias
179
// *
180
// * @param aliasID The UUID of the method alias to be set in the descriptor
181
// *
182
// * @return Nothing
183
// */
184
// public void setAliasID(UUID aliasID)
185
// {
186
// this.aliasID = aliasID;
187
// }
188

189     /**
190      * Convert the AliasDescriptor to a String.
191      *
192      * @return A String representation of this AliasDescriptor
193      */

194
195     public String JavaDoc toString()
196     {
197         if (SanityManager.DEBUG)
198         {
199             return "aliasID: " + aliasID + "\n" +
200                 "aliasName: " + aliasName + "\n" +
201                 "schemaID: " + schemaID + "\n" +
202                 "javaClassName: " + javaClassName + "\n" +
203                 "aliasType: " + aliasType + "\n" +
204                 "nameSpace: " + nameSpace + "\n" +
205                 "systemAlias: " + systemAlias + "\n" +
206                 "aliasInfo: " + aliasInfo + "\n";
207         }
208         else
209         {
210             return "";
211         }
212     }
213
214     // Methods so that we can put AliasDescriptors on hashed lists
215

216     /**
217       * Determine if two AliasDescriptors are the same.
218       *
219       * @param otherObject other descriptor
220       *
221       * @return true if they are the same, false otherwise
222       */

223
224     public boolean equals(Object JavaDoc otherObject)
225     {
226         if (!(otherObject instanceof AliasDescriptor))
227         { return false; }
228
229         AliasDescriptor other = (AliasDescriptor) otherObject;
230
231         return aliasID.equals( other.getUUID() );
232     }
233
234     /**
235       * Get a hashcode for this AliasDescriptor
236       *
237       * @return hashcode
238       */

239     public int hashCode()
240     {
241         return aliasID.hashCode();
242     }
243
244     //
245
// Provider interface
246
//
247

248     /**
249         @return the stored form of this provider
250             representation
251
252             @see Dependable#getDependableFinder
253      */

254     public DependableFinder getDependableFinder()
255     {
256         return getDependableFinder(StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID);
257     }
258
259     /**
260      * Return the name of this Provider. (Useful for errors.)
261      *
262      * @return String The name of this provider.
263      */

264     public String JavaDoc getObjectName()
265     {
266         return aliasName;
267     }
268
269     /**
270      * Get the provider's UUID
271      *
272      * @return String The provider's UUID
273      */

274     public UUID getObjectID()
275     {
276         return aliasID;
277     }
278
279     /**
280      * Get the provider's type.
281      *
282      * @return String The provider's type.
283      */

284     public String JavaDoc getClassType()
285     {
286         return Dependable.ALIAS;
287     }
288     
289     /** @see TupleDescriptor#getDescriptorType */
290     public String JavaDoc getDescriptorType()
291     {
292         return getAliasType(aliasType);
293     }
294     
295     public static final String JavaDoc getAliasType(char nameSpace)
296     {
297         switch (nameSpace)
298         {
299             case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
300                 return "PROCEDURE";
301             case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
302                 return "FUNCTION";
303             case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
304                 return "SYNONYM";
305         }
306         return null;
307     }
308
309     /** @see TupleDescriptor#getDescriptorName */
310     public String JavaDoc getDescriptorName()
311     {
312         return aliasName;
313     }
314
315
316     /**
317         Return the specific name for this object.
318     */

319     public String JavaDoc getSpecificName()
320     {
321         return specificName;
322     }
323     
324     /**
325      * Functions are persistent unless they are in the SYSFUN schema.
326      *
327      */

328     public boolean isPersistent()
329     {
330         return !getSchemaUUID().toString().equals(SchemaDescriptor.SYSFUN_SCHEMA_UUID);
331     }
332 }
333
Popular Tags