001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.GrantNode
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.execute.ConstantAction;
025: import org.apache.derby.impl.sql.execute.PrivilegeInfo;
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027: import org.apache.derby.iapi.error.StandardException;
028:
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.List;
032:
033: /**
034: * This class represents a GRANT statement.
035: */
036: public class GrantNode extends DDLStatementNode {
037: private PrivilegeNode privileges;
038: private List grantees;
039:
040: /**
041: * Convert this object to a String. See comments in QueryTreeNode.java
042: * for how this should be done for tree printing.
043: *
044: * @return This object as a String
045: */
046:
047: public String toString() {
048: if (SanityManager.DEBUG) {
049: StringBuffer sb = new StringBuffer();
050: for (Iterator it = grantees.iterator(); it.hasNext();) {
051: if (sb.length() > 0)
052: sb.append(",");
053: sb.append(it.next().toString());
054: }
055: return super .toString() + privileges.toString() + "TO: \n"
056: + sb.toString() + "\n";
057: } else {
058: return "";
059: }
060: } // end of toString
061:
062: public String statementToString() {
063: return "GRANT";
064: }
065:
066: /**
067: * Initialize a GrantNode.
068: *
069: * @param privileges PrivilegesNode
070: * @param grantees List
071: */
072: public void init(Object privileges, Object grantees) {
073: this .privileges = (PrivilegeNode) privileges;
074: this .grantees = (List) grantees;
075: }
076:
077: /**
078: * Bind this GrantNode. Resolve all table, column, and routine references.
079: *
080: * @return the bound GrantNode
081: *
082: * @exception StandardException Standard error policy.
083: */
084: public QueryTreeNode bind() throws StandardException {
085: privileges = (PrivilegeNode) privileges.bind(new HashMap(),
086: grantees, true);
087: return this ;
088: } // end of bind
089:
090: /**
091: * Create the Constant information that will drive the guts of Execution.
092: *
093: * @exception StandardException Standard error policy.
094: */
095: public ConstantAction makeConstantAction() throws StandardException {
096: return getGenericConstantActionFactory()
097: .getGrantConstantAction(privileges.makePrivilegeInfo(),
098: grantees);
099: }
100: }
|