1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.sql.compile.C_NodeTypes; 25 26 import org.apache.derby.iapi.services.context.ContextManager; 27 28 import org.apache.derby.iapi.sql.execute.ConstantAction; 29 30 import org.apache.derby.iapi.reference.SQLState; 31 32 import org.apache.derby.iapi.error.StandardException; 33 34 import org.apache.derby.iapi.services.monitor.Monitor; 35 import org.apache.derby.iapi.services.sanity.SanityManager; 36 37 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; 38 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 39 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 40 41 import org.apache.derby.catalog.AliasInfo; 42 43 48 49 public class DropAliasNode extends DDLStatementNode 50 { 51 private char aliasType; 52 private char nameSpace; 53 54 62 public void init(Object dropAliasName, Object aliasType) 63 throws StandardException 64 { 65 TableName dropItem = (TableName) dropAliasName; 66 initAndCheck(dropItem); 67 this.aliasType = ((Character ) aliasType).charValue(); 68 69 switch (this.aliasType) 70 { 71 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 72 nameSpace = AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR; 73 break; 74 75 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 76 nameSpace = AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR; 77 break; 78 79 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 80 nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR; 81 break; 82 83 default: 84 if (SanityManager.DEBUG) 85 { 86 SanityManager.THROWASSERT("bad type to DropAliasNode: "+this.aliasType); 87 } 88 } 89 } 90 91 public char getAliasType() { return aliasType; } 92 93 public String statementToString() 94 { 95 return "DROP ".concat(aliasTypeName(aliasType)); 96 } 97 98 105 public QueryTreeNode bind() throws StandardException 106 { 107 DataDictionary dataDictionary = getDataDictionary(); 108 String aliasName = getRelativeName(); 109 110 AliasDescriptor ad = null; 111 SchemaDescriptor sd = getSchemaDescriptor(); 112 113 if (sd.getUUID() != null) { 114 ad = dataDictionary.getAliasDescriptor 115 (sd.getUUID().toString(), aliasName, nameSpace ); 116 } 117 if ( ad == null ) 118 { 119 throw StandardException.newException(SQLState.LANG_OBJECT_DOES_NOT_EXIST, statementToString(), aliasName); 120 } 121 122 if (ad.getSystemAlias()) 124 { 125 throw StandardException.newException(SQLState.LANG_CANNOT_DROP_SYSTEM_ALIASES, aliasName); 126 } 127 128 return this; 129 } 130 131 133 134 139 public ConstantAction makeConstantAction() throws StandardException 140 { 141 return getGenericConstantActionFactory().getDropAliasConstantAction(getSchemaDescriptor(), getRelativeName(), nameSpace); 142 } 143 144 145 private static String aliasTypeName( char actualType) 146 { 147 String typeName = null; 148 149 switch ( actualType ) 150 { 151 case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR: 152 typeName = "PROCEDURE"; 153 break; 154 case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR: 155 typeName = "FUNCTION"; 156 break; 157 case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR: 158 typeName = "SYNONYM"; 159 break; 160 } 161 return typeName; 162 } 163 } 164 | Popular Tags |