KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.DropSchemaConstantAction
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.dictionary.ConglomerateDescriptor;
27 import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
28 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
29 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
30
31 import org.apache.derby.iapi.sql.depend.DependencyManager;
32 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
33 import org.apache.derby.iapi.store.access.TransactionController;
34
35 import org.apache.derby.iapi.reference.SQLState;
36
37 import org.apache.derby.iapi.sql.execute.ConstantAction;
38
39 import org.apache.derby.iapi.sql.Activation;
40
41 import org.apache.derby.catalog.UUID;
42
43 /**
44  * This class describes actions that are ALWAYS performed for a
45  * DROP SCHEMA Statement at Execution time.
46  *
47  * @author jamie
48  */

49
50 class DropSchemaConstantAction extends DDLConstantAction
51 {
52
53
54     private final String JavaDoc schemaName;
55
56
57     // CONSTRUCTORS
58

59     /**
60      * Make the ConstantAction for a DROP TABLE statement.
61      *
62      * @param schemaName Table name.
63      *
64      */

65     DropSchemaConstantAction(String JavaDoc schemaName)
66     {
67         this.schemaName = schemaName;
68     }
69
70     ///////////////////////////////////////////////
71
//
72
// OBJECT SHADOWS
73
//
74
///////////////////////////////////////////////
75

76     public String JavaDoc toString()
77     {
78         // Do not put this under SanityManager.DEBUG - it is needed for
79
// error reporting.
80
return "DROP SCHEMA " + schemaName;
81     }
82
83     // INTERFACE METHODS
84

85
86     /**
87      * This is the guts of the Execution-time logic for DROP TABLE.
88      *
89      * @see ConstantAction#executeConstantAction
90      *
91      * @exception StandardException Thrown on failure
92      */

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

112         dd.startWriting(lcc);
113
114         sd = dd.getSchemaDescriptor(schemaName, null, true);
115
116     //If user is attempting to drop SESSION schema and there is no physical SESSION schema, then throw an exception
117
//Need to handle it this special way is because SESSION schema is also used for temporary tables. If there is no
118
//physical SESSION schema, we internally generate an in-memory SESSION schema in order to support temporary tables
119
//But there is no way for the user to access that in-memory SESSION schema. Following if will be true if there is
120
//no physical SESSION schema and hence getSchemaDescriptor has returned an in-memory SESSION schema
121
if (schemaName.equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME) && (sd != null) && (sd.getUUID() == null))
122             throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, schemaName);
123
124         /*
125         ** Make sure the schema is empty.
126         ** In the future we want to drop everything
127         ** in the schema if it is CASCADE.
128         */

129         if (!dd.isSchemaEmpty(sd))
130         {
131             throw StandardException.newException(SQLState.LANG_SCHEMA_NOT_EMPTY, schemaName);
132         }
133
134         /* Prepare all dependents to invalidate. (This is there chance
135          * to say that they can't be invalidated. For example, an open
136          * cursor referencing a table/view that the user is attempting to
137          * drop.) If no one objects, then invalidate any dependent objects.
138          * We check for invalidation before we drop the table descriptor
139          * since the table descriptor may be looked up as part of
140          * decoding tuples in SYSDEPENDS.
141          */

142         dm.invalidateFor(sd, DependencyManager.DROP_SCHEMA, lcc);
143
144         dd.dropSchemaDescriptor(schemaName, tc);
145
146         /*
147         ** If we have dropped the current default schema,
148         ** then we will set the default to null. The
149         ** LCC is free to set the new default schema to
150         ** some system defined default.
151         */

152         sd = lcc.getDefaultSchema();
153         if ((sd != null) &&
154             schemaName.equals(sd.getSchemaName()))
155         {
156             lcc.setDefaultSchema((SchemaDescriptor)null);
157         }
158
159     }
160
161 }
162
Popular Tags