001: /*
002:
003: Derby - Class org.apache.derby.iapi.sql.dictionary.AliasDescriptor
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.iapi.sql.dictionary;
023:
024: import org.apache.derby.iapi.sql.depend.Provider;
025:
026: import org.apache.derby.iapi.error.StandardException;
027: import org.apache.derby.iapi.services.sanity.SanityManager;
028:
029: import org.apache.derby.catalog.AliasInfo;
030:
031: import org.apache.derby.catalog.UUID;
032:
033: import org.apache.derby.catalog.AliasInfo;
034: import org.apache.derby.catalog.DependableFinder;
035: import org.apache.derby.catalog.Dependable;
036: import org.apache.derby.catalog.UUID;
037: import org.apache.derby.iapi.services.io.StoredFormatIds;
038:
039: /**
040: * This class represents an Alias Descriptor.
041: * The public methods for this class are:
042: *
043: * <ol>
044: * <li>getUUID</li>
045: * <li>getJavaClassName</li>
046: * <li>getAliasType</li>
047: * <li>getNameSpace</li>
048: * <li>getSystemAlias</li>
049: * <li>getAliasId</li>
050: * </ol>
051: *
052: * @author Jerry Brenner
053: */
054:
055: public final class AliasDescriptor extends TupleDescriptor implements
056: UniqueTupleDescriptor, Provider {
057: private final UUID aliasID;
058: private final String aliasName;
059: private final UUID schemaID;
060: private final String javaClassName;
061: private final char aliasType;
062: private final char nameSpace;
063: private final boolean systemAlias;
064: private final AliasInfo aliasInfo;
065: private final String specificName;
066:
067: /**
068: * Constructor for a AliasDescriptor
069: *
070: * @param dataDictionary The data dictionary that this descriptor lives in
071: * @param aliasID The UUID for this alias
072: * @param aliasName The name of the method alias
073: * @param schemaID The UUID for this alias's schema
074: * @param javaClassName The java class name of the alias
075: * @param aliasType The alias type
076: * @param nameSpace The alias name space
077: * @param aliasInfo The AliasInfo for the alias
078: *
079: */
080:
081: public AliasDescriptor(DataDictionary dataDictionary, UUID aliasID,
082: String aliasName, UUID schemaID, String javaClassName,
083: char aliasType, char nameSpace, boolean systemAlias,
084: AliasInfo aliasInfo, String specificName) {
085: super (dataDictionary);
086:
087: this .aliasID = aliasID;
088: this .aliasName = aliasName;
089: this .schemaID = schemaID;
090: this .javaClassName = javaClassName;
091: this .aliasType = aliasType;
092: this .nameSpace = nameSpace;
093: this .systemAlias = systemAlias;
094: this .aliasInfo = aliasInfo;
095: if (specificName == null)
096: specificName = dataDictionary.getSystemSQLName();
097: this .specificName = specificName;
098: }
099:
100: // Interface methods
101:
102: /**
103: * Gets the UUID of the method alias.
104: *
105: * @return The UUID String of the method alias.
106: */
107: public UUID getUUID() {
108: return aliasID;
109: }
110:
111: /**
112: * Gets the UUID of the schema for this method alias.
113: *
114: * @return The UUID String of the schema id.
115: */
116: public UUID getSchemaUUID() {
117: return schemaID;
118: }
119:
120: /**
121: * Gets the java class name of the alias.
122: *
123: * @return The java class name of the alias.
124: */
125: public String getJavaClassName() {
126: return javaClassName;
127: }
128:
129: /**
130: * Gets the type of the alias.
131: *
132: * @return The type of the alias.
133: */
134: public char getAliasType() {
135: return aliasType;
136: }
137:
138: /**
139: * Gets the name space of the alias.
140: *
141: * @return The name space of the alias.
142: */
143: public char getNameSpace() {
144: return nameSpace;
145: }
146:
147: /**
148: * Gets whether or not the alias is a system alias.
149: *
150: * @return Whether or not the alias is a system alias.
151: */
152: public boolean getSystemAlias() {
153: return systemAlias;
154: }
155:
156: /**
157: * Gests the AliasInfo for the alias.
158: *
159: * @return The AliasInfo for the alias.
160: */
161: public AliasInfo getAliasInfo() {
162: return aliasInfo;
163: }
164:
165: // /**
166: // * Sets the ID of the method alias
167: // *
168: // * @param aliasID The UUID of the method alias to be set in the descriptor
169: // *
170: // * @return Nothing
171: // */
172: // public void setAliasID(UUID aliasID)
173: // {
174: // this.aliasID = aliasID;
175: // }
176:
177: /**
178: * Convert the AliasDescriptor to a String.
179: *
180: * @return A String representation of this AliasDescriptor
181: */
182:
183: public String toString() {
184: if (SanityManager.DEBUG) {
185: return "aliasID: " + aliasID + "\n" + "aliasName: "
186: + aliasName + "\n" + "schemaID: " + schemaID + "\n"
187: + "javaClassName: " + javaClassName + "\n"
188: + "aliasType: " + aliasType + "\n" + "nameSpace: "
189: + nameSpace + "\n" + "systemAlias: " + systemAlias
190: + "\n" + "aliasInfo: " + aliasInfo + "\n";
191: } else {
192: return "";
193: }
194: }
195:
196: // Methods so that we can put AliasDescriptors on hashed lists
197:
198: /**
199: * Determine if two AliasDescriptors are the same.
200: *
201: * @param otherObject other descriptor
202: *
203: * @return true if they are the same, false otherwise
204: */
205:
206: public boolean equals(Object otherObject) {
207: if (!(otherObject instanceof AliasDescriptor)) {
208: return false;
209: }
210:
211: AliasDescriptor other = (AliasDescriptor) otherObject;
212:
213: return aliasID.equals(other.getUUID());
214: }
215:
216: /**
217: * Get a hashcode for this AliasDescriptor
218: *
219: * @return hashcode
220: */
221: public int hashCode() {
222: return aliasID.hashCode();
223: }
224:
225: //
226: // Provider interface
227: //
228:
229: /**
230: @return the stored form of this provider
231: representation
232:
233: @see Dependable#getDependableFinder
234: */
235: public DependableFinder getDependableFinder() {
236: return getDependableFinder(StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID);
237: }
238:
239: /**
240: * Return the name of this Provider. (Useful for errors.)
241: *
242: * @return String The name of this provider.
243: */
244: public String getObjectName() {
245: return aliasName;
246: }
247:
248: /**
249: * Get the provider's UUID
250: *
251: * @return String The provider's UUID
252: */
253: public UUID getObjectID() {
254: return aliasID;
255: }
256:
257: /**
258: * Get the provider's type.
259: *
260: * @return String The provider's type.
261: */
262: public String getClassType() {
263: return Dependable.ALIAS;
264: }
265:
266: /** @see TupleDescriptor#getDescriptorType */
267: public String getDescriptorType() {
268: return getAliasType(aliasType);
269: }
270:
271: public static final String getAliasType(char nameSpace) {
272: switch (nameSpace) {
273: case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
274: return "PROCEDURE";
275: case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
276: return "FUNCTION";
277: case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
278: return "SYNONYM";
279: }
280: return null;
281: }
282:
283: /** @see TupleDescriptor#getDescriptorName */
284: public String getDescriptorName() {
285: return aliasName;
286: }
287:
288: /**
289: Return the specific name for this object.
290: */
291: public String getSpecificName() {
292: return specificName;
293: }
294:
295: /**
296: * Functions are persistent unless they are in the SYSFUN schema.
297: *
298: */
299: public boolean isPersistent() {
300: return !getSchemaUUID().toString().equals(
301: SchemaDescriptor.SYSFUN_SCHEMA_UUID);
302: }
303: }
|