KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.execute.DropViewConstantAction
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
26 import org.apache.derby.iapi.error.StandardException;
27 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
28
29 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
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 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
35 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;
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.UUID;
48
49 /**
50  * This class describes actions that are ALWAYS performed for a
51  * DROP VIEW Statement at Execution time.
52  *
53  * @author Jerry Brenner.
54  */

55
56 class DropViewConstantAction extends DDLConstantAction
57 {
58
59     private String JavaDoc fullTableName;
60     private String JavaDoc tableName;
61     private SchemaDescriptor sd;
62
63     // CONSTRUCTORS
64

65     /**
66      * Make the ConstantAction for a DROP VIEW statement.
67      *
68      *
69      * @param fullTableName Fully qualified table name
70      * @param tableName Table name.
71      * @param sd Schema that view lives in.
72      *
73      */

74     DropViewConstantAction(
75                                 String JavaDoc fullTableName,
76                                 String JavaDoc tableName,
77                                 SchemaDescriptor sd )
78     {
79         this.fullTableName = fullTableName;
80         this.tableName = tableName;
81         this.sd = sd;
82
83         if (SanityManager.DEBUG)
84         {
85             SanityManager.ASSERT(sd != null, "SchemaDescriptor is null");
86         }
87     }
88
89     // OBJECT METHODS
90

91     public String JavaDoc toString()
92     {
93         // Do not put this under SanityManager.DEBUG - it is needed for
94
// error reporting.
95
return "DROP VIEW " + fullTableName;
96     }
97
98     // INTERFACE METHODS
99

100
101     /**
102      * This is the guts of the Execution-time logic for DROP VIEW.
103      *
104      * @see ConstantAction#executeConstantAction
105      *
106      * @exception StandardException Thrown on failure
107      */

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

128         dd.startWriting(lcc);
129
130         /* Get the table descriptor. We're responsible for raising
131          * the error if it isn't found
132          */

133         td = dd.getTableDescriptor(tableName, sd);
134
135         if (td == null)
136         {
137             throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
138         }
139
140         /* Verify that TableDescriptor represents a view */
141         if (td.getTableType() != TableDescriptor.VIEW_TYPE)
142         {
143             throw StandardException.newException(SQLState.LANG_DROP_VIEW_ON_NON_VIEW, fullTableName);
144         }
145
146         vd = dd.getViewDescriptor(td);
147
148         vd.dropViewWork(dd, dm, lcc, tc, sd, td, false);
149     }
150 }
151
Popular Tags