KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.DropSchemaNode
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.sql.compile.CompilerContext;
25 import org.apache.derby.iapi.sql.conn.Authorizer;
26 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
27 import org.apache.derby.iapi.sql.execute.ConstantAction;
28
29 import org.apache.derby.iapi.error.StandardException;
30
31 import org.apache.derby.iapi.services.sanity.SanityManager;
32 import org.apache.derby.iapi.reference.SQLState;
33
34 /**
35  * A DropSchemaNode is the root of a QueryTree that represents
36  * a DROP SCHEMA statement.
37  *
38  * @author jamie
39  */

40
41 public class DropSchemaNode extends DDLStatementNode
42 {
43     private int dropBehavior;
44     private String JavaDoc schemaName;
45
46     /**
47      * Initializer for a DropSchemaNode
48      *
49      * @param schemaName The name of the object being dropped
50      * @param dropBehavior Drop behavior (RESTRICT | CASCADE)
51      *
52      */

53     public void init(Object JavaDoc schemaName, Object JavaDoc dropBehavior)
54         throws StandardException
55     {
56         initAndCheck(null);
57         this.schemaName = (String JavaDoc) schemaName;
58         this.dropBehavior = ((Integer JavaDoc) dropBehavior).intValue();
59     }
60
61     public QueryTreeNode bind() throws StandardException
62     {
63         
64         LanguageConnectionContext lcc = getLanguageConnectionContext();
65
66         /*
67         ** Users are not permitted to drop
68         ** the SYS or APP schemas.
69         */

70         if (getDataDictionary().isSystemSchemaName(schemaName))
71         {
72             throw(StandardException.newException(
73                     SQLState.LANG_CANNOT_DROP_SYSTEM_SCHEMAS, this.schemaName));
74         }
75         
76         /*
77         ** In SQL authorization mode, the current authorization identifier
78         ** must be either the owner of the schema or the database owner
79         ** in order for the schema object to be dropped.
80         */

81         if (isPrivilegeCollectionRequired())
82         {
83             getCompilerContext().addRequiredSchemaPriv(schemaName,
84                 lcc.getAuthorizationId(),
85                 Authorizer.DROP_SCHEMA_PRIV);
86         }
87         
88         return this;
89     }
90
91     /**
92      * Convert this object to a String. See comments in QueryTreeNode.java
93      * for how this should be done for tree printing.
94      *
95      * @return This object as a String
96      */

97
98     public String JavaDoc toString()
99     {
100         if (SanityManager.DEBUG)
101         {
102             return super.toString() +
103                 "dropBehavior: " + "\n" + dropBehavior + "\n";
104         }
105         else
106         {
107             return "";
108         }
109     }
110
111     public String JavaDoc statementToString()
112     {
113         return "DROP SCHEMA";
114     }
115
116     // inherit generate() method from DDLStatementNode
117

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

124     public ConstantAction makeConstantAction() throws StandardException
125     {
126         return getGenericConstantActionFactory().getDropSchemaConstantAction(schemaName);
127     }
128 }
129
Popular Tags