Search in sources :

Example 11 with TransactionController

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

the class TriggerDescriptor method drop.

public void drop(LanguageConnectionContext lcc) throws StandardException {
    DataDictionary dd = getDataDictionary();
    DependencyManager dm = getDataDictionary().getDependencyManager();
    TransactionController tc = lcc.getTransactionExecute();
    dm.invalidateFor(this, DependencyManager.DROP_TRIGGER, lcc);
    // Drop the trigger
    dd.dropTriggerDescriptor(this, tc);
    // Clear the dependencies for the trigger
    dm.clearDependencies(lcc, this);
    // Drop the spses
    SPSDescriptor spsd = dd.getSPSDescriptor(this.getActionId());
    // there shouldn't be any dependencies, but in case
    // there are, lets clear them
    dm.invalidateFor(spsd, DependencyManager.DROP_TRIGGER, lcc);
    dm.clearDependencies(lcc, spsd);
    dd.dropSPSDescriptor(spsd, tc);
    if (getWhenClauseId() != null) {
        spsd = dd.getSPSDescriptor(getWhenClauseId());
        dm.invalidateFor(spsd, DependencyManager.DROP_TRIGGER, lcc);
        dm.clearDependencies(lcc, spsd);
        dd.dropSPSDescriptor(spsd, tc);
    }
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 12 with TransactionController

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

the class ConstraintDescriptor method drop.

/**
 * Drop the constraint.  Clears dependencies, drops
 * the backing index and removes the constraint
 * from the list on the table descriptor.  Does NOT
 * do an dm.invalidateFor()
 *
 * @return If the backing conglomerate for this constraint
 *  was a) dropped and b) shared by other constraints/indexes,
 *  then this method will return a ConglomerateDescriptor that
 *  describes what a new backing conglomerate must look like
 *  to stay "sharable" across the remaining constraints/indexes.
 *  It is then up to the caller to create a corresponding
 *  conglomerate.  We don't create the conglomerate here
 *  because depending on who called us, it might not make
 *  sense to create it--ex. if we get here because of a DROP
 *  TABLE, the DropTable action doesn't need to create a
 *  new backing conglomerate since the table (and all of
 *  its constraints/indexes) are going to disappear anyway.
 */
public ConglomerateDescriptor drop(LanguageConnectionContext lcc, boolean clearDependencies) throws StandardException {
    DataDictionary dd = getDataDictionary();
    TransactionController tc = lcc.getTransactionExecute();
    if (clearDependencies) {
        DependencyManager dm = dd.getDependencyManager();
        dm.clearDependencies(lcc, this);
    }
    /* Drop the constraint.
         * NOTE: This must occur before dropping any backing index, since
         * a user is not allowed to drop a backing index without dropping
         * the constraint.
         */
    dd.dropConstraintDescriptor(this, tc);
    /* Drop the index, if there's one for this constraint.
         * NOTE: There will always be an indexAction. We don't
         * force the constraint to exist at bind time, so we always
         * generate one.
         */
    ConglomerateDescriptor newBackingConglomCD = null;
    if (hasBackingIndex()) {
        // it may have duplicates, and we drop a backing index
        // Bug 4307
        // We need to get the conglomerate descriptors from the
        // dd in case we dropped other constraints in a cascade operation.
        ConglomerateDescriptor[] conglomDescs = dd.getConglomerateDescriptors(getConglomerateId());
        // information since they point to the same physical index.
        for (ConglomerateDescriptor cd : conglomDescs) {
            if (cd.isConstraint()) {
                newBackingConglomCD = cd.drop(lcc, table);
                break;
            }
        }
    }
    table.removeConstraintDescriptor(this);
    return newBackingConglomCD;
}
Also used : DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 13 with TransactionController

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

the class EmbedConnection method checkUserIsNotARole.

/**
 * If applicable, check that we don't connect with a user name
 * that equals a role.
 *
 * @exception SQLException Will throw if the current authorization
 *            id in {@code lcc} (which is already normalized to
 *            case normal form - CNF) equals an existing role name
 *            (which is also stored in CNF).
 */
private void checkUserIsNotARole() throws SQLException {
    TransactionResourceImpl tr = getTR();
    try {
        tr.startTransaction();
        LanguageConnectionContext lcc = tr.getLcc();
        String username = lcc.getSessionUserId();
        DataDictionary dd = lcc.getDataDictionary();
        // introduced in 10.4):
        if (lcc.usesSqlAuthorization() && dd.checkVersion(DataDictionary.DD_VERSION_DERBY_10_4, null)) {
            TransactionController tc = lcc.getTransactionExecute();
            String failedString = MessageService.getTextMessage(MessageId.AUTH_INVALID);
            if (dd.getRoleDefinitionDescriptor(username) != null) {
                throw newSQLException(SQLState.NET_CONNECT_AUTH_FAILED, failedString);
            }
        }
        tr.rollback();
        InterruptStatus.restoreIntrFlagIfSeen(lcc);
    } catch (StandardException e) {
        try {
            tr.rollback();
        } catch (StandardException ee) {
        }
        throw handleException(e);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) TransactionController(org.apache.derby.iapi.store.access.TransactionController) XATransactionController(org.apache.derby.iapi.store.access.XATransactionController)

Example 14 with TransactionController

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

the class BasicDatabase method getAllDatabaseProperties.

/**
 * Get the set of database properties from the set stored
 * on disk outside of service.properties.
 */
protected Properties getAllDatabaseProperties() throws StandardException {
    TransactionController tc = af.getTransaction(getContextService().getCurrentContextManager());
    Properties dbProps = tc.getProperties();
    tc.commit();
    tc.destroy();
    return dbProps;
}
Also used : TransactionController(org.apache.derby.iapi.store.access.TransactionController) Properties(java.util.Properties) DoubleProperties(org.apache.derby.iapi.util.DoubleProperties)

Example 15 with TransactionController

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

the class BasicDatabase method makeDatabaseID.

protected UUID makeDatabaseID(boolean create, Properties startParams) throws StandardException {
    TransactionController tc = af.getTransaction(getContextService().getCurrentContextManager());
    String upgradeID = null;
    UUID databaseID;
    if ((databaseID = (UUID) tc.getProperty(DataDictionary.DATABASE_ID)) == null) {
        // no property defined in the Transaction set
        // this could be an upgrade, see if it's stored in the service set
        UUIDFactory uuidFactory = getMonitor().getUUIDFactory();
        upgradeID = startParams.getProperty(DataDictionary.DATABASE_ID);
        if (upgradeID == null) {
            // just create one
            databaseID = uuidFactory.createUUID();
        } else {
            databaseID = uuidFactory.recreateUUID(upgradeID);
        }
        tc.setProperty(DataDictionary.DATABASE_ID, databaseID, true);
    }
    // property set.
    if (upgradeID != null)
        startParams.remove(DataDictionary.DATABASE_ID);
    tc.commit();
    tc.destroy();
    return databaseID;
}
Also used : UUIDFactory(org.apache.derby.iapi.services.uuid.UUIDFactory) TransactionController(org.apache.derby.iapi.store.access.TransactionController) UUID(org.apache.derby.catalog.UUID)

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