001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.DropAliasNode
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.impl.sql.compile;
023:
024: import org.apache.derby.iapi.sql.compile.C_NodeTypes;
025:
026: import org.apache.derby.iapi.services.context.ContextManager;
027:
028: import org.apache.derby.iapi.sql.execute.ConstantAction;
029:
030: import org.apache.derby.iapi.reference.SQLState;
031:
032: import org.apache.derby.iapi.error.StandardException;
033:
034: import org.apache.derby.iapi.services.monitor.Monitor;
035: import org.apache.derby.iapi.services.sanity.SanityManager;
036:
037: import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
038: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
039: import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
040:
041: import org.apache.derby.catalog.AliasInfo;
042:
043: /**
044: * A DropAliasNode represents a DROP ALIAS statement.
045: *
046: * @author Jerry Brenner
047: */
048:
049: public class DropAliasNode extends DDLStatementNode {
050: private char aliasType;
051: private char nameSpace;
052:
053: /**
054: * Initializer for a DropAliasNode
055: *
056: * @param dropAliasName The name of the method alias being dropped
057: * @param aliasType Alias type
058: *
059: * @exception StandardException
060: */
061: public void init(Object dropAliasName, Object aliasType)
062: throws StandardException {
063: TableName dropItem = (TableName) dropAliasName;
064: initAndCheck(dropItem);
065: this .aliasType = ((Character) aliasType).charValue();
066:
067: switch (this .aliasType) {
068: case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
069: nameSpace = AliasInfo.ALIAS_NAME_SPACE_PROCEDURE_AS_CHAR;
070: break;
071:
072: case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
073: nameSpace = AliasInfo.ALIAS_NAME_SPACE_FUNCTION_AS_CHAR;
074: break;
075:
076: case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
077: nameSpace = AliasInfo.ALIAS_NAME_SPACE_SYNONYM_AS_CHAR;
078: break;
079:
080: default:
081: if (SanityManager.DEBUG) {
082: SanityManager.THROWASSERT("bad type to DropAliasNode: "
083: + this .aliasType);
084: }
085: }
086: }
087:
088: public char getAliasType() {
089: return aliasType;
090: }
091:
092: public String statementToString() {
093: return "DROP ".concat(aliasTypeName(aliasType));
094: }
095:
096: /**
097: * Bind this DropMethodAliasNode.
098: *
099: * @return The bound query tree
100: *
101: * @exception StandardException Thrown on error
102: */
103: public QueryTreeNode bind() throws StandardException {
104: DataDictionary dataDictionary = getDataDictionary();
105: String aliasName = getRelativeName();
106:
107: AliasDescriptor ad = null;
108: SchemaDescriptor sd = getSchemaDescriptor();
109:
110: if (sd.getUUID() != null) {
111: ad = dataDictionary.getAliasDescriptor(sd.getUUID()
112: .toString(), aliasName, nameSpace);
113: }
114: if (ad == null) {
115: throw StandardException.newException(
116: SQLState.LANG_OBJECT_DOES_NOT_EXIST,
117: statementToString(), aliasName);
118: }
119:
120: // User cannot drop a system alias
121: if (ad.getSystemAlias()) {
122: throw StandardException
123: .newException(
124: SQLState.LANG_CANNOT_DROP_SYSTEM_ALIASES,
125: aliasName);
126: }
127:
128: return this ;
129: }
130:
131: // inherit generate() method from DDLStatementNode
132:
133: /**
134: * Create the Constant information that will drive the guts of Execution.
135: *
136: * @exception StandardException Thrown on failure
137: */
138: public ConstantAction makeConstantAction() throws StandardException {
139: return getGenericConstantActionFactory()
140: .getDropAliasConstantAction(getSchemaDescriptor(),
141: getRelativeName(), nameSpace);
142: }
143:
144: /* returns the alias type name given the alias char type */
145: private static String aliasTypeName(char actualType) {
146: String typeName = null;
147:
148: switch (actualType) {
149: case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
150: typeName = "PROCEDURE";
151: break;
152: case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
153: typeName = "FUNCTION";
154: break;
155: case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
156: typeName = "SYNONYM";
157: break;
158: }
159: return typeName;
160: }
161: }
|