Search in sources :

Example 56 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController 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;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Example 57 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController 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);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) 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 58 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController 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);
}
Also used : LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor)

Example 59 with TransactionController

use of org.apache.derby.iapi.store.access.TransactionController 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);
    }
}
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 60 with TransactionController

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

the class DropTableConstantAction method executeConstantAction.

// INTERFACE METHODS
/**
 *	This is the guts of the Execution-time logic for DROP TABLE.
 *
 *	@see ConstantAction#executeConstantAction
 *
 * @exception StandardException		Thrown on failure
 */
public void executeConstantAction(Activation activation) throws StandardException {
    TableDescriptor td;
    UUID tableID;
    ConglomerateDescriptor[] cds;
    LanguageConnectionContext lcc = activation.getLanguageConnectionContext();
    DataDictionary dd = lcc.getDataDictionary();
    DependencyManager dm = dd.getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    if ((sd != null) && sd.getSchemaName().equals(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME)) {
        // check if this is a temp table before checking data dictionary
        td = lcc.getTableDescriptorForDeclaredGlobalTempTable(tableName);
        if (// td null here means it is not a temporary table. Look for table in physical SESSION schema
        td == null)
            td = dd.getTableDescriptor(tableName, sd, tc);
        if (// td null means tableName is not a temp table and it is not a physical table in SESSION schema
        td == null) {
            throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
        }
        if (td.getTableType() == TableDescriptor.GLOBAL_TEMPORARY_TABLE_TYPE) {
            dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);
            tc.dropConglomerate(td.getHeapConglomerateId());
            lcc.dropDeclaredGlobalTempTable(tableName);
            return;
        }
    }
    /* Lock the table before we access the data dictionary
		 * to prevent deadlocks.
		 *
		 * Note that for DROP TABLE replayed at Targets during REFRESH,
		 * the conglomerateNumber will be 0. That's ok. During REFRESH,
		 * we don't need to lock the conglomerate.
		 */
    if (conglomerateNumber != 0) {
        lockTableForDDL(tc, conglomerateNumber, true);
    }
    /*
		** 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);
    /* Get the table descriptor. */
    td = dd.getTableDescriptor(tableId);
    if (td == null) {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND_DURING_EXECUTION, fullTableName);
    }
    /* Get an exclusive table lock on the table. */
    long heapId = td.getHeapConglomerateId();
    lockTableForDDL(tc, heapId, true);
    /* Drop the triggers */
    for (TriggerDescriptor trd : dd.getTriggerDescriptors(td)) {
        trd.drop(lcc);
    }
    /* Drop all defaults */
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    for (ColumnDescriptor cd : cdl) {
        // 
        if (cd.isAutoincrement() && dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_11, null)) {
            dropIdentitySequence(dd, td, activation);
        }
        // any dependencies
        if (cd.getDefaultInfo() != null) {
            DefaultDescriptor defaultDesc = cd.getDefaultDescriptor(dd);
            dm.clearDependencies(lcc, defaultDesc);
        }
    }
    /* Drop the columns */
    dd.dropAllColumnDescriptors(tableId, tc);
    /* Drop all table and column permission descriptors */
    dd.dropAllTableAndColPermDescriptors(tableId, tc);
    /* Drop the constraints */
    dropAllConstraintDescriptors(td, activation);
    /*
		** Drop all the conglomerates.  Drop the heap last, because the
		** store needs it for locking the indexes when they are dropped.
		*/
    cds = td.getConglomerateDescriptors();
    long[] dropped = new long[cds.length - 1];
    int numDropped = 0;
    for (int index = 0; index < cds.length; index++) {
        ConglomerateDescriptor cd = cds[index];
        /* if it's for an index, since similar indexes share one
			 * conglomerate, we only drop the conglomerate once
			 */
        if (cd.getConglomerateNumber() != heapId) {
            long thisConglom = cd.getConglomerateNumber();
            int i;
            for (i = 0; i < numDropped; i++) {
                if (dropped[i] == thisConglom)
                    break;
            }
            if (// not dropped
            i == numDropped) {
                dropped[numDropped++] = thisConglom;
                tc.dropConglomerate(thisConglom);
                dd.dropStatisticsDescriptors(td.getUUID(), cd.getUUID(), tc);
            }
        }
    }
    /* Prepare all dependents to invalidate.  (This is there chance
		 * to say that they can't be invalidated.  For example, an open
		 * cursor referencing a table/view that the user is attempting to
		 * drop.) If no one objects, then invalidate any dependent objects.
		 * We check for invalidation before we drop the table descriptor
		 * since the table descriptor may be looked up as part of
		 * decoding tuples in SYSDEPENDS.
		 */
    dm.invalidateFor(td, DependencyManager.DROP_TABLE, lcc);
    // 
    // The table itself can depend on the user defined types of its columns.
    // Drop all of those dependencies now.
    // 
    adjustUDTDependencies(lcc, dd, td, null, true);
    /* Drop the table */
    dd.dropTableDescriptor(td, sd, tc);
    /* Drop the conglomerate descriptors */
    dd.dropAllConglomerateDescriptors(td, tc);
    /* Drop the store element at last, to prevent dangling reference
		 * for open cursor, beetle 4393.
		 */
    tc.dropConglomerate(heapId);
}
Also used : ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) TriggerDescriptor(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor) 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) DefaultDescriptor(org.apache.derby.iapi.sql.dictionary.DefaultDescriptor)

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