KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > DropAliasConstantAction


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.DropAliasConstantAction
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.execute;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25 import org.apache.derby.iapi.error.StandardException;
26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
27
28 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
29 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
30 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
31 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
32 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
33 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
34
35 import org.apache.derby.iapi.types.DataValueFactory;
36
37 import org.apache.derby.iapi.sql.depend.DependencyManager;
38
39 import org.apache.derby.iapi.reference.SQLState;
40
41 import org.apache.derby.iapi.sql.execute.ConstantAction;
42
43 import org.apache.derby.iapi.sql.Activation;
44
45 import org.apache.derby.iapi.store.access.TransactionController;
46
47 import org.apache.derby.catalog.AliasInfo;
48
49 /**
50  * This class describes actions that are ALWAYS performed for a
51  * DROP ALIAS Statement at Execution time.
52  *
53  * @author Jerry Brenner.
54  */

55
56 class DropAliasConstantAction extends DDLConstantAction
57 {
58
59     private SchemaDescriptor sd;
60     private final String JavaDoc schemaName;
61     private final String JavaDoc aliasName;
62     private final char nameSpace;
63
64     // CONSTRUCTORS
65

66
67     /**
68      * Make the ConstantAction for a DROP ALIAS statement.
69      *
70      *
71      * @param aliasName Alias name.
72      * @param nameSpace Alias name space.
73      *
74      */

75     DropAliasConstantAction(SchemaDescriptor sd, String JavaDoc aliasName, char nameSpace)
76     {
77         this.sd = sd;
78         this.schemaName = sd.getSchemaName();
79         this.aliasName = aliasName;
80         this.nameSpace = nameSpace;
81     }
82
83     // OBJECT SHADOWS
84

85     public String JavaDoc toString()
86     {
87         // Do not put this under SanityManager.DEBUG - it is needed for
88
// error reporting.
89
return "DROP ALIAS " + aliasName;
90     }
91
92     // INTERFACE METHODS
93

94
95     /**
96      * This is the guts of the Execution-time logic for DROP ALIAS.
97      *
98      * @see ConstantAction#executeConstantAction
99      *
100      * @exception StandardException Thrown on failure
101      */

102     public void executeConstantAction( Activation activation )
103                         throws StandardException
104     {
105         LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
106         DataDictionary dd = lcc.getDataDictionary();
107         TransactionController tc = lcc.getTransactionExecute();
108         DependencyManager dm = dd.getDependencyManager();
109
110
111         /*
112         ** Inform the data dictionary that we are about to write to it.
113         ** There are several calls to data dictionary "get" methods here
114         ** that might be done in "read" mode in the data dictionary, but
115         ** it seemed safer to do this whole operation in "write" mode.
116         **
117         ** We tell the data dictionary we're done writing at the end of
118         ** the transaction.
119         */

120         dd.startWriting(lcc);
121
122         if (sd == null) {
123             sd = dd.getSchemaDescriptor(schemaName, lcc.getTransactionExecute(), true);
124         }
125
126
127         /* Get the alias descriptor. We're responsible for raising
128          * the error if it isn't found
129          */

130         AliasDescriptor ad = dd.getAliasDescriptor(sd.getUUID().toString(), aliasName, nameSpace);
131
132         // RESOLVE - fix error message
133
if (ad == null)
134         {
135             throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND, ad.getAliasType(nameSpace), aliasName);
136         }
137
138         /* Prepare all dependents to invalidate. (This is their chance
139          * to say that they can't be invalidated. For example, an open
140          * cursor referencing a table/view that the user is attempting to
141          * drop.) If no one objects, then invalidate any dependent objects.
142          * We check for invalidation before we drop the descriptor
143          * since the descriptor may be looked up as part of
144          * decoding tuples in SYSDEPENDS.
145          */

146         int invalidationType = 0;
147         switch (ad.getAliasType())
148         {
149             case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
150             case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
151                 invalidationType = DependencyManager.DROP_METHOD_ALIAS;
152                 break;
153
154             case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
155                 invalidationType = DependencyManager.DROP_SYNONYM;
156                 break;
157         }
158
159         dm.invalidateFor(ad, invalidationType, lcc);
160
161         if (ad.getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR)
162         {
163             // Drop the entry from SYSTABLES as well.
164
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
165             TableDescriptor td = ddg.newTableDescriptor(aliasName, sd,
166                 TableDescriptor.SYNONYM_TYPE, TableDescriptor.DEFAULT_LOCK_GRANULARITY);
167             dd.dropTableDescriptor(td, sd, tc);
168         }
169         else
170             dd.dropAllRoutinePermDescriptors(ad.getUUID(), tc);
171             
172         /* Drop the alias */
173         dd.dropAliasDescriptor(ad, tc);
174
175     }
176 }
177
Popular Tags