--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.iapi.sql.dictionary.AliasDescriptor\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.iapi.sql.dictionary;\r
+\r
+import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;\r
+import org.apache.derby.iapi.sql.depend.DependencyManager;\r
+import org.apache.derby.iapi.sql.depend.Provider;\r
+import org.apache.derby.iapi.store.access.TransactionController;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.services.sanity.SanityManager;\r
+\r
+import org.apache.derby.catalog.AliasInfo;\r
+\r
+import org.apache.derby.catalog.UUID;\r
+\r
+import org.apache.derby.catalog.AliasInfo;\r
+import org.apache.derby.catalog.DependableFinder;\r
+import org.apache.derby.catalog.Dependable;\r
+import org.apache.derby.catalog.UUID;\r
+import org.apache.derby.iapi.services.io.StoredFormatIds;\r
+\r
+/**\r
+ * This class represents an Alias Descriptor. \r
+ * The public methods for this class are:\r
+ * \r
+ * <ol>\r
+ * <li>getUUID</li>\r
+ * <li>getJavaClassName</li>\r
+ * <li>getAliasType</li>\r
+ * <li>getNameSpace</li>\r
+ * <li>getSystemAlias</li>\r
+ * <li>getAliasId</li>\r
+ * </ol>\r
+ *\r
+ */\r
+\r
+public final class AliasDescriptor \r
+ extends TupleDescriptor\r
+ implements UniqueTupleDescriptor, Provider\r
+{\r
+ private final UUID aliasID;\r
+ private final String aliasName;\r
+ private final UUID schemaID;\r
+ private final String javaClassName;\r
+ private final char aliasType;\r
+ private final char nameSpace;\r
+ private final boolean systemAlias;\r
+ private final AliasInfo aliasInfo;\r
+ private final String specificName;\r
+\r
+ /**\r
+ * Constructor for a AliasDescriptor\r
+ *\r
+ * @param dataDictionary The data dictionary that this descriptor lives in\r
+ * @param aliasID The UUID for this alias\r
+ * @param aliasName The name of the method alias\r
+ * @param schemaID The UUID for this alias's schema\r
+ * @param javaClassName The java class name of the alias\r
+ * @param aliasType The alias type\r
+ * @param nameSpace The alias name space\r
+ * @param aliasInfo The AliasInfo for the alias\r
+ *\r
+ */\r
+\r
+ public AliasDescriptor( DataDictionary dataDictionary, UUID aliasID,\r
+ String aliasName, UUID schemaID, String javaClassName,\r
+ char aliasType, char nameSpace, boolean systemAlias,\r
+ AliasInfo aliasInfo, String specificName)\r
+ {\r
+ super( dataDictionary );\r
+\r
+ this.aliasID = aliasID;\r
+ this.aliasName = aliasName;\r
+ this.schemaID = schemaID;\r
+ this.javaClassName = javaClassName;\r
+ this.aliasType = aliasType;\r
+ this.nameSpace = nameSpace;\r
+ this.systemAlias = systemAlias;\r
+ this.aliasInfo = aliasInfo;\r
+ if (specificName == null)\r
+ specificName = dataDictionary.getSystemSQLName();\r
+ this.specificName = specificName;\r
+ }\r
+\r
+ // Interface methods\r
+\r
+ /**\r
+ * Gets the UUID of the method alias.\r
+ *\r
+ * @return The UUID String of the method alias.\r
+ */\r
+ public UUID getUUID()\r
+ {\r
+ return aliasID;\r
+ }\r
+\r
+ /**\r
+ * Gets the UUID of the schema for this method alias.\r
+ *\r
+ * @return The UUID String of the schema id.\r
+ */\r
+ public UUID getSchemaUUID()\r
+ {\r
+ return schemaID;\r
+ }\r
+\r
+ /**\r
+ * Gets the java class name of the alias.\r
+ *\r
+ * @return The java class name of the alias.\r
+ */\r
+ public String getJavaClassName()\r
+ {\r
+ return javaClassName;\r
+ }\r
+\r
+\r
+ /**\r
+ * Gets the type of the alias.\r
+ *\r
+ * @return The type of the alias.\r
+ */\r
+ public char getAliasType()\r
+ {\r
+ return aliasType;\r
+ }\r
+\r
+ /**\r
+ * Gets the name space of the alias.\r
+ *\r
+ * @return The name space of the alias.\r
+ */\r
+ public char getNameSpace()\r
+ {\r
+ return nameSpace;\r
+ }\r
+\r
+ /**\r
+ * Gets whether or not the alias is a system alias.\r
+ *\r
+ * @return Whether or not the alias is a system alias.\r
+ */\r
+ public boolean getSystemAlias()\r
+ {\r
+ return systemAlias;\r
+ }\r
+\r
+ /**\r
+ * Gests the AliasInfo for the alias.\r
+ *\r
+ * @return The AliasInfo for the alias.\r
+ */\r
+ public AliasInfo getAliasInfo()\r
+ {\r
+ return aliasInfo;\r
+ }\r
+\r
+\r
+// /**\r
+// * Sets the ID of the method alias\r
+// *\r
+// * @param aliasID The UUID of the method alias to be set in the descriptor\r
+// *\r
+// * @return Nothing\r
+// */\r
+// public void setAliasID(UUID aliasID)\r
+// {\r
+// this.aliasID = aliasID;\r
+// }\r
+\r
+ /**\r
+ * Convert the AliasDescriptor to a String.\r
+ *\r
+ * @return A String representation of this AliasDescriptor\r
+ */\r
+\r
+ public String toString()\r
+ {\r
+ if (SanityManager.DEBUG)\r
+ {\r
+ return "aliasID: " + aliasID + "\n" +\r
+ "aliasName: " + aliasName + "\n" +\r
+ "schemaID: " + schemaID + "\n" +\r
+ "javaClassName: " + javaClassName + "\n" +\r
+ "aliasType: " + aliasType + "\n" +\r
+ "nameSpace: " + nameSpace + "\n" +\r
+ "systemAlias: " + systemAlias + "\n" +\r
+ "aliasInfo: " + aliasInfo + "\n";\r
+ }\r
+ else\r
+ {\r
+ return "";\r
+ }\r
+ }\r
+\r
+ // Methods so that we can put AliasDescriptors on hashed lists\r
+\r
+ /**\r
+ * Determine if two AliasDescriptors are the same.\r
+ *\r
+ * @param otherObject other descriptor\r
+ *\r
+ * @return true if they are the same, false otherwise\r
+ */\r
+\r
+ public boolean equals(Object otherObject)\r
+ {\r
+ if (!(otherObject instanceof AliasDescriptor))\r
+ { return false; }\r
+\r
+ AliasDescriptor other = (AliasDescriptor) otherObject;\r
+\r
+ return aliasID.equals( other.getUUID() );\r
+ }\r
+\r
+ /**\r
+ * Get a hashcode for this AliasDescriptor\r
+ *\r
+ * @return hashcode\r
+ */\r
+ public int hashCode()\r
+ {\r
+ return aliasID.hashCode();\r
+ }\r
+\r
+ //\r
+ // Provider interface\r
+ //\r
+\r
+ /** \r
+ @return the stored form of this provider\r
+ representation\r
+\r
+ @see Dependable#getDependableFinder\r
+ */\r
+ public DependableFinder getDependableFinder()\r
+ {\r
+ return getDependableFinder(StoredFormatIds.ALIAS_DESCRIPTOR_FINDER_V01_ID);\r
+ }\r
+\r
+ /**\r
+ * Return the name of this Provider. (Useful for errors.)\r
+ *\r
+ * @return String The name of this provider.\r
+ */\r
+ public String getObjectName()\r
+ {\r
+ return aliasName;\r
+ }\r
+\r
+ /**\r
+ * Get the provider's UUID\r
+ *\r
+ * @return String The provider's UUID\r
+ */\r
+ public UUID getObjectID()\r
+ {\r
+ return aliasID;\r
+ }\r
+\r
+ /**\r
+ * Get the provider's type.\r
+ *\r
+ * @return String The provider's type.\r
+ */\r
+ public String getClassType()\r
+ {\r
+ return Dependable.ALIAS;\r
+ }\r
+ \r
+ /** @see TupleDescriptor#getDescriptorType */\r
+ public String getDescriptorType()\r
+ {\r
+ return getAliasType(aliasType);\r
+ }\r
+ \r
+ public static final String getAliasType(char nameSpace)\r
+ {\r
+ switch (nameSpace)\r
+ {\r
+ case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:\r
+ return "PROCEDURE";\r
+ case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:\r
+ return "FUNCTION";\r
+ case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:\r
+ return "SYNONYM";\r
+ }\r
+ return null;\r
+ }\r
+\r
+ /** @see TupleDescriptor#getDescriptorName */\r
+ public String getDescriptorName()\r
+ {\r
+ return aliasName;\r
+ }\r
+\r
+\r
+ /**\r
+ Return the specific name for this object.\r
+ */\r
+ public String getSpecificName()\r
+ {\r
+ return specificName;\r
+ }\r
+ \r
+ /**\r
+ * Functions are persistent unless they are in the SYSFUN schema.\r
+ *\r
+ */\r
+ public boolean isPersistent()\r
+ {\r
+ return !getSchemaUUID().toString().equals(SchemaDescriptor.SYSFUN_SCHEMA_UUID);\r
+ }\r
+ \r
+ /**\r
+ * Drop the routine or synonym.\r
+ * For a routine its permission descriptors will be dropped as well.\r
+ * For a synonym its TableDescriptor will be dropped as well.\r
+ * @param lcc\r
+ * @throws StandardException\r
+ */\r
+ public void drop(LanguageConnectionContext lcc) throws StandardException {\r
+ \r
+ DataDictionary dd = getDataDictionary();\r
+ TransactionController tc = lcc.getTransactionExecute();\r
+ DependencyManager dm = dd.getDependencyManager();\r
+ \r
+ \r
+ /* Prepare all dependents to invalidate. (This is their chance\r
+ * to say that they can't be invalidated. For example, an open\r
+ * cursor referencing a table/view that the user is attempting to\r
+ * drop.) If no one objects, then invalidate any dependent objects.\r
+ * We check for invalidation before we drop the descriptor\r
+ * since the descriptor may be looked up as part of\r
+ * decoding tuples in SYSDEPENDS.\r
+ */\r
+ int invalidationType = 0;\r
+ switch (getAliasType())\r
+ {\r
+ case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:\r
+ case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:\r
+ invalidationType = DependencyManager.DROP_METHOD_ALIAS;\r
+ break;\r
+ \r
+ case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:\r
+ invalidationType = DependencyManager.DROP_SYNONYM;\r
+ break;\r
+ }\r
+ \r
+ dm.invalidateFor(this, invalidationType, lcc);\r
+ \r
+ if (getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)\r
+ {\r
+ SchemaDescriptor sd = dd.getSchemaDescriptor(schemaID, tc);\r
+ \r
+ // Drop the entry from SYSTABLES as well.\r
+ DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();\r
+ TableDescriptor td = ddg.newTableDescriptor(aliasName, sd,\r
+ TableDescriptor.SYNONYM_TYPE, TableDescriptor.DEFAULT_LOCK_GRANULARITY);\r
+ dd.dropTableDescriptor(td, sd, tc);\r
+ }\r
+ else\r
+ dd.dropAllRoutinePermDescriptors(getUUID(), tc);\r
+ \r
+ /* Drop the alias */\r
+ dd.dropAliasDescriptor(this, tc);\r
+ }\r
+}\r