Search in sources :

Example 61 with DataDictionary

use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.

the class T_ConsistencyChecker method countDependencies.

/**
 * Check to make sure that there are no active dependencies (stored or
 * in memory).
 *
 * @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
 * @exception java.sql.SQLException     Thrown on error
 */
public static String countDependencies() throws StandardException, java.sql.SQLException {
    int numDependencies = 0;
    DataDictionary dd;
    DependencyManager dm;
    StringBuffer debugBuf = new StringBuffer();
    LanguageConnectionContext lcc = (LanguageConnectionContext) getContext(LanguageConnectionContext.CONTEXT_ID);
    dd = lcc.getDataDictionary();
    dm = dd.getDependencyManager();
    numDependencies = dm.countDependencies();
    if (numDependencies > 0) {
        debugBuf.append(numDependencies + " dependencies found");
    } else {
        debugBuf.append("No outstanding dependencies.\n");
    }
    return debugBuf.toString();
}
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)

Example 62 with DataDictionary

use of org.apache.derby.iapi.sql.dictionary.DataDictionary 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;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) Properties(java.util.Properties) 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 63 with DataDictionary

use of org.apache.derby.iapi.sql.dictionary.DataDictionary 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);
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) DependencyManager(org.apache.derby.iapi.sql.depend.DependencyManager) 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 64 with DataDictionary

use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.

the class GenericLanguageConnectionContext method isEffectivelyDeferred.

public boolean isEffectivelyDeferred(SQLSessionContext sc, UUID constraintId) throws StandardException {
    final Boolean deferred = sc.isDeferred(constraintId);
    final boolean effectivelyDeferred;
    final DataDictionary dd = getDataDictionary();
    if (deferred != null) {
        effectivelyDeferred = deferred.booleanValue();
    } else {
        // no explicit setting applicable, use initial constraint mode
        final ConstraintDescriptor conDesc = dd.getConstraintDescriptor(constraintId);
        effectivelyDeferred = conDesc.initiallyDeferred();
    }
    return effectivelyDeferred;
}
Also used : CheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 65 with DataDictionary

use of org.apache.derby.iapi.sql.dictionary.DataDictionary in project derby by apache.

the class GenericLanguageConnectionContext method initDefaultSchemaDescriptor.

/**
 * Compute the initial default schema and set
 * cachedInitialDefaultSchemaDescr accordingly.
 *
 * @return computed initial default schema value for this session
 * @throws StandardException
 */
protected SchemaDescriptor initDefaultSchemaDescriptor() throws StandardException {
    /*
        ** - If the database supports schemas and a schema with the
        ** same name as the user's name exists (has been created using
        ** create schema already) the database will set the users
        ** default schema to the the schema with the same name as the
        ** user.
        ** - Else Set the default schema to APP.
        */
    if (cachedInitialDefaultSchemaDescr == null) {
        DataDictionary dd = getDataDictionary();
        SchemaDescriptor sd = dd.getSchemaDescriptor(getSessionUserId(), getTransactionCompile(), false);
        if (sd == null) {
            sd = new SchemaDescriptor(dd, getSessionUserId(), getSessionUserId(), (UUID) null, false);
        }
        cachedInitialDefaultSchemaDescr = sd;
    }
    return cachedInitialDefaultSchemaDescr;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) UUID(org.apache.derby.catalog.UUID)

Aggregations

DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)102 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)57 TransactionController (org.apache.derby.iapi.store.access.TransactionController)40 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)33 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)23 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)22 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)17 StandardException (org.apache.derby.shared.common.error.StandardException)16 UUID (org.apache.derby.catalog.UUID)15 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)15 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)13 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)10 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)9 RoleGrantDescriptor (org.apache.derby.iapi.sql.dictionary.RoleGrantDescriptor)8 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)7 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)7 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)6 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)6 Iterator (java.util.Iterator)5