001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.DropSchemaNode
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.sql.compile.CompilerContext;
025: import org.apache.derby.iapi.sql.conn.Authorizer;
026: import org.apache.derby.iapi.sql.conn.LanguageConnectionContext;
027: import org.apache.derby.iapi.sql.execute.ConstantAction;
028:
029: import org.apache.derby.iapi.error.StandardException;
030:
031: import org.apache.derby.iapi.services.sanity.SanityManager;
032: import org.apache.derby.iapi.reference.SQLState;
033:
034: /**
035: * A DropSchemaNode is the root of a QueryTree that represents
036: * a DROP SCHEMA statement.
037: *
038: * @author jamie
039: */
040:
041: public class DropSchemaNode extends DDLStatementNode {
042: private int dropBehavior;
043: private String schemaName;
044:
045: /**
046: * Initializer for a DropSchemaNode
047: *
048: * @param schemaName The name of the object being dropped
049: * @param dropBehavior Drop behavior (RESTRICT | CASCADE)
050: *
051: */
052: public void init(Object schemaName, Object dropBehavior)
053: throws StandardException {
054: initAndCheck(null);
055: this .schemaName = (String) schemaName;
056: this .dropBehavior = ((Integer) dropBehavior).intValue();
057: }
058:
059: public QueryTreeNode bind() throws StandardException {
060:
061: LanguageConnectionContext lcc = getLanguageConnectionContext();
062:
063: /*
064: ** Users are not permitted to drop
065: ** the SYS or APP schemas.
066: */
067: if (getDataDictionary().isSystemSchemaName(schemaName)) {
068: throw (StandardException.newException(
069: SQLState.LANG_CANNOT_DROP_SYSTEM_SCHEMAS,
070: this .schemaName));
071: }
072:
073: /*
074: ** In SQL authorization mode, the current authorization identifier
075: ** must be either the owner of the schema or the database owner
076: ** in order for the schema object to be dropped.
077: */
078: if (isPrivilegeCollectionRequired()) {
079: getCompilerContext().addRequiredSchemaPriv(schemaName,
080: lcc.getAuthorizationId(),
081: Authorizer.DROP_SCHEMA_PRIV);
082: }
083:
084: return this ;
085: }
086:
087: /**
088: * Convert this object to a String. See comments in QueryTreeNode.java
089: * for how this should be done for tree printing.
090: *
091: * @return This object as a String
092: */
093:
094: public String toString() {
095: if (SanityManager.DEBUG) {
096: return super .toString() + "dropBehavior: " + "\n"
097: + dropBehavior + "\n";
098: } else {
099: return "";
100: }
101: }
102:
103: public String statementToString() {
104: return "DROP SCHEMA";
105: }
106:
107: // inherit generate() method from DDLStatementNode
108:
109: /**
110: * Create the Constant information that will drive the guts of Execution.
111: *
112: * @exception StandardException Thrown on failure
113: */
114: public ConstantAction makeConstantAction() throws StandardException {
115: return getGenericConstantActionFactory()
116: .getDropSchemaConstantAction(schemaName);
117: }
118: }
|