KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.DropIndexNode
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.iapi.sql.compile.CompilerContext;
27
28 import org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor;
29 import org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor;
30 import org.apache.derby.iapi.sql.dictionary.DataDictionary;
31 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
32 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
33 import org.apache.derby.iapi.sql.dictionary.TableDescriptor;
34
35 import org.apache.derby.iapi.reference.SQLState;
36
37 import org.apache.derby.iapi.sql.execute.ConstantAction;
38
39 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
40
41 import org.apache.derby.iapi.error.StandardException;
42
43 /**
44  * A DropIndexNode is the root of a QueryTree that represents a DROP INDEX
45  * statement.
46  *
47  * @author Jeff Lichtman
48  */

49
50 public class DropIndexNode extends DDLStatementNode
51 {
52     private ConglomerateDescriptor cd;
53     private TableDescriptor td;
54
55     public String JavaDoc statementToString()
56     {
57         return "DROP INDEX";
58     }
59
60     /**
61      * Bind this DropIndexNode. This means looking up the index,
62      * verifying it exists and getting the conglomerate number.
63      *
64      * @return The bound query tree
65      *
66      * @exception StandardException Thrown on error
67      */

68     public QueryTreeNode bind() throws StandardException
69     {
70         CompilerContext cc = getCompilerContext();
71         DataDictionary dd = getDataDictionary();
72         SchemaDescriptor sd;
73
74         sd = getSchemaDescriptor();
75
76         if (sd.getUUID() != null)
77             cd = dd.getConglomerateDescriptor(getRelativeName(), sd, false);
78
79         if (cd == null)
80         {
81             throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND, getFullName());
82         }
83
84         /* Get the table descriptor */
85         td = getTableDescriptor(cd.getTableID());
86
87         /* Drop index is not allowed on an index backing a constraint -
88          * user must drop the constraint, which will drop the index.
89          * Drop constraint drops the constraint before the index,
90          * so it's okay to drop a backing index if we can't find its
91          * ConstraintDescriptor.
92          */

93         if (cd.isConstraint())
94         {
95             ConstraintDescriptor conDesc;
96             String JavaDoc constraintName;
97
98             conDesc = dd.getConstraintDescriptor(td, cd.getUUID());
99             if (conDesc != null)
100             {
101                 constraintName = conDesc.getConstraintName();
102                 throw StandardException.newException(SQLState.LANG_CANT_DROP_BACKING_INDEX,
103                                         getFullName(), constraintName);
104             }
105         }
106
107         /* Statement is dependent on the TableDescriptor and ConglomerateDescriptor */
108         cc.createDependency(td);
109         cc.createDependency(cd);
110
111         return this;
112     }
113
114     // inherit generate() method from DDLStatementNode
115

116     /**
117      * Create the Constant information that will drive the guts of Execution.
118      *
119      * @exception StandardException Thrown on failure
120      */

121     public ConstantAction makeConstantAction() throws StandardException
122     {
123         return getGenericConstantActionFactory().getDropIndexConstantAction( getFullName(),
124                                              getRelativeName(),
125                                              getRelativeName(),
126                                              getSchemaDescriptor().getSchemaName(),
127                                              td.getUUID(),
128                                              td.getHeapConglomerateId());
129     }
130 }
131
Popular Tags