Search in sources :

Example 46 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class RenameConstantAction method execGutsRenameTable.

// do necessary work for rename table at execute time.
private void execGutsRenameTable(TableDescriptor td, Activation activation) throws StandardException {
    ConstraintDescriptorList constraintDescriptorList;
    ConstraintDescriptor constraintDescriptor;
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    dm.invalidateFor(td, DependencyManager.RENAME, lcc);
    /* look for foreign key dependency on the table. If found any,
		use dependency manager to pass the rename action to the
		dependents. */
    constraintDescriptorList = dd.getConstraintDescriptors(td);
    for (int index = 0; index < constraintDescriptorList.size(); index++) {
        constraintDescriptor = constraintDescriptorList.elementAt(index);
        if (constraintDescriptor instanceof ReferencedKeyConstraintDescriptor)
            dm.invalidateFor(constraintDescriptor, DependencyManager.RENAME, lcc);
    }
    // Drop the table
    dd.dropTableDescriptor(td, sd, tc);
    // Change the table name of the table descriptor
    td.setTableName(newTableName);
    // add the table descriptor with new name
    dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 47 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class RevokeRoleConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 * This is the guts of the Execution-time logic for REVOKE 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();
    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, "REVOKE role");
            }
            RoleGrantDescriptor rd = dd.getRoleGrantDescriptor(role, grantee, grantor);
            if (rd != null && withAdminOption) {
                if (SanityManager.DEBUG) {
                    SanityManager.NOTREACHED();
                }
                // 
                if (rd.isWithAdminOption()) {
                // Invalidate and remove old descriptor and add a new
                // one without admin option.
                // 
                // RoleClosureIterator rci =
                // dd.createRoleClosureIterator
                // (activation.getTransactionController(),
                // role, false);
                // 
                // String r;
                // while ((r = rci.next()) != null) {
                // rdDef = dd.getRoleDefinitionDescriptor(r);
                // 
                // dd.getDependencyManager().invalidateFor
                // (rdDef, DependencyManager.REVOKE_ROLE, lcc);
                // }
                // 
                // rd.drop(lcc);
                // rd.setWithAdminOption(false);
                // dd.addDescriptor(rd,
                // null,  // parent
                // DataDictionary.SYSROLES_CATALOG_NUM,
                // false, // no duplicatesAllowed
                // tc);
                } else {
                    activation.addWarning(StandardException.newWarning(SQLState.LANG_WITH_ADMIN_OPTION_NOT_REVOKED, role, grantee));
                }
            } else if (rd != null) {
                // Normal revoke of role from grantee.
                // 
                // When a role is revoked, 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 DropRoleConstantAction.
                RoleClosureIterator rci = dd.createRoleClosureIterator(activation.getTransactionController(), role, false);
                String r;
                while ((r = rci.next()) != null) {
                    rdDef = dd.getRoleDefinitionDescriptor(r);
                    dd.getDependencyManager().invalidateFor(rdDef, DependencyManager.REVOKE_ROLE, lcc);
                }
                rd.drop(lcc);
            } else {
                activation.addWarning(StandardException.newWarning(SQLState.LANG_ROLE_NOT_REVOKED, role, grantee));
            }
        }
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) RoleClosureIterator(org.apache.derby.iapi.sql.dictionary.RoleClosureIterator) Iterator(java.util.Iterator) RoleClosureIterator(org.apache.derby.iapi.sql.dictionary.RoleClosureIterator) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) RoleGrantDescriptor(org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)

Example 48 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class CreateViewConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for CREATE VIEW.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    TableDescriptor td;
    UUID toid;
    ColumnDescriptor columnDescriptor;
    ViewDescriptor vd;
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    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);
    SchemaDescriptor sd = DDLConstantAction.getSchemaDescriptorForCreate(dd, activation, schemaName);
    /* Create a new table descriptor.
		 * (Pass in row locking, even though meaningless for views.)
		 */
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    td = ddg.newTableDescriptor(tableName, sd, tableType, TableDescriptor.ROW_LOCK_GRANULARITY);
    dd.addDescriptor(td, sd, DataDictionary.SYSTABLES_CATALOG_NUM, false, tc);
    toid = td.getUUID();
    // for each column, stuff system.column
    ColumnDescriptor[] cdlArray = new ColumnDescriptor[columnInfo.length];
    int index = 1;
    for (int ix = 0; ix < columnInfo.length; ix++) {
        columnDescriptor = new ColumnDescriptor(columnInfo[ix].name, index++, columnInfo[ix].dataType, columnInfo[ix].defaultValue, columnInfo[ix].defaultInfo, td, (UUID) null, columnInfo[ix].autoincStart, columnInfo[ix].autoincInc, columnInfo[ix].autoincCycle);
        cdlArray[ix] = columnDescriptor;
    }
    dd.addDescriptorArray(cdlArray, td, DataDictionary.SYSCOLUMNS_CATALOG_NUM, false, tc);
    // add columns to the column descriptor list.
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    for (int i = 0; i < cdlArray.length; i++) cdl.add(cdlArray[i]);
    /* Get and add a view descriptor */
    vd = ddg.newViewDescriptor(toid, tableName, viewText, checkOption, (compSchemaId == null) ? lcc.getDefaultSchema().getUUID() : compSchemaId);
    for (int ix = 0; ix < providerInfo.length; ix++) {
        /* We should always be able to find the Provider */
        Provider provider = (Provider) providerInfo[ix].getDependableFinder().getDependable(dd, providerInfo[ix].getObjectId());
        dm.addDependency(vd, provider, lcc.getContextManager());
    }
    // store view's dependency on various privileges in the dependeny system
    storeViewTriggerDependenciesOnPrivileges(activation, vd);
    dd.addDescriptor(vd, sd, DataDictionary.SYSVIEWS_CATALOG_NUM, true, tc);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ViewDescriptor(org.apache.derby.iapi.sql.dictionary.ViewDescriptor) Provider(org.apache.derby.iapi.sql.depend.Provider) DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) UUID(org.apache.derby.catalog.UUID) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 49 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class DDLConstantAction method adjustUDTDependencies.

