use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class GenericPrivilegeInfo method executeGrantRevoke.
// /////////////////////////////////////////////////////////////////////////////////
//
// PrivilegeInfo BEHAVIOR
//
// /////////////////////////////////////////////////////////////////////////////////
/**
* This is the guts of the Execution-time logic for GRANT/REVOKE generic privileges.
*
* @param activation
* @param grant true if grant, false if revoke
* @param grantees a list of authorization ids (strings)
*
* @exception StandardException Thrown on failure
*/
public void executeGrantRevoke(Activation activation, boolean grant, List grantees) throws StandardException {
// Check that the current user has permission to grant the privileges.
LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
DataDictionary dd = lcc.getDataDictionary();
String currentUser = lcc.getCurrentUserId(activation);
TransactionController tc = lcc.getTransactionExecute();
SchemaDescriptor sd = _tupleDescriptor.getSchemaDescriptor();
UUID objectID = _tupleDescriptor.getUUID();
String objectTypeName = _tupleDescriptor.getObjectTypeName();
// Check that the current user has permission to grant the privileges.
checkOwnership(currentUser, (TupleDescriptor) _tupleDescriptor, sd, dd);
DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
PermDescriptor permDesc = ddg.newPermDescriptor(null, objectTypeName, objectID, _privilege, currentUser, null, false);
dd.startWriting(lcc);
for (Iterator itr = grantees.iterator(); itr.hasNext(); ) {
// Keep track to see if any privileges are revoked by a revoke
// statement. If a privilege is not revoked, we need to raise a
// warning.
boolean privileges_revoked = false;
String grantee = (String) itr.next();
if (dd.addRemovePermissionsDescriptor(grant, permDesc, grantee, tc)) {
//
// We fall in here if we are performing REVOKE.
//
privileges_revoked = true;
int invalidationType = _restrict ? DependencyManager.REVOKE_PRIVILEGE_RESTRICT : DependencyManager.REVOKE_PRIVILEGE;
dd.getDependencyManager().invalidateFor(permDesc, invalidationType, lcc);
// Now invalidate all GPSs refering to the object.
dd.getDependencyManager().invalidateFor(_tupleDescriptor, invalidationType, lcc);
}
addWarningIfPrivilegeNotRevoked(activation, grant, privileges_revoked, grantee);
}
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class SetRoleConstantAction method executeConstantAction.
// INTERFACE METHODS
/**
* This is the guts of the Execution-time logic for SET ROLE.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
LanguageConnectionContext lcc;
DataDictionary dd;
// find the language context.
lcc = activation.getLanguageConnectionContext();
dd = lcc.getDataDictionary();
String thisRoleName = roleName;
final String currentAuthId = lcc.getCurrentUserId(activation);
final String dbo = lcc.getDataDictionary().getAuthorizationDatabaseOwner();
TransactionController tc = lcc.getTransactionExecute();
// SQL 2003, section 18.3, General rule 1:
if (!tc.isIdle()) {
throw StandardException.newException(SQLState.INVALID_TRANSACTION_STATE_ACTIVE_CONNECTION);
}
if (type == StatementType.SET_ROLE_DYNAMIC) {
ParameterValueSet pvs = activation.getParameterValueSet();
DataValueDescriptor dvs = pvs.getParameter(0);
// SQL 2003, section 18.3, GR2: trim whitespace first, and
// interpret as identifier, then we convert it to case normal form
// here.
String roleId = dvs.getString();
if (roleId == null) {
throw StandardException.newException(SQLState.ID_PARSE_ERROR);
}
thisRoleName = IdUtil.parseRoleId(roleId);
}
RoleGrantDescriptor rdDef = null;
try {
String oldRole = lcc.getCurrentRoleId(activation);
if (oldRole != null && !oldRole.equals(thisRoleName)) {
rdDef = dd.getRoleDefinitionDescriptor(oldRole);
if (rdDef != null) {
dd.getDependencyManager().invalidateFor(rdDef, DependencyManager.RECHECK_PRIVILEGES, lcc);
}
// else: old role else no longer exists, so ignore.
}
if (thisRoleName != null) {
rdDef = dd.getRoleDefinitionDescriptor(thisRoleName);
// SQL 2003, section 18.3, General rule 4:
if (rdDef == null) {
throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION, thisRoleName);
}
if (!lcc.roleIsSettable(activation, thisRoleName)) {
throw StandardException.newException(SQLState.ROLE_INVALID_SPECIFICATION_NOT_GRANTED, thisRoleName);
}
}
} finally {
// reading above changes idle state, so reestablish it
lcc.userCommit();
}
lcc.setCurrentRole(activation, rdDef != null ? thisRoleName : null);
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class T_ConsistencyChecker method countOpens.
/**
* Check to make sure that there are no open conglomerates, scans or sorts.
*
* @return String If an inconsistency is found, and if DEBUG is on,
* then a string will be returned with more info.
* If DEBUG is off, then a simple string will be
* returned stating whether or not there are open scans.
*
* @exception StandardException Thrown on error
*/
public static String countOpens() throws StandardException {
int numOpens = 0;
LanguageConnectionContext lcc;
String output = "No open scans, etc.\n";
TransactionController tc;
lcc = (LanguageConnectionContext) getContext(LanguageConnectionContext.CONTEXT_ID);
tc = lcc.getTransactionExecute();
numOpens = tc.countOpens(TransactionController.OPEN_TOTAL);
if (numOpens > 0) {
output = numOpens + " conglomerates/scans/sorts found open\n";
}
return output;
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class TestPropertyInfo method getConglomerateProperties.
private static Properties getConglomerateProperties(String schemaName, String conglomerateName, boolean isIndex) throws java.sql.SQLException {
ConglomerateController cc;
ConglomerateDescriptor cd;
DataDictionary dd;
Properties properties;
SchemaDescriptor sd;
TableDescriptor td;
TransactionController tc;
long conglomerateNumber;
// find the language context.
LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
// Get the current transaction controller
tc = lcc.getTransactionExecute();
try {
// find the DataDictionary
dd = lcc.getDataDictionary();
// get the SchemaDescriptor
sd = dd.getSchemaDescriptor(schemaName, tc, true);
if (!isIndex) {
// get the TableDescriptor for the table
td = dd.getTableDescriptor(conglomerateName, sd, tc);
// Return an empty Properties if table does not exist or if it is for a view.
if ((td == null) || td.getTableType() == TableDescriptor.VIEW_TYPE) {
return new Properties();
}
conglomerateNumber = td.getHeapConglomerateId();
} else {
// get the ConglomerateDescriptor for the index
cd = dd.getConglomerateDescriptor(conglomerateName, sd, false);
// Return an empty Properties if index does not exist
if (cd == null) {
return new Properties();
}
conglomerateNumber = cd.getConglomerateNumber();
}
cc = tc.openConglomerate(conglomerateNumber, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
properties = cc.getInternalTablePropertySet(new Properties());
cc.close();
} catch (StandardException se) {
throw PublicAPI.wrapStandardException(se);
}
return properties;
}
use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.
the class AlterConstraintConstantAction method executeConstantAction.
/**
* This is the guts of the Execution-time logic for ALTER CONSTRAINT.
*
* @see ConstantAction#executeConstantAction
*
* @exception StandardException Thrown on failure
*/
public void executeConstantAction(Activation activation) throws StandardException {
final LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
final DataDictionary dd = lcc.getDataDictionary();
final DependencyManager dm = dd.getDependencyManager();
final 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);
final TableDescriptor td = dd.getTableDescriptor(tableId);
if (td == null) {
throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, tableName);
}
/* Table gets locked in AlterTableConstantAction */
/*
** 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 tdSd = td.getSchemaDescriptor();
SchemaDescriptor constraintSd = constraintSchemaName == null ? tdSd : dd.getSchemaDescriptor(constraintSchemaName, tc, true);
/* Get the constraint descriptor for the index, along
* with an exclusive row lock on the row in sys.sysconstraints
* in order to ensure that no one else compiles against the
* index.
*/
final ConstraintDescriptor conDesc = dd.getConstraintDescriptorByName(td, constraintSd, constraintName, true);
if (conDesc == null) {
throw StandardException.newException(SQLState.LANG_DROP_OR_ALTER_NON_EXISTING_CONSTRAINT, constraintSd.getSchemaName() + "." + constraintName, td.getQualifiedName());
}
if (characteristics[2] != ConstraintDefinitionNode.ENFORCED_DEFAULT) {
dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, "DEFERRED CONSTRAINTS");
if (constraintType == DataDictionary.FOREIGNKEY_CONSTRAINT || constraintType == DataDictionary.NOTNULL_CONSTRAINT || !characteristics[2]) /* not enforced */
{
// Remove when feature DERBY-532 is completed
if (!PropertyUtil.getSystemProperty("derby.constraintsTesting", "false").equals("true")) {
throw StandardException.newException(SQLState.NOT_IMPLEMENTED, "non-default enforcement");
}
}
}
// The first two characteristics are unused during ALTER CONSTRAINT; only
// enforcement can change.
conDesc.setEnforced(characteristics[2]);
int[] colsToSet = new int[1];
colsToSet[0] = SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_STATE;
dd.updateConstraintDescriptor(conDesc, conDesc.getUUID(), colsToSet, tc);
}
Aggregations