KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > DropTableNode


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.DropTableNode
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.compile;
23
24 import org.apache.derby.iapi.services.context.ContextManager;
25
26 import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
27 import org.apache.derby.impl.sql.execute.BaseActivation;
28 import org.apache.derby.iapi.sql.ResultSet;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import org.apache.derby.iapi.sql.compile.CompilerContext;
33 import org.apache.derby.iapi.sql.StatementType;
34
35 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
36 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
37 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
38 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
39 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
40
41 import org.apache.derby.iapi.reference.SQLState;
42
43 import org.apache.derby.iapi.sql.execute.ConstantAction;
44
45 import org.apache.derby.iapi.services.sanity.SanityManager;
46
47 /**
48  * A DropTableNode is the root of a QueryTree that represents a DROP TABLE
49  * statement.
50  *
51  * @author Jerry Brenner
52  */

53
54 public class DropTableNode extends DDLStatementNode
55 {
56     private long conglomerateNumber;
57     private int dropBehavior;
58     private TableDescriptor td;
59
60     /**
61      * Intializer for a DropTableNode
62      *
63      * @param dropObjectName The name of the object being dropped
64      * @param dropBehavior Drop behavior (RESTRICT | CASCADE)
65      *
66      */

67
68     public void init(Object JavaDoc dropObjectName, Object JavaDoc dropBehavior)
69         throws StandardException
70     {
71         initAndCheck(dropObjectName);
72         this.dropBehavior = ((Integer JavaDoc) dropBehavior).intValue();
73     }
74
75     /**
76      * Convert this object to a String. See comments in QueryTreeNode.java
77      * for how this should be done for tree printing.
78      *
79      * @return This object as a String
80      */

81
82     public String JavaDoc toString()
83     {
84         if (SanityManager.DEBUG)
85         {
86             return super.toString() +
87                 "conglomerateNumber: " + conglomerateNumber + "\n" +
88                 "td: " + ((td == null) ? "null" : td.toString()) + "\n" +
89                 "dropBehavior: " + "\n" + dropBehavior + "\n";
90         }
91         else
92         {
93             return "";
94         }
95     }
96
97     public String JavaDoc statementToString()
98     {
99         return "DROP TABLE";
100     }
101
102     /**
103      * Bind this LockTableNode. This means looking up the table,
104      * verifying it exists and getting the heap conglomerate number.
105      *
106      * @return The bound query tree
107      *
108      * @exception StandardException Thrown on error
109      */

110
111     public QueryTreeNode bind() throws StandardException
112     {
113         CompilerContext cc = getCompilerContext();
114
115         td = getTableDescriptor();
116
117         conglomerateNumber = td.getHeapConglomerateId();
118
119         /* Get the base conglomerate descriptor */
120         ConglomerateDescriptor cd = td.getConglomerateDescriptor(conglomerateNumber);
121
122         /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
123         cc.createDependency(td);
124         cc.createDependency(cd);
125
126         return this;
127     }
128
129     /**
130      * Return true if the node references SESSION schema tables (temporary or permanent)
131      *
132      * @return true if references SESSION schema tables, else false
133      *
134      * @exception StandardException Thrown on error
135      */

136     public boolean referencesSessionSchema()
137         throws StandardException
138     {
139         //If table being dropped is in SESSION schema, then return true.
140
return isSessionSchema(td.getSchemaDescriptor());
141     }
142
143     // inherit generate() method from DDLStatementNode
144

145
146     /**
147      * Create the Constant information that will drive the guts of Execution.
148      *
149      * @exception StandardException Thrown on failure
150      */

151     public ConstantAction makeConstantAction() throws StandardException
152     {
153         return getGenericConstantActionFactory().getDropTableConstantAction( getFullName(),
154                                              getRelativeName(),
155                                              getSchemaDescriptor(),
156                                              conglomerateNumber,
157                                              td.getUUID(),
158                                              dropBehavior);
159     }
160 }
161
Popular Tags