KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > DropAliasNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.DropAliasNode
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.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 /**
44  * A DropAliasNode represents a DROP ALIAS statement.
45  *
46  * @author Jerry Brenner
47  */

48
49 public class DropAliasNode extends DDLStatementNode
50 {
51     private char aliasType;
52     private char nameSpace;
53
54     /**
55      * Initializer for a DropAliasNode
56      *
57      * @param dropAliasName The name of the method alias being dropped
58      * @param aliasType Alias type
59      *
60      * @exception StandardException
61      */

62     public void init(Object JavaDoc dropAliasName, Object JavaDoc aliasType)
63                 throws StandardException
64     {
65         TableName dropItem = (TableName) dropAliasName;
66         initAndCheck(dropItem);
67         this.aliasType = ((Character JavaDoc) 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 JavaDoc statementToString()
94     {
95         return "DROP ".concat(aliasTypeName(aliasType));
96     }
97
98     /**
99      * Bind this DropMethodAliasNode.
100      *
101      * @return The bound query tree
102      *
103      * @exception StandardException Thrown on error
104      */

105     public QueryTreeNode bind() throws StandardException
106     {
107         DataDictionary dataDictionary = getDataDictionary();
108         String JavaDoc 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         // User cannot drop a system alias
123
if (ad.getSystemAlias())
124         {
125             throw StandardException.newException(SQLState.LANG_CANNOT_DROP_SYSTEM_ALIASES, aliasName);
126         }
127
128         return this;
129     }
130
131     // inherit generate() method from DDLStatementNode
132

133
134     /**
135      * Create the Constant information that will drive the guts of Execution.
136      *
137      * @exception StandardException Thrown on failure
138      */

139     public ConstantAction makeConstantAction() throws StandardException
140     {
141         return getGenericConstantActionFactory().getDropAliasConstantAction(getSchemaDescriptor(), getRelativeName(), nameSpace);
142     }
143
144     /* returns the alias type name given the alias char type */
145     private static String JavaDoc aliasTypeName( char actualType)
146     {
147         String JavaDoc 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