1 21 22 package org.apache.derby.impl.sql.compile; 23 24 import org.apache.derby.iapi.error.StandardException; 25 import org.apache.derby.iapi.reference.SQLState; 26 27 import org.apache.derby.impl.sql.execute.PrivilegeInfo; 28 import org.apache.derby.impl.sql.execute.TablePrivilegeInfo; 29 import org.apache.derby.iapi.services.io.FormatableBitSet; 30 import org.apache.derby.iapi.sql.dictionary.TableDescriptor; 31 32 import org.apache.derby.iapi.sql.depend.DependencyManager; 33 import org.apache.derby.iapi.sql.depend.Provider; 34 import org.apache.derby.iapi.sql.depend.ProviderInfo; 35 import org.apache.derby.iapi.sql.depend.ProviderList; 36 import org.apache.derby.iapi.sql.conn.ConnectionUtil; 37 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 38 import org.apache.derby.iapi.sql.dictionary.AliasDescriptor; 39 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 40 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 41 import org.apache.derby.iapi.sql.dictionary.TupleDescriptor; 42 import org.apache.derby.iapi.sql.dictionary.ViewDescriptor; 43 44 import java.util.ArrayList ; 45 import java.util.List ; 46 47 50 public class TablePrivilegesNode extends QueryTreeNode 51 { 52 private boolean[] actionAllowed = new boolean[ TablePrivilegeInfo.ACTION_COUNT]; 53 private ResultColumnList[] columnLists = new ResultColumnList[ TablePrivilegeInfo.ACTION_COUNT]; 54 private FormatableBitSet[] columnBitSets = new FormatableBitSet[ TablePrivilegeInfo.ACTION_COUNT]; 55 private TableDescriptor td; 56 private List descriptorList; 57 58 61 public void addAll() 62 { 63 for( int i = 0; i < TablePrivilegeInfo.ACTION_COUNT; i++) 64 { 65 actionAllowed[i] = true; 66 columnLists[i] = null; 67 } 68 } 70 78 public void addAction( int action, ResultColumnList privilegeColumnList) 79 { 80 actionAllowed[ action] = true; 81 if( privilegeColumnList == null) 82 columnLists[ action] = null; 83 else if( columnLists[ action] == null) 84 columnLists[ action] = privilegeColumnList; 85 else 86 columnLists[ action].appendResultColumns( privilegeColumnList, false); 87 } 89 95 public void bind( TableDescriptor td, boolean isGrant) throws StandardException 96 { 97 this.td = td; 98 99 for( int action = 0; action < TablePrivilegeInfo.ACTION_COUNT; action++) 100 { 101 if( columnLists[ action] != null) 102 columnBitSets[action] = columnLists[ action].bindResultColumnsByName( td, (DMLStatementNode) null); 103 104 if (td.getTableType() == TableDescriptor.VIEW_TYPE && action != TablePrivilegeInfo.SELECT_ACTION) 106 if (actionAllowed[action]) 107 throw StandardException.newException(SQLState.AUTH_GRANT_REVOKE_NOT_ALLOWED, 108 td.getQualifiedName()); 109 } 110 111 if (isGrant && td.getTableType() == TableDescriptor.VIEW_TYPE) 112 { 113 bindPrivilegesForView(td); 114 } 115 } 116 117 120 public PrivilegeInfo makePrivilegeInfo() 121 { 122 return new TablePrivilegeInfo( td, actionAllowed, columnBitSets, 123 descriptorList); 124 } 125 126 140 private void bindPrivilegesForView ( TableDescriptor td) 141 throws StandardException 142 { 143 LanguageConnectionContext lcc = getLanguageConnectionContext(); 144 DataDictionary dd = lcc.getDataDictionary(); 145 ViewDescriptor vd = dd.getViewDescriptor(td); 146 DependencyManager dm = dd.getDependencyManager(); 147 ProviderInfo[] pis = dm.getPersistentProviderInfos(vd); 148 this.descriptorList = new ArrayList (); 149 150 int siz = pis.length; 151 for (int i=0; i < siz; i++) 152 { 153 try 154 { 155 Provider provider = (Provider) pis[i].getDependableFinder().getDependable(pis[i].getObjectId()); 156 if (provider == null) 157 { 158 throw StandardException.newException( 159 SQLState.LANG_OBJECT_NOT_FOUND, 160 "OBJECT", 161 pis[i].getObjectId()); 162 } 163 164 if (provider instanceof TableDescriptor || 165 provider instanceof ViewDescriptor || 166 provider instanceof AliasDescriptor) 167 { 168 descriptorList.add(provider); 169 } 170 } 171 catch(java.sql.SQLException ex) 172 { 173 throw StandardException.plainWrapException(ex); 174 } 175 } 176 } 177 178 } 179 180 | Popular Tags |