001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.CreateSchemaNode
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.iapi.sql.ResultSet;
027: import org.apache.derby.iapi.sql.execute.ConstantAction;
028:
029: import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext;
030: import org.apache.derby.iapi.sql.dictionary.DataDictionary;
031: import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor;
032: import org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator;
033:
034: import org.apache.derby.iapi.sql.compile.CompilerContext;
035: import org.apache.derby.iapi.sql.conn.Authorizer;
036:
037: import org.apache.derby.iapi.error.StandardException;
038:
039: import org.apache.derby.iapi.services.monitor.Monitor;
040: import org.apache.derby.iapi.services.sanity.SanityManager;
041:
042: import org.apache.derby.impl.sql.compile.ActivationClassBuilder;
043: import org.apache.derby.impl.sql.execute.BaseActivation;
044:
045: import java.util.Properties;
046:
047: /**
048: * A CreateSchemaNode is the root of a QueryTree that
049: * represents a CREATE SCHEMA statement.
050: *
051: * @author jamie
052: */
053:
054: public class CreateSchemaNode extends DDLStatementNode {
055: private String name;
056: private String aid;
057:
058: /**
059: * Initializer for a CreateSchemaNode
060: *
061: * @param schemaName The name of the new schema
062: * @param aid The authorization id
063: *
064: * @exception StandardException Thrown on error
065: */
066: public void init(Object schemaName, Object aid)
067: throws StandardException {
068: /*
069: ** DDLStatementNode expects tables, null out
070: ** objectName explicitly to clarify that we
071: ** can't hang with schema.object specifiers.
072: */
073: initAndCheck(null);
074:
075: this .name = (String) schemaName;
076: this .aid = (String) aid;
077: }
078:
079: /**
080: * Convert this object to a String. See comments in QueryTreeNode.java
081: * for how this should be done for tree printing.
082: *
083: * @return This object as a String
084: */
085:
086: public String toString() {
087: if (SanityManager.DEBUG) {
088: return super .toString() + "schemaName: " + "\n" + name
089: + "\n" + "authorizationId: " + "\n" + aid + "\n";
090: } else {
091: return "";
092: }
093: }
094:
095: /**
096: * Bind this createSchemaNode. Main work is to create a StatementPermission
097: * object to require CREATE_SCHEMA_PRIV at execution time.
098: */
099: public QueryTreeNode bind() throws StandardException {
100: super .bind();
101:
102: CompilerContext cc = getCompilerContext();
103: if (isPrivilegeCollectionRequired())
104: cc.addRequiredSchemaPriv(name, aid,
105: Authorizer.CREATE_SCHEMA_PRIV);
106:
107: return this ;
108: }
109:
110: public String statementToString() {
111: return "CREATE SCHEMA";
112: }
113:
114: // We inherit the 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() {
122: return getGenericConstantActionFactory()
123: .getCreateSchemaConstantAction(name, aid);
124: }
125: }
|