use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class GrantRoleConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for GRANT role.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
final String grantor = lcc.getCurrentUserId(activation);
dd.startWriting(lcc);
for (Iterator rIter = roleNames.iterator(); rIter.hasNext(); ) {
String role = (String) rIter.next();
if (role.equals(Authorizer.PUBLIC_AUTHORIZATION_ID)) {
throw StandardException.newException(SQLState.AUTH_PUBLIC_ILLEGAL_AUTHORIZATION_ID);
}
for (Iterator gIter = grantees.iterator(); gIter.hasNext(); ) {
String grantee = (String) gIter.next();
// check that role exists
RoleGrantDescriptor rdDef = dd.getRoleDefinitionDescriptor(role);
if (rdDef == null) {
throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION, role);
}
// :
if (grantor.equals(lcc.getDataDictionary().getAuthorizationDatabaseOwner())) {
// All ok, we are database owner
if (SanityManager.DEBUG) {
SanityManager.ASSERT(rdDef.getGrantee().equals(grantor), "expected database owner in role grant descriptor");
SanityManager.ASSERT(rdDef.isWithAdminOption(), "expected role definition to have ADMIN OPTION");
}
} else {
throw StandardException.newException(SQLState.AUTH_ROLE_DBO_ONLY, "GRANT role");
}
// Has it already been granted?
RoleGrantDescriptor rgd = dd.getRoleGrantDescriptor(role, grantee, grantor);
if (rgd != null && withAdminOption && !rgd.isWithAdminOption()) {
// NOTE: Never called yet, withAdminOption not yet
// implemented.
// Remove old descriptor and add a new one with admin
// option: cf. SQL 2003, section 12.5, general rule 3
rgd.drop(lcc);
rgd.setWithAdminOption(true);
dd.addDescriptor(rgd, // parent
null, DataDictionary.SYSROLES_CATALOG_NUM, // no duplicatesAllowed
false, tc);
} else if (rgd == null) {
// Check if the grantee is a role (if not, it is a user)
RoleGrantDescriptor granteeDef = dd.getRoleDefinitionDescriptor(grantee);
if (granteeDef != null) {
checkCircularity(role, grantee, grantor, tc, dd);
}
rgd = ddg.newRoleGrantDescriptor(dd.getUUIDFactory().createUUID(), role, grantee, // dbo for now
grantor, withAdminOption, // not definition
false);
dd.addDescriptor(rgd, // parent
null, DataDictionary.SYSROLES_CATALOG_NUM, // no duplicatesAllowed
false, tc);
}
// else exists already, no need to add
}
}
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class DropIndexConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for DROP INDEX.
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
TableDescriptor td;
ConglomerateDescriptor cd;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
// older version (or target) has to get td first, potential deadlock
if (tableConglomerateId == 0) {
td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
}
tableConglomerateId = td.getHeapConglomerateId();
}
lockTableForDDL(tc, tableConglomerateId, true);
td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
}
/*
** If the schema descriptor is null, then
** we must have just read ourselves in.
** So we will get the corresponding schema
** descriptor from the data dictionary.
*/
SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
/* Get the conglomerate descriptor for the index, along
* with an exclusive row lock on the row in sys.sysconglomerates
* in order to ensure that no one else compiles against the
* index.
*/
cd = dd.getConglomerateDescriptor(indexName, sd, true);
if (cd == null) {
throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION, fullIndexName);
}
/* Since we support the sharing of conglomerates across
* multiple indexes, dropping the physical conglomerate
* for the index might affect other indexes/constraints
* which share the conglomerate. The following call will
* deal with that situation by creating a new physical
* conglomerate to replace the dropped one, if necessary.
*/
dropConglomerate(cd, td, activation, lcc);
return;
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class DropRoleConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for DROP ROLE.
*
* @see org.apache.derby.iapi.sql.execute.ConstantAction#executeConstantAction
*/
public void executeConstantAction(Activation activation) throws StandardException {
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
RoleGrantDescriptor rdDef = dd.getRoleDefinitionDescriptor(roleName);
if (rdDef == null) {
throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION, roleName);
}
// When a role is dropped, for every role in its grantee closure, we
// call the REVOKE_ROLE action. It is used to invalidate dependent
// objects (constraints, triggers and views). Note that until
// DERBY-1632 is fixed, we risk dropping objects not really dependent
// on this role, but one some other role just because it inherits from
// this one. See also RevokeRoleConstantAction.
RoleClosureIterator rci = dd.createRoleClosureIterator(activation.getTransactionController(), roleName, false);
String role;
while ((role = rci.next()) != null) {
RoleGrantDescriptor r = dd.getRoleDefinitionDescriptor(role);
dd.getDependencyManager().invalidateFor(r, DependencyManager.REVOKE_ROLE, lcc);
}
rdDef.drop(lcc);
/*
* We dropped a role, now drop all dependents:
* - role grants to this role
* - grants of this role to other roles or users
* - privilege grants to this role
*/
dd.dropRoleGrantsByGrantee(roleName, tc);
dd.dropRoleGrantsByName(roleName, tc);
dd.dropAllPermsByGrantee(roleName, tc);
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class DropSequenceConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for DROP SEQUENCE.
*
* @see org.apache.derby.iapi.sql.execute.ConstantAction#executeConstantAction
*/
public void executeConstantAction(Activation activation) throws StandardException {
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
TransactionController tc = lcc.getTransactionExecute();
/*
** Inform the data dictionary that we are about to write to it.
** There are several calls to data dictionary "get" methods here
** that might be done in "read" mode in the data dictionary, but
** it seemed safer to do this whole operation in "write" mode.
**
** We tell the data dictionary we're done writing at the end of
** the transaction.
*/
dd.startWriting(lcc);
dd.clearSequenceCaches();
SequenceDescriptor sequenceDescriptor = dd.getSequenceDescriptor(schemaDescriptor, sequenceName);
if (sequenceDescriptor == null) {
throw StandardException.newException(SQLState.LANG_OBJECT_NOT_FOUND_DURING_EXECUTION, "SEQUENCE", (schemaDescriptor.getObjectName() + "." + sequenceName));
}
sequenceDescriptor.drop(lcc);
}
use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.
the class DropTableConstantAction method dropAllConstraintDescriptors.
private void dropAllConstraintDescriptors(TableDescriptor td, Activation activation) throws StandardException {
ConstraintDescriptor cd;
ConstraintDescriptorList cdl;
ConstraintDescriptor fkcd;
ConstraintDescriptorList fkcdl;
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
DependencyManager dm = dd.getDependencyManager();
TransactionController tc = lcc.getTransactionExecute();
cdl = dd.getConstraintDescriptors(td);
/* The current element will be deleted underneath
* the loop, so we only increment the counter when
* skipping an element. (HACK!)
*/
for (int index = 0; index < cdl.size(); ) {
cd = cdl.elementAt(index);
if (cd instanceof ReferencedKeyConstraintDescriptor) {
index++;
continue;
}
dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT, lcc);
dropConstraint(cd, td, activation, lcc, true);
}
/* The current element will be deleted underneath
* the loop. (HACK!)
*/
while (cdl.size() > 0) {
cd = cdl.elementAt(0);
if (SanityManager.DEBUG) {
if (!(cd instanceof ReferencedKeyConstraintDescriptor)) {
SanityManager.THROWASSERT("Constraint descriptor not an instance of " + "ReferencedKeyConstraintDescriptor as expected. Is a " + cd.getClass().getName());
}
}
/*
** Drop the referenced constraint (after we got
** the primary keys) now. Do this prior to
** droping the referenced keys to avoid performing
** a lot of extra work updating the referencedcount
** field of sys.sysconstraints.
**
** Pass in false to dropConstraintsAndIndex so it
** doesn't clear dependencies, we'll do that ourselves.
*/
dropConstraint(cd, td, activation, lcc, false);
/*
** If we are going to cascade, get all the
** referencing foreign keys and zap them first.
*/
if (cascade) {
/*
** Go to the system tables to get the foreign keys
** to be safe
*/
fkcdl = dd.getForeignKeys(cd.getUUID());
/*
** For each FK that references this key, drop
** it.
*/
for (int inner = 0; inner < fkcdl.size(); inner++) {
fkcd = (ConstraintDescriptor) fkcdl.elementAt(inner);
dm.invalidateFor(fkcd, DependencyManager.DROP_CONSTRAINT, lcc);
dropConstraint(fkcd, td, activation, lcc, true);
activation.addWarning(StandardException.newWarning(SQLState.LANG_CONSTRAINT_DROPPED, fkcd.getConstraintName(), fkcd.getTableDescriptor().getName()));
}
}
/*
** Now that we got rid of the fks (if we were cascading), it is
** ok to do an invalidate for.
*/
dm.invalidateFor(cd, DependencyManager.DROP_CONSTRAINT, lcc);
dm.clearDependencies(lcc, cd);
}
}
Aggregations