1 21 22 package org.apache.derby.impl.sql.execute; 23 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 import org.apache.derby.iapi.services.monitor.Monitor; 28 29 import org.apache.derby.iapi.services.sanity.SanityManager; 30 31 import org.apache.derby.iapi.services.io.FormatIdUtil; 32 import org.apache.derby.iapi.services.io.Formatable; 33 import org.apache.derby.iapi.services.io.StoredFormatIds; 34 35 import org.apache.derby.iapi.error.StandardException; 36 37 import org.apache.derby.iapi.sql.conn.Authorizer; 38 import org.apache.derby.iapi.sql.conn.LanguageConnectionContext; 39 40 import org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor; 41 import org.apache.derby.iapi.sql.dictionary.DataDictionary; 42 import org.apache.derby.iapi.sql.dictionary.DataDictionaryContext; 43 import org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor; 44 import org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor; 45 import org.apache.derby.iapi.sql.dictionary.SchemaDescriptor; 46 import org.apache.derby.iapi.sql.dictionary.StatementColumnPermission; 47 import org.apache.derby.iapi.sql.dictionary.StatementPermission; 48 import org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission; 49 import org.apache.derby.iapi.sql.dictionary.StatementSchemaPermission; 50 import org.apache.derby.iapi.sql.dictionary.StatementTablePermission; 51 52 import org.apache.derby.iapi.sql.depend.Dependency; 53 import org.apache.derby.iapi.sql.depend.Dependent; 54 import org.apache.derby.iapi.sql.depend.DependencyManager; 55 56 import org.apache.derby.iapi.sql.Activation; 57 58 import org.apache.derby.iapi.reference.SQLState; 59 60 import org.apache.derby.iapi.sql.execute.ConstantAction; 61 62 import org.apache.derby.iapi.store.access.ConglomerateController; 63 import org.apache.derby.iapi.store.access.TransactionController; 64 65 import org.apache.derby.catalog.UUID; 66 67 73 public abstract class DDLConstantAction extends GenericConstantAction 74 { 75 81 85 93 98 99 102 107 119 static SchemaDescriptor getAndCheckSchemaDescriptor( 120 DataDictionary dd, 121 UUID schemaId, 122 String statementType) 123 throws StandardException 124 { 125 SchemaDescriptor sd = dd.getSchemaDescriptor(schemaId, null); 126 return sd; 127 } 128 129 141 static SchemaDescriptor getSchemaDescriptorForCreate( 142 DataDictionary dd, 143 Activation activation, 144 String schemaName) 145 throws StandardException 146 { 147 TransactionController tc = activation.getLanguageConnectionContext().getTransactionExecute(); 148 SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, false); 149 150 if (sd == null || sd.getUUID() == null) { 151 ConstantAction csca 152 = new CreateSchemaConstantAction(schemaName, (String ) null); 153 154 try { 155 csca.executeConstantAction(activation); 156 } catch (StandardException se) { 157 if (se.getMessageId() 158 .equals(SQLState.LANG_OBJECT_ALREADY_EXISTS)) { 159 } else { 162 throw se; 163 } 164 } 165 166 sd = dd.getSchemaDescriptor(schemaName, tc, true); 167 } 168 169 return sd; 170 } 171 172 181 final void lockTableForDDL(TransactionController tc, 182 long heapConglomerateNumber, boolean exclusiveMode) 183 throws StandardException 184 { 185 ConglomerateController cc; 186 187 cc = tc.openConglomerate( 188 heapConglomerateNumber, 189 false, 190 (exclusiveMode) ? 191 (TransactionController.OPENMODE_FORUPDATE | 192 TransactionController.OPENMODE_FOR_LOCK_ONLY) : 193 TransactionController.OPENMODE_FOR_LOCK_ONLY, 194 TransactionController.MODE_TABLE, 195 TransactionController.ISOLATION_SERIALIZABLE); 196 cc.close(); 197 } 198 199 protected String constructToString( 200 String statementType, 201 String objectName) 202 { 203 206 return statementType + objectName; 207 } 208 209 210 242 protected void storeConstraintDependenciesOnPrivileges( 243 Activation activation, Dependent dependent, UUID refTableUUID) 244 throws StandardException 245 { 246 LanguageConnectionContext lcc = activation.getLanguageConnectionContext(); 247 DataDictionary dd = lcc.getDataDictionary(); 248 DependencyManager dm = dd.getDependencyManager(); 249 250 if (!(lcc.getAuthorizationId().equals(dd.getAuthorizationDatabaseOwner()))) 254 { 255 PermissionsDescriptor permDesc; 256 List requiredPermissionsList = activation.getPreparedStatement().getRequiredPermissionsList(); 261 if (requiredPermissionsList != null && ! requiredPermissionsList.isEmpty()) 262 { 263 for(Iterator iter = requiredPermissionsList.iterator();iter.hasNext();) 264 { 265 StatementPermission statPerm = (StatementPermission) iter.next(); 266 if (statPerm instanceof StatementTablePermission) 270 { StatementTablePermission statementTablePermission = 272 (StatementTablePermission) statPerm; 273 if (statementTablePermission.getPrivType() != Authorizer.REFERENCES_PRIV) 277 continue; 278 if (!statementTablePermission.getTableUUID().equals(refTableUUID)) 283 continue; 284 } else if (statPerm instanceof StatementSchemaPermission 285 || statPerm instanceof StatementRoutinePermission) 286 continue; 287 288 permDesc = statPerm.getPermissionDescriptor(lcc.getAuthorizationId(), dd); 298 if (permDesc == null) 299 { 300 permDesc = statPerm.getPermissionDescriptor(Authorizer.PUBLIC_AUTHORIZATION_ID, dd); 304 if (!(permDesc.checkOwner(lcc.getAuthorizationId()))) 305 dm.addDependency(dependent, permDesc, lcc.getContextManager()); 306 } else 307 if (!(permDesc.checkOwner(lcc.getAuthorizationId()))) 311 { 312 dm.addDependency(dependent, permDesc, lcc.getContextManager()); 313 if (permDesc instanceof ColPermsDescriptor) 314 { 315 StatementColumnPermission statementColumnPermission = (StatementColumnPermission) statPerm; 323 permDesc = statementColumnPermission.getPUBLIClevelColPermsDescriptor(lcc.getAuthorizationId(), dd); 324 if (permDesc != null) 329 dm.addDependency(dependent, permDesc, lcc.getContextManager()); 330 } 331 } 332 break; 337 } 338 } 339 } 340 341 } 342 343 373 protected void storeViewTriggerDependenciesOnPrivileges( 374 Activation activation, Dependent dependent) 375 throws StandardException 376 { 377 LanguageConnectionContext lcc = activation.getLanguageConnectionContext(); 378 DataDictionary dd = lcc.getDataDictionary(); 379 DependencyManager dm = dd.getDependencyManager(); 380 381 if (!(lcc.getAuthorizationId().equals(dd.getAuthorizationDatabaseOwner()))) 385 { 386 PermissionsDescriptor permDesc; 387 List requiredPermissionsList = activation.getPreparedStatement().getRequiredPermissionsList(); 388 if (requiredPermissionsList != null && ! requiredPermissionsList.isEmpty()) 389 { 390 for(Iterator iter = requiredPermissionsList.iterator();iter.hasNext();) 391 { 392 StatementPermission statPerm = (StatementPermission) iter.next(); 393 if (statPerm instanceof StatementSchemaPermission) 400 continue; 401 permDesc = statPerm.getPermissionDescriptor(lcc.getAuthorizationId(), dd); 403 if (permDesc == null) { 405 permDesc = statPerm.getPermissionDescriptor(Authorizer.PUBLIC_AUTHORIZATION_ID, dd); 409 if (!(permDesc.checkOwner(lcc.getAuthorizationId()))) 413 dm.addDependency(dependent, permDesc, lcc.getContextManager()); 414 continue; 415 } 416 if (!(permDesc.checkOwner(lcc.getAuthorizationId()))) 420 { 421 dm.addDependency(dependent, permDesc, lcc.getContextManager()); 422 if (permDesc instanceof ColPermsDescriptor) 423 { 424 StatementColumnPermission statementColumnPermission = (StatementColumnPermission) statPerm; 444 permDesc = statementColumnPermission.getPUBLIClevelColPermsDescriptor(lcc.getAuthorizationId(), dd); 445 if (permDesc != null) 450 dm.addDependency(dependent, permDesc, lcc.getContextManager()); 451 } 452 } 453 } 454 } 455 456 } 457 } 458 } 459 460 | Popular Tags |