Search in sources :

Example 61 with SchemaDescriptor

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

the class DropSchemaConstantAction 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 {
    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);
    SchemaDescriptor sd = dd.getSchemaDescriptor(schemaName, tc, true);
    sd.drop(lcc, activation);
}
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)

Example 62 with SchemaDescriptor

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

the class QueryTreeNode method getUDTDesc.

/**
 * Get the AliasDescriptor of a UDT
 */
public AliasDescriptor getUDTDesc(DataTypeDescriptor dtd) throws StandardException {
    UserDefinedTypeIdImpl userTypeID = (UserDefinedTypeIdImpl) dtd.getTypeId().getBaseTypeId();
    DataDictionary dd = getDataDictionary();
    SchemaDescriptor typeSchema = getSchemaDescriptor(userTypeID.getSchemaName());
    char udtNameSpace = AliasInfo.ALIAS_NAME_SPACE_UDT_AS_CHAR;
    String unqualifiedTypeName = userTypeID.getUnqualifiedName();
    AliasDescriptor ad = dd.getAliasDescriptor(typeSchema.getUUID().toString(), unqualifiedTypeName, udtNameSpace);
    return ad;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) UserDefinedTypeIdImpl(org.apache.derby.catalog.types.UserDefinedTypeIdImpl) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary)

Example 63 with SchemaDescriptor

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

the class SYSCONSTRAINTSRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make a ConstraintDescriptor out of a SYSCONSTRAINTS row
 *
 * @param row a SYSCONSTRAINTS row
 * @param parentTupleDescriptor	Subconstraint descriptor with auxiliary info.
 * @param dd dataDictionary
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    ConstraintDescriptor constraintDesc = null;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(row.nColumns() == SYSCONSTRAINTS_COLUMN_COUNT, "Wrong number of columns for a SYSCONSTRAINTS row");
    }
    DataValueDescriptor col;
    ConglomerateDescriptor conglomDesc;
    DataDescriptorGenerator ddg;
    TableDescriptor td = null;
    int constraintIType = -1;
    int[] keyColumns = null;
    UUID constraintUUID;
    UUID schemaUUID;
    UUID tableUUID;
    UUID referencedConstraintId = null;
    SchemaDescriptor schema;
    String tableUUIDString;
    String constraintName;
    String constraintSType;
    String constraintStateStr;
    boolean deferrable = ConstraintDefinitionNode.DEFERRABLE_DEFAULT;
    boolean initiallyDeferred = ConstraintDefinitionNode.INITIALLY_DEFERRED_DEFAULT;
    boolean enforced = ConstraintDefinitionNode.ENFORCED_DEFAULT;
    int referenceCount;
    String constraintUUIDString;
    String schemaUUIDString;
    SubConstraintDescriptor scd;
    if (SanityManager.DEBUG) {
        if (!(parentTupleDescriptor instanceof SubConstraintDescriptor)) {
            SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " + "SubConstraintDescriptor, not " + parentTupleDescriptor.getClass().getName());
        }
    }
    scd = (SubConstraintDescriptor) parentTupleDescriptor;
    ddg = dd.getDataDescriptorGenerator();
    /* 1st column is CONSTRAINTID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTID);
    constraintUUIDString = col.getString();
    constraintUUID = getUUIDFactory().recreateUUID(constraintUUIDString);
    /* 2nd column is TABLEID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_TABLEID);
    tableUUIDString = col.getString();
    tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
    /* Get the TableDescriptor.  
		 * It may be cached in the SCD, 
		 * otherwise we need to go to the
		 * DD.
		 */
    if (scd != null) {
        td = scd.getTableDescriptor();
    }
    if (td == null) {
        td = dd.getTableDescriptor(tableUUID);
    }
    /* 3rd column is NAME (varchar(128)) */
    col = row.getColumn(SYSCONSTRAINTS_CONSTRAINTNAME);
    constraintName = col.getString();
    /* 4th column is TYPE (char(1)) */
    col = row.getColumn(SYSCONSTRAINTS_TYPE);
    constraintSType = col.getString();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(constraintSType.length() == 1, "Fourth column type incorrect");
    }
    boolean typeSet = false;
    switch(constraintSType.charAt(0)) {
        case 'P':
            constraintIType = DataDictionary.PRIMARYKEY_CONSTRAINT;
            typeSet = true;
        case 'U':
            if (!typeSet) {
                constraintIType = DataDictionary.UNIQUE_CONSTRAINT;
                typeSet = true;
            }
        case 'F':
            if (!typeSet)
                constraintIType = DataDictionary.FOREIGNKEY_CONSTRAINT;
            if (SanityManager.DEBUG) {
                if (!(parentTupleDescriptor instanceof SubKeyConstraintDescriptor)) {
                    SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " + "SubKeyConstraintDescriptor, not " + parentTupleDescriptor.getClass().getName());
                }
            }
            conglomDesc = td.getConglomerateDescriptor(((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId());
            /* Take care the rare case of conglomDesc being null.  The
				 * reason is that our "td" is out of date.  Another thread
				 * which was adding a constraint committed between the moment
				 * we got the table descriptor (conglomerate list) and the
				 * moment we scanned and got the constraint desc list.  Since
				 * that thread just added a new row to SYSCONGLOMERATES, 
				 * SYSCONSTRAINTS, etc.  We wouldn't have wanted to lock the
				 * system tables just to prevent other threads from adding new
				 * rows.
				 */
            if (conglomDesc == null) {
                // we can't be getting td from cache because if we are
                // here, we must have been in dd's ddl mode (that's why
                // the ddl thread went through), we are not done yet, the
                // dd ref count is not 0, hence it couldn't have turned
                // into COMPILE_ONLY mode
                td = dd.getTableDescriptor(tableUUID);
                if (scd != null)
                    scd.setTableDescriptor(td);
                // try again now
                conglomDesc = td.getConglomerateDescriptor(((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId());
            }
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(conglomDesc != null, "conglomDesc is expected to be non-null for backing index");
            }
            keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
            referencedConstraintId = ((SubKeyConstraintDescriptor) parentTupleDescriptor).getKeyConstraintId();
            keyColumns = conglomDesc.getIndexDescriptor().baseColumnPositions();
            break;
        case 'C':
            constraintIType = DataDictionary.CHECK_CONSTRAINT;
            if (SanityManager.DEBUG) {
                if (!(parentTupleDescriptor instanceof SubCheckConstraintDescriptor)) {
                    SanityManager.THROWASSERT("parentTupleDescriptor expected to be instanceof " + "SubCheckConstraintDescriptor, not " + parentTupleDescriptor.getClass().getName());
                }
            }
            break;
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Fourth column value invalid");
            }
    }
    /* 5th column is SCHEMAID (UUID - char(36)) */
    col = row.getColumn(SYSCONSTRAINTS_SCHEMAID);
    schemaUUIDString = col.getString();
    schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
    schema = dd.getSchemaDescriptor(schemaUUID, null);
    /* 6th column is STATE (char(1)) */
    col = row.getColumn(SYSCONSTRAINTS_STATE);
    constraintStateStr = col.getString();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(constraintStateStr.length() == 1, "Sixth column (state) type incorrect");
    }
    // 
    switch(constraintStateStr.charAt(0)) {
        case 'E':
            deferrable = false;
            initiallyDeferred = false;
            enforced = true;
            break;
        case 'D':
            deferrable = false;
            initiallyDeferred = false;
            enforced = false;
            break;
        case 'e':
            deferrable = true;
            initiallyDeferred = true;
            enforced = true;
            break;
        case 'd':
            deferrable = true;
            initiallyDeferred = true;
            enforced = false;
            break;
        case 'i':
            deferrable = true;
            initiallyDeferred = false;
            enforced = true;
            break;
        case 'j':
            deferrable = true;
            initiallyDeferred = false;
            enforced = false;
            break;
        default:
            if (SanityManager.DEBUG) {
                SanityManager.THROWASSERT("Invalidate state value '" + constraintStateStr + "' for constraint");
            }
    }
    /* 7th column is REFERENCECOUNT, boolean */
    col = row.getColumn(SYSCONSTRAINTS_REFERENCECOUNT);
    referenceCount = col.getInt();
    switch(constraintIType) {
        case DataDictionary.PRIMARYKEY_CONSTRAINT:
            constraintDesc = ddg.newPrimaryKeyConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, // genReferencedColumns(dd, td), //int referencedColumns[],
            keyColumns, constraintUUID, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId(), schema, enforced, referenceCount);
            break;
        case DataDictionary.UNIQUE_CONSTRAINT:
            constraintDesc = ddg.newUniqueConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, // genReferencedColumns(dd, td), //int referencedColumns[],
            keyColumns, constraintUUID, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId(), schema, enforced, referenceCount);
            break;
        case DataDictionary.FOREIGNKEY_CONSTRAINT:
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(referenceCount == 0, "REFERENCECOUNT column is nonzero for fk constraint");
            }
            constraintDesc = ddg.newForeignKeyConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, // genReferencedColumns(dd, td), //int referencedColumns[],
            keyColumns, constraintUUID, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getIndexId(), schema, referencedConstraintId, enforced, ((SubKeyConstraintDescriptor) parentTupleDescriptor).getRaDeleteRule(), ((SubKeyConstraintDescriptor) parentTupleDescriptor).getRaUpdateRule());
            break;
        case DataDictionary.CHECK_CONSTRAINT:
            if (SanityManager.DEBUG) {
                SanityManager.ASSERT(referenceCount == 0, "REFERENCECOUNT column is nonzero for check constraint");
            }
            constraintDesc = ddg.newCheckConstraintDescriptor(td, constraintName, deferrable, initiallyDeferred, constraintUUID, ((SubCheckConstraintDescriptor) parentTupleDescriptor).getConstraintText(), ((SubCheckConstraintDescriptor) parentTupleDescriptor).getReferencedColumnsDescriptor(), schema, enforced);
            break;
    }
    return constraintDesc;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) SubConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) SubKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor) SubConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor) SubKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID)

