001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.execute.DropAliasConstantAction
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: import org.apache.derby.iapi.error.StandardException;
026: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
027:
028: import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
029: import org.apache.derby.iapi.sql.dictionary.AliasDescriptor;
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:
035: import org.apache.derby.iapi.types.DataValueFactory;
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.AliasInfo;
048:
049: /**
050: * This class describes actions that are ALWAYS performed for a
051: * DROP ALIAS Statement at Execution time.
052: *
053: * @author Jerry Brenner.
054: */
055:
056: class DropAliasConstantAction extends DDLConstantAction {
057:
058: private SchemaDescriptor sd;
059: private final String schemaName;
060: private final String aliasName;
061: private final char nameSpace;
062:
063: // CONSTRUCTORS
064:
065: /**
066: * Make the ConstantAction for a DROP ALIAS statement.
067: *
068: *
069: * @param aliasName Alias name.
070: * @param nameSpace Alias name space.
071: *
072: */
073: DropAliasConstantAction(SchemaDescriptor sd, String aliasName,
074: char nameSpace) {
075: this .sd = sd;
076: this .schemaName = sd.getSchemaName();
077: this .aliasName = aliasName;
078: this .nameSpace = nameSpace;
079: }
080:
081: // OBJECT SHADOWS
082:
083: public String toString() {
084: // Do not put this under SanityManager.DEBUG - it is needed for
085: // error reporting.
086: return "DROP ALIAS " + aliasName;
087: }
088:
089: // INTERFACE METHODS
090:
091: /**
092: * This is the guts of the Execution-time logic for DROP ALIAS.
093: *
094: * @see ConstantAction#executeConstantAction
095: *
096: * @exception StandardException Thrown on failure
097: */
098: public void executeConstantAction(Activation activation)
099: throws StandardException {
100: LanguageConnectionContext lcc = activation
101: .getLanguageConnectionContext();
102: DataDictionary dd = lcc.getDataDictionary();
103: TransactionController tc = lcc.getTransactionExecute();
104: DependencyManager dm = dd.getDependencyManager();
105:
106: /*
107: ** Inform the data dictionary that we are about to write to it.
108: ** There are several calls to data dictionary "get" methods here
109: ** that might be done in "read" mode in the data dictionary, but
110: ** it seemed safer to do this whole operation in "write" mode.
111: **
112: ** We tell the data dictionary we're done writing at the end of
113: ** the transaction.
114: */
115: dd.startWriting(lcc);
116:
117: if (sd == null) {
118: sd = dd.getSchemaDescriptor(schemaName, lcc
119: .getTransactionExecute(), true);
120: }
121:
122: /* Get the alias descriptor. We're responsible for raising
123: * the error if it isn't found
124: */
125: AliasDescriptor ad = dd.getAliasDescriptor(sd.getUUID()
126: .toString(), aliasName, nameSpace);
127:
128: // RESOLVE - fix error message
129: if (ad == null) {
130: throw StandardException.newException(
131: SQLState.LANG_OBJECT_NOT_FOUND, ad
132: .getAliasType(nameSpace), aliasName);
133: }
134:
135: /* Prepare all dependents to invalidate. (This is their chance
136: * to say that they can't be invalidated. For example, an open
137: * cursor referencing a table/view that the user is attempting to
138: * drop.) If no one objects, then invalidate any dependent objects.
139: * We check for invalidation before we drop the descriptor
140: * since the descriptor may be looked up as part of
141: * decoding tuples in SYSDEPENDS.
142: */
143: int invalidationType = 0;
144: switch (ad.getAliasType()) {
145: case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
146: case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
147: invalidationType = DependencyManager.DROP_METHOD_ALIAS;
148: break;
149:
150: case AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR:
151: invalidationType = DependencyManager.DROP_SYNONYM;
152: break;
153: }
154:
155: dm.invalidateFor(ad, invalidationType, lcc);
156:
157: if (ad.getAliasType() == AliasInfo.ALIAS_TYPE_SYNONYM_AS_CHAR) {
158: // Drop the entry from SYSTABLES as well.
159: DataDescriptorGenerator ddg = dd
160: .getDataDescriptorGenerator();
161: TableDescriptor td = ddg.newTableDescriptor(aliasName, sd,
162: TableDescriptor.SYNONYM_TYPE,
163: TableDescriptor.DEFAULT_LOCK_GRANULARITY);
164: dd.dropTableDescriptor(td, sd, tc);
165: } else
166: dd.dropAllRoutinePermDescriptors(ad.getUUID(), tc);
167:
168: /* Drop the alias */
169: dd.dropAliasDescriptor(ad, tc);
170:
171: }
172: }
|