Search in sources :

Example 51 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class RenameConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 * The guts of the Execution-time logic for RENAME TABLE/COLUMN/INDEX.
 *
 * @see ConstantAction#executeConstantAction
 *
 * @exception StandardException Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    TableDescriptor td;
    UUID tableID;
    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);
    td = dd.getTableDescriptor(tableId);
    if (td == null) {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
    }
    /*
		** 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.
		*/
    if (sd == null) {
        sd = getAndCheckSchemaDescriptor(dd, schemaId, "RENAME TABLE");
    }
    long heapId = td.getHeapConglomerateId();
    /* need to lock table, beetle 4271
		 */
    lockTableForDDL(tc, heapId, true);
    /* need to get td again, in case it's changed before lock acquired
		 */
    td = dd.getTableDescriptor(tableId);
    if (td == null) {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
    }
    switch(renamingWhat) {
        case StatementType.RENAME_TABLE:
            execGutsRenameTable(td, activation);
            break;
        case StatementType.RENAME_COLUMN:
            execGutsRenameColumn(td, activation);
            break;
        case StatementType.RENAME_INDEX:
            execGutsRenameIndex(td, activation);
            break;
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Unexpected rename action in RenameConstantAction");
            }
            break;
    }
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) UUID(org.apache.derby.catalog.UUID) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 52 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext in project derby by apache.

the class RenameConstantAction method execGutsRenameIndex.

// do necessary work for rename index at execute time.
private void execGutsRenameIndex(TableDescriptor td, Activation activation) throws StandardException {
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    // for indexes, we only invalidate sps, rest we ignore(ie views)
    dm.invalidateFor(td, DependencyManager.RENAME_INDEX, lcc);
    ConglomerateDescriptor conglomerateDescriptor = dd.getConglomerateDescriptor(oldObjectName, sd, true);
    if (conglomerateDescriptor == null)
        throw StandardException.newException(SQLState.LANG_INDEX_NOT_FOUND_DURING_EXECUTION, oldObjectName);
    /* Drop the index descriptor */
    dd.dropConglomerateDescriptor(conglomerateDescriptor, tc);
    // Change the index name of the index descriptor
    conglomerateDescriptor.setConglomerateName(newObjectName);
    // add the index descriptor with new name
    dd.addDescriptor(conglomerateDescriptor, sd, DataDictionary.SYSCONGLOMERATES_CATALOG_NUM, false, tc);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 53 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext 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 54 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext 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 55 with LanguageConnectionContext

use of org.apache.derby.iapi.sql.conn.LanguageConnectionContext 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)

Aggregations

LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)126 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)47 StandardException (org.apache.derby.shared.common.error.StandardException)36 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)20 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 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)10 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 SQLException (java.sql.SQLException)5 Iterator (java.util.Iterator)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)5 ArrayList (java.util.ArrayList)4