/**
 * Add and drop dependencies of a routine on UDTs.
 *
 * @param lcc Interpreter's state variable for this session.
 * @param dd Metadata
 * @param ad Alias descriptor for the routine
 * @param adding True if we are adding dependencies, false if we're dropping them
 */
protected void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, AliasDescriptor ad, boolean adding) throws StandardException {
    RoutineAliasInfo routineInfo = null;
    AggregateAliasInfo aggInfo = null;
    // nothing to do if this is not a routine
    switch(ad.getAliasType()) {
        case AliasInfo.ALIAS_TYPE_AGGREGATE_AS_CHAR:
            aggInfo = (AggregateAliasInfo) ad.getAliasInfo();
            break;
        case AliasInfo.ALIAS_TYPE_PROCEDURE_AS_CHAR:
        case AliasInfo.ALIAS_TYPE_FUNCTION_AS_CHAR:
            routineInfo = (RoutineAliasInfo) ad.getAliasInfo();
            break;
        default:
            return;
    }
    TransactionController tc = lcc.getTransactionExecute();
    HashMap<String, AliasDescriptor> addUdtMap = new HashMap<String, AliasDescriptor>();
    HashMap<String, AliasDescriptor> dropUdtMap = new HashMap<String, AliasDescriptor>();
    HashMap<String, AliasDescriptor> udtMap = adding ? addUdtMap : dropUdtMap;
    TypeDescriptor rawReturnType = aggInfo != null ? aggInfo.getReturnType() : routineInfo.getReturnType();
    if (rawReturnType != null) {
        AliasDescriptor returnTypeAD = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(rawReturnType));
        if (returnTypeAD != null) {
            udtMap.put(returnTypeAD.getObjectID().toString(), returnTypeAD);
        }
    }
    // table functions can have udt columns. track those dependencies.
    if ((rawReturnType != null) && rawReturnType.isRowMultiSet()) {
        TypeDescriptor[] columnTypes = rawReturnType.getRowTypes();
        int columnCount = columnTypes.length;
        for (int i = 0; i < columnCount; i++) {
            AliasDescriptor columnTypeAD = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(columnTypes[i]));
            if (columnTypeAD != null) {
                udtMap.put(columnTypeAD.getObjectID().toString(), columnTypeAD);
            }
        }
    }
    TypeDescriptor[] paramTypes = aggInfo != null ? new TypeDescriptor[] { aggInfo.getForType() } : routineInfo.getParameterTypes();
    if (paramTypes != null) {
        int paramCount = paramTypes.length;
        for (int i = 0; i < paramCount; i++) {
            AliasDescriptor paramType = dd.getAliasDescriptorForUDT(tc, DataTypeDescriptor.getType(paramTypes[i]));
            if (paramType != null) {
                udtMap.put(paramType.getObjectID().toString(), paramType);
            }
        }
    }
    adjustUDTDependencies(lcc, dd, ad, addUdtMap, dropUdtMap);
}
Also used : RoutineAliasInfo(org.apache.derby.catalog.types.RoutineAliasInfo) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) HashMap(java.util.HashMap) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) AggregateAliasInfo(org.apache.derby.catalog.types.AggregateAliasInfo) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 50 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController in project derby by apache.

the class DDLConstantAction method adjustUDTDependencies.

/**
 * Add and drop dependencies of an object on UDTs.
 *
 * @param lcc Interpreter's state variable for this session.
 * @param dd Metadata
 * @param dependent Object which depends on UDT
 * @param addUdtMap Map of UDTs for which dependencies should be added
 * @param dropUdtMap Map of UDT for which dependencies should be dropped
 */
private void adjustUDTDependencies(LanguageConnectionContext lcc, DataDictionary dd, Dependent dependent, HashMap<String, AliasDescriptor> addUdtMap, HashMap<String, AliasDescriptor> dropUdtMap) throws StandardException {
    // again, nothing to do if there are no columns of udt type
    if ((addUdtMap.isEmpty()) && (dropUdtMap.isEmpty())) {
        return;
    }
    TransactionController tc = lcc.getTransactionExecute();
    DependencyManager dm = dd.getDependencyManager();
    ContextManager cm = lcc.getContextManager();
    // add new dependencies
    for (AliasDescriptor ad : addUdtMap.values()) {
        dm.addDependency(dependent, ad, cm);
    }
    // drop dependencies that are orphaned
    for (AliasDescriptor ad : dropUdtMap.values()) {
        DependencyDescriptor dep = new DependencyDescriptor(dependent, ad);
        dd.dropStoredDependency(dep, tc);
    }
}
Also used : DependencyDescriptor(org.apache.derby.iapi.sql.dictionary.DependencyDescriptor) ContextManager(org.apache.derby.iapi.services.context.ContextManager) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Aggregations

TransactionController (org.apache.derby.iapi.store.access.TransactionController)124 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)47 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)40 StandardException (org.apache.derby.shared.common.error.StandardException)26 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)23 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)20 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)20 UUID (org.apache.derby.catalog.UUID)14 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)13 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)12 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)12 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)12 Properties (java.util.Properties)11 AccessFactory (org.apache.derby.iapi.store.access.AccessFactory)11 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 XATransactionController (org.apache.derby.iapi.store.access.XATransactionController)9 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)8 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)8 ScanController (org.apache.derby.iapi.store.access.ScanController)8