001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.DropViewConstantAction
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.execute;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025:
026: import org.apache.derby.iapi.error.StandardException;
027: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
028:
029: import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
030: import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
031: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
032: import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
033: import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
034: import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
035: import org.apache.derby.iapi.sql.dictionary.ViewDescriptor;
036:
037: import org.apache.derby.iapi.sql.depend.DependencyManager;
038:
039: import org.apache.derby.iapi.reference.SQLState;
040:
041: import org.apache.derby.iapi.sql.execute.ConstantAction;
042:
043: import org.apache.derby.iapi.sql.Activation;
044:
045: import org.apache.derby.iapi.store.access.TransactionController;
046:
047: import org.apache.derby.catalog.UUID;
048:
049: /**
050: * This class describes actions that are ALWAYS performed for a
051: * DROP VIEW Statement at Execution time.
052: *
053: * @author Jerry Brenner.
054: */
055:
056: class DropViewConstantAction extends DDLConstantAction {
057:
058: private String fullTableName;
059: private String tableName;
060: private SchemaDescriptor sd;
061:
062: // CONSTRUCTORS
063:
064: /**
065: * Make the ConstantAction for a DROP VIEW statement.
066: *
067: *
068: * @param fullTableName Fully qualified table name
069: * @param tableName Table name.
070: * @param sd Schema that view lives in.
071: *
072: */
073: DropViewConstantAction(String fullTableName, String tableName,
074: SchemaDescriptor sd) {
075: this .fullTableName = fullTableName;
076: this .tableName = tableName;
077: this .sd = sd;
078:
079: if (SanityManager.DEBUG) {
080: SanityManager
081: .ASSERT(sd != null, "SchemaDescriptor is null");
082: }
083: }
084:
085: // OBJECT METHODS
086:
087: public String toString() {
088: // Do not put this under SanityManager.DEBUG - it is needed for
089: // error reporting.
090: return "DROP VIEW " + fullTableName;
091: }
092:
093: // INTERFACE METHODS
094:
095: /**
096: * This is the guts of the Execution-time logic for DROP VIEW.
097: *
098: * @see ConstantAction#executeConstantAction
099: *
100: * @exception StandardException Thrown on failure
101: */
102: public void executeConstantAction(Activation activation)
103: throws StandardException {
104: TableDescriptor td;
105: ViewDescriptor vd;
106:
107: LanguageConnectionContext lcc = activation
108: .getLanguageConnectionContext();
109: DataDictionary dd = lcc.getDataDictionary();
110: DependencyManager dm = dd.getDependencyManager();
111: TransactionController tc = lcc.getTransactionExecute();
112:
113: /*
114: ** Inform the data dictionary that we are about to write to it.
115: ** There are several calls to data dictionary "get" methods here
116: ** that might be done in "read" mode in the data dictionary, but
117: ** it seemed safer to do this whole operation in "write" mode.
118: **
119: ** We tell the data dictionary we're done writing at the end of
120: ** the transaction.
121: */
122: dd.startWriting(lcc);
123:
124: /* Get the table descriptor. We're responsible for raising
125: * the error if it isn't found
126: */
127: td = dd.getTableDescriptor(tableName, sd);
128:
129: if (td == null) {
130: throw StandardException.newException(
131: SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION,
132: fullTableName);
133: }
134:
135: /* Verify that TableDescriptor represents a view */
136: if (td.getTableType() != TableDescriptor.VIEW_TYPE) {
137: throw StandardException.newException(
138: SQLState.LANG_DROP_VIEW_ON_NON_VIEW, fullTableName);
139: }
140:
141: vd = dd.getViewDescriptor(td);
142:
143: vd.dropViewWork(dd, dm, lcc, tc, sd, td, false);
144: }
145: }
|