Example 64 with SchemaDescriptor

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

the class SYSSCHEMASRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * Make an  Tuple Descriptor out of a SYSSCHEMAS row
 *
 * @param row 					a SYSSCHEMAS row
 * @param parentTupleDescriptor	unused
 * @param dd 					dataDictionary
 *
 * @return	a  descriptor equivalent to a SYSSCHEMAS row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    DataValueDescriptor col;
    SchemaDescriptor descriptor;
    String name;
    UUID id;
    String aid;
    String uuid;
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(row.nColumns() == SYSSCHEMAS_COLUMN_COUNT, "Wrong number of columns for a SYSSCHEMAS row");
    }
    // first column is schemaid (UUID - char(36))
    col = row.getColumn(1);
    uuid = col.getString();
    id = getUUIDFactory().recreateUUID(uuid);
    // second column is schemaname (varchar(128))
    col = row.getColumn(2);
    name = col.getString();
    // third column is auid (varchar(128))
    col = row.getColumn(3);
    aid = col.getString();
    descriptor = ddg.newSchemaDescriptor(name, aid, id);
    return descriptor;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID)

Example 65 with SchemaDescriptor

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

the class CurrentOfNode method bindNonVTITables.

// 
// FromTable interface
// 
/**
 * Binding this FromTable means finding the prepared statement
 * for the cursor and creating the result columns (the columns
 * updatable on that cursor).
 *
 * We expect someone else to verify that the target table
 * of the positioned update or delete is the table under this cursor.
 *
 * @param dataDictionary	The DataDictionary to use for binding
 * @param fromListParam		FromList to use/append to.
 *
 * @return	ResultSetNode		Returns this.
 *
 * @exception StandardException		Thrown on error
 */
@Override
ResultSetNode bindNonVTITables(DataDictionary dataDictionary, FromList fromListParam) throws StandardException {
    // verify that the cursor exists
    preStmt = getCursorStatement();
    if (preStmt == null) {
        throw StandardException.newException(SQLState.LANG_CURSOR_NOT_FOUND, cursorName);
    }
    preStmt.rePrepare(getLanguageConnectionContext());
    // for checking that the right columns are updatable)
    if (preStmt.getUpdateMode() != CursorNode.UPDATE) {
        String printableString = (cursorName == null) ? "" : cursorName;
        throw StandardException.newException(SQLState.LANG_CURSOR_NOT_UPDATABLE, printableString);
    }
    ExecCursorTableReference refTab = preStmt.getTargetTable();
    String schemaName = refTab.getSchemaName();
    exposedTableName = makeTableName(null, refTab.getExposedName());
    baseTableName = makeTableName(schemaName, refTab.getBaseName());
    SchemaDescriptor tableSchema = getSchemaDescriptor(refTab.getSchemaName());
    /*
		** This will only happen when we are binding against a publication
		** dictionary w/o the schema we are interested in.
		*/
    if (tableSchema == null) {
        throw StandardException.newException(SQLState.LANG_SCHEMA_DOES_NOT_EXIST, refTab.getSchemaName());
    }
    /* Create dependency on target table, in case table not named in 
		 * positioned update/delete.  Make sure we find the table descriptor,
		 * we may fail to find it if we are binding a publication.
		 */
    TableDescriptor td = getTableDescriptor(refTab.getBaseName(), tableSchema);
    if (td == null) {
        throw StandardException.newException(SQLState.LANG_TABLE_NOT_FOUND, refTab.getBaseName());
    }
    /*
		** Add all the result columns from the target table.
		** For now, all updatable cursors have all columns
		** from the target table.  In the future, we should
		** relax this so that the cursor may do a partial
		** read and then the current of should make sure that
		** it can go to the base table to get all of the 
		** columns needed by the referencing positioned
		** DML.  In the future, we'll probably need to get
		** the result columns from preparedStatement and
		** turn them into an RCL that we can run with.
		*/
    setResultColumns(new ResultColumnList(getContextManager()));
    ColumnDescriptorList cdl = td.getColumnDescriptorList();
    int cdlSize = cdl.size();
    for (int index = 0; index < cdlSize; index++) {
        /* Build a ResultColumn/BaseColumnNode pair for the column */
        ColumnDescriptor colDesc = cdl.elementAt(index);
        BaseColumnNode bcn = new BaseColumnNode(colDesc.getColumnName(), exposedTableName, colDesc.getType(), getContextManager());
        ResultColumn rc = new ResultColumn(colDesc, bcn, getContextManager());
        /* Build the ResultColumnList to return */
        getResultColumns().addResultColumn(rc);
    }
    /* Assign the tableNumber */
    if (// allow re-bind, in which case use old number
    tableNumber == -1)
        tableNumber = getCompilerContext().getNextTableNumber();
    return this;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) ExecCursorTableReference(org.apache.derby.iapi.sql.execute.ExecCursorTableReference) ColumnDescriptorList(org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList) ColumnDescriptor(org.apache.derby.iapi.sql.dictionary.ColumnDescriptor) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor)

Aggregations

SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)85 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)33 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)27 UUID (org.apache.derby.catalog.UUID)21 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)20 TransactionController (org.apache.derby.iapi.store.access.TransactionController)20 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)14 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)12 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)12 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)11 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 DependencyManager (org.apache.derby.iapi.sql.depend.DependencyManager)8 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)8 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)8 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)8 Properties (java.util.Properties)5 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)5 StandardException (org.apache.derby.shared.common.error.StandardException)5 RoutineAliasInfo (org.apache.derby.catalog.types.RoutineAliasInfo)4