001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.DropTableNode
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.compile;
023:
024: import org.apache.derby.iapi.services.context.ContextManager;
025:
026: import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
027: import org.apache.derby.impl.sql.execute.BaseActivation;
028: import org.apache.derby.iapi.sql.ResultSet;
029:
030: import org.apache.derby.iapi.error.StandardException;
031:
032: import org.apache.derby.iapi.sql.compile.CompilerContext;
033: import org.apache.derby.iapi.sql.StatementType;
034:
035: import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
036: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
037: import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
038: import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
039: import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
040:
041: import org.apache.derby.iapi.reference.SQLState;
042:
043: import org.apache.derby.iapi.sql.execute.ConstantAction;
044:
045: import org.apache.derby.iapi.services.sanity.SanityManager;
046:
047: /**
048: * A DropTableNode is the root of a QueryTree that represents a DROP TABLE
049: * statement.
050: *
051: * @author Jerry Brenner
052: */
053:
054: public class DropTableNode extends DDLStatementNode {
055: private long conglomerateNumber;
056: private int dropBehavior;
057: private TableDescriptor td;
058:
059: /**
060: * Intializer for a DropTableNode
061: *
062: * @param dropObjectName The name of the object being dropped
063: * @param dropBehavior Drop behavior (RESTRICT | CASCADE)
064: *
065: */
066:
067: public void init(Object dropObjectName, Object dropBehavior)
068: throws StandardException {
069: initAndCheck(dropObjectName);
070: this .dropBehavior = ((Integer) dropBehavior).intValue();
071: }
072:
073: /**
074: * Convert this object to a String. See comments in QueryTreeNode.java
075: * for how this should be done for tree printing.
076: *
077: * @return This object as a String
078: */
079:
080: public String toString() {
081: if (SanityManager.DEBUG) {
082: return super .toString() + "conglomerateNumber: "
083: + conglomerateNumber + "\n" + "td: "
084: + ((td == null) ? "null" : td.toString()) + "\n"
085: + "dropBehavior: " + "\n" + dropBehavior + "\n";
086: } else {
087: return "";
088: }
089: }
090:
091: public String statementToString() {
092: return "DROP TABLE";
093: }
094:
095: /**
096: * Bind this LockTableNode. This means looking up the table,
097: * verifying it exists and getting the heap conglomerate number.
098: *
099: * @return The bound query tree
100: *
101: * @exception StandardException Thrown on error
102: */
103:
104: public QueryTreeNode bind() throws StandardException {
105: CompilerContext cc = getCompilerContext();
106:
107: td = getTableDescriptor();
108:
109: conglomerateNumber = td.getHeapConglomerateId();
110:
111: /* Get the base conglomerate descriptor */
112: ConglomerateDescriptor cd = td
113: .getConglomerateDescriptor(conglomerateNumber);
114:
115: /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
116: cc.createDependency(td);
117: cc.createDependency(cd);
118:
119: return this ;
120: }
121:
122: /**
123: * Return true if the node references SESSION schema tables (temporary or permanent)
124: *
125: * @return true if references SESSION schema tables, else false
126: *
127: * @exception StandardException Thrown on error
128: */
129: public boolean referencesSessionSchema() throws StandardException {
130: //If table being dropped is in SESSION schema, then return true.
131: return isSessionSchema(td.getSchemaDescriptor());
132: }
133:
134: // inherit generate() method from DDLStatementNode
135:
136: /**
137: * Create the Constant information that will drive the guts of Execution.
138: *
139: * @exception StandardException Thrown on failure
140: */
141: public ConstantAction makeConstantAction() throws StandardException {
142: return getGenericConstantActionFactory()
143: .getDropTableConstantAction(getFullName(),
144: getRelativeName(), getSchemaDescriptor(),
145: conglomerateNumber, td.getUUID(), dropBehavior);
146: }
147: }
|