Search in sources :

Example 1 with UserType

use of org.apache.derby.iapi.types.UserType in project derby by apache.

the class DataDictionaryImpl method clearSPSPlans.

/**
 * Mark all SPS plans in the data dictionary invalid. This does
 * not invalidate cached plans. This function is for use by
 * the boot-up code.
 * @exception StandardException		Thrown on error
 */
void clearSPSPlans() throws StandardException {
    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    faultInTabInfo(ti);
    TransactionController tc = getTransactionExecute();
    FormatableBitSet columnToReadSet = new FormatableBitSet(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT);
    FormatableBitSet columnToUpdateSet = new FormatableBitSet(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT);
    columnToUpdateSet.set(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID - 1);
    columnToUpdateSet.set(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE - 1);
    DataValueDescriptor[] replaceRow = new DataValueDescriptor[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_COLUMN_COUNT];
    /* Set up a couple of row templates for fetching CHARS */
    replaceRow[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_VALID - 1] = new SQLBoolean(false);
    replaceRow[SYSSTATEMENTSRowFactory.SYSSTATEMENTS_CONSTANTSTATE - 1] = new UserType((Object) null);
    /* Scan the entire heap */
    ScanController sc = tc.openScan(ti.getHeapConglomerate(), false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, columnToReadSet, (DataValueDescriptor[]) null, ScanController.NA, (Qualifier[][]) null, (DataValueDescriptor[]) null, ScanController.NA);
    while (sc.fetchNext((DataValueDescriptor[]) null)) {
        /* Replace the column in the table */
        sc.replace(replaceRow, columnToUpdateSet);
    }
    sc.close();
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Example 2 with UserType

use of org.apache.derby.iapi.types.UserType in project derby by apache.

the class DataDictionaryImpl method rewriteSYSCOLPERMSforAlterTable.

/**
 * Workhorse for ALTER TABLE-driven mods to SYSCOLPERMS
 *
 * This method finds all the SYSCOLPERMS rows for this table. Then it
 * iterates through each row, either adding a new column to the end of
 * the table, or dropping a column from the table, as appropriate. It
 * updates each SYSCOLPERMS row to store the new COLUMNS value.
 *
 * @param tableID	The UUID of the table being altered
 * @param tc		TransactionController for the transaction
 * @param columnDescriptor   Dropped column info, or null if adding
 *
 * @exception StandardException		Thrown on error
 */
private void rewriteSYSCOLPERMSforAlterTable(UUID tableID, TransactionController tc, ColumnDescriptor columnDescriptor) throws StandardException {
    // In Derby authorization mode, permission catalogs may not be present
    if (!usesSqlAuthorization)
        return;
    /* This method has 2 steps to it. First get all the ColPermsDescriptor   
		for given tableid. And next step is to go back to SYSCOLPERMS to find
		unique row corresponding to each of ColPermsDescriptor and update the
		"COLUMNS" column in SYSCOLPERMS. The reason for this 2 step process is
		that SYSCOLPERMS has a non-unique row on "TABLEID" column and hence   
		we can't get a unique handle on each of the affected row in SYSCOLPERMS
		using just the "TABLEID" column */
    // First get all the ColPermsDescriptor for the given tableid from
    // SYSCOLPERMS using getDescriptorViaIndex().
    // all ColPermsDescriptor for given tableid
    List<ColPermsDescriptor> permissionDescriptorsList;
    DataValueDescriptor tableIDOrderable = getIDValueAsCHAR(tableID);
    TabInfoImpl ti = getNonCoreTI(SYSCOLPERMS_CATALOG_NUM);
    SYSCOLPERMSRowFactory rf = (SYSCOLPERMSRowFactory) ti.getCatalogRowFactory();
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, tableIDOrderable);
    permissionDescriptorsList = newSList();
    getDescriptorViaIndex(SYSCOLPERMSRowFactory.TABLEID_INDEX_NUM, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, permissionDescriptorsList, ColPermsDescriptor.class, false);
    /* Next, using each of the ColPermDescriptor's uuid, get the unique row 
		in SYSCOLPERMS and adjust the "COLUMNS" column in SYSCOLPERMS to 
		accomodate the added or dropped column in the tableid*/
    ExecRow curRow;
    ExecIndexRow uuidKey;
    // Not updating any indexes on SYSCOLPERMS
    boolean[] bArray = new boolean[SYSCOLPERMSRowFactory.TOTAL_NUM_OF_INDEXES];
    int[] colsToUpdate = { SYSCOLPERMSRowFactory.COLUMNS_COL_NUM };
    for (ColPermsDescriptor colPermsDescriptor : permissionDescriptorsList) {
        removePermEntryInCache(colPermsDescriptor);
        uuidKey = rf.buildIndexKeyRow(rf.COLPERMSID_INDEX_NUM, colPermsDescriptor);
        curRow = ti.getRow(tc, uuidKey, rf.COLPERMSID_INDEX_NUM);
        FormatableBitSet columns = (FormatableBitSet) curRow.getColumn(SYSCOLPERMSRowFactory.COLUMNS_COL_NUM).getObject();
        // for the dropped column.
        if (columnDescriptor == null) {
            int currentLength = columns.getLength();
            columns.grow(currentLength + 1);
        } else {
            FormatableBitSet modifiedColumns = new FormatableBitSet(columns);
            modifiedColumns.shrink(columns.getLength() - 1);
            // FormatableBitSet count from 0.
            for (int i = columnDescriptor.getPosition() - 1; i < modifiedColumns.getLength(); i++) {
                if (columns.isSet(i + 1))
                    modifiedColumns.set(i);
                else
                    modifiedColumns.clear(i);
            }
            columns = modifiedColumns;
        }
        curRow.setColumn(SYSCOLPERMSRowFactory.COLUMNS_COL_NUM, new UserType((Object) columns));
        ti.updateRow(uuidKey, curRow, SYSCOLPERMSRowFactory.COLPERMSID_INDEX_NUM, bArray, colsToUpdate, tc);
    }
}
Also used : ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ColPermsDescriptor(org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UserType(org.apache.derby.iapi.types.UserType)

Example 3 with UserType

use of org.apache.derby.iapi.types.UserType in project derby by apache.

the class SYSTRIGGERSRowFactory method makeRow.

/**
 * Helper method that contains common logic for {@code makeRow()} and
 * {@code makeEmptyRowForCurrentVersion()}. Creates a row for the
 * SYSTRIGGERS conglomerate.
 *
 * @param td the {@code TriggerDescriptor} to create a row from (can be
 *   {@code null} if the returned row should be empty)
 * @param columnCount the number of columns in the returned row (used for
 *   trimming off columns in soft upgrade mode to match the format in
 *   the old dictionary version)
 * @return a row for the SYSTRIGGERS conglomerate
 * @throws StandardException if an error happens when creating the row
 */
private ExecRow makeRow(TupleDescriptor td, int columnCount) throws StandardException {
    String name = null;
    UUID uuid = null;
    // schema
    UUID suuid = null;
    // referenced table
    UUID tuuid = null;
    // action sps uuid string
    UUID actionSPSID = null;
    // when clause sps uuid string
    UUID whenSPSID = null;
    Timestamp createTime = null;
    String event = null;
    String time = null;
    String type = null;
    String enabled = null;
    String triggerDefinition = null;
    String oldReferencingName = null;
    String newReferencingName = null;
    ReferencedColumns rcd = null;
    boolean referencingOld = false;
    boolean referencingNew = false;
    String whenClauseText = null;
    if (td != null) {
        TriggerDescriptor triggerDescriptor = (TriggerDescriptor) td;
        name = triggerDescriptor.getName();
        uuid = triggerDescriptor.getUUID();
        suuid = triggerDescriptor.getSchemaDescriptor().getUUID();
        createTime = triggerDescriptor.getCreationTimestamp();
        // for now we are assuming that a trigger can only listen to a single event
        event = triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_UPDATE) ? "U" : triggerDescriptor.listensForEvent(TriggerDescriptor.TRIGGER_EVENT_DELETE) ? "D" : "I";
        time = triggerDescriptor.isBeforeTrigger() ? "B" : "A";
        type = triggerDescriptor.isRowTrigger() ? "R" : "S";
        enabled = triggerDescriptor.isEnabled() ? "E" : "D";
        tuuid = triggerDescriptor.getTableDescriptor().getUUID();
        int[] refCols = triggerDescriptor.getReferencedCols();
        int[] refColsInTriggerAction = triggerDescriptor.getReferencedColsInTriggerAction();
        rcd = (refCols != null || refColsInTriggerAction != null) ? new ReferencedColumnsDescriptorImpl(refCols, refColsInTriggerAction) : null;
        actionSPSID = triggerDescriptor.getActionId();
        whenSPSID = triggerDescriptor.getWhenClauseId();
        triggerDefinition = triggerDescriptor.getTriggerDefinition();
        referencingOld = triggerDescriptor.getReferencingOld();
        referencingNew = triggerDescriptor.getReferencingNew();
        oldReferencingName = triggerDescriptor.getOldReferencingName();
        newReferencingName = triggerDescriptor.getNewReferencingName();
        whenClauseText = triggerDescriptor.getWhenClauseText();
    }
    /* Build the row to insert */
    ExecRow row = getExecutionFactory().getValueRow(columnCount);
    /* 1st column is TRIGGERID */
    row.setColumn(1, new SQLChar((uuid == null) ? null : uuid.toString()));
    /* 2nd column is TRIGGERNAME */
    row.setColumn(2, new SQLVarchar(name));
    /* 3rd column is SCHEMAID */
    row.setColumn(3, new SQLChar((suuid == null) ? null : suuid.toString()));
    /* 4th column is CREATIONTIMESTAMP */
    SQLTimestamp creationTimestamp = (createTime == null) ? new SQLTimestamp(null) : new SQLTimestamp(createTime, getCalendarForCreationTimestamp());
    row.setColumn(4, creationTimestamp);
    /* 5th column is EVENT */
    row.setColumn(5, new SQLChar(event));
    /* 6th column is FIRINGTIME */
    row.setColumn(6, new SQLChar(time));
    /* 7th column is TYPE */
    row.setColumn(7, new SQLChar(type));
    /* 8th column is STATE */
    row.setColumn(8, new SQLChar(enabled));
    /* 9th column is TABLEID */
    row.setColumn(9, new SQLChar((tuuid == null) ? null : tuuid.toString()));
    /* 10th column is WHENSTMTID */
    row.setColumn(10, new SQLChar((whenSPSID == null) ? null : whenSPSID.toString()));
    /* 11th column is ACTIONSTMTID */
    row.setColumn(11, new SQLChar((actionSPSID == null) ? null : actionSPSID.toString()));
    /* 12th column is REFERENCEDCOLUMNS 
		 *  (user type org.apache.derby.catalog.ReferencedColumns)
		 */
    row.setColumn(12, new UserType(rcd));
    /* 13th column is TRIGGERDEFINITION */
    row.setColumn(13, dvf.getLongvarcharDataValue(triggerDefinition));
    /* 14th column is REFERENCINGOLD */
    row.setColumn(14, new SQLBoolean(referencingOld));
    /* 15th column is REFERENCINGNEW */
    row.setColumn(15, new SQLBoolean(referencingNew));
    /* 16th column is OLDREFERENCINGNAME */
    row.setColumn(16, new SQLVarchar(oldReferencingName));
    /* 17th column is NEWREFERENCINGNAME */
    row.setColumn(17, new SQLVarchar(newReferencingName));
    /* 18th column is WHENCLAUSETEXT */
    if (row.nColumns() >= 18) {
        // This column is present only if the data dictionary version is
        // 10.11 or higher.
        row.setColumn(18, dvf.getLongvarcharDataValue(whenClauseText));
    }
    return row;
}
Also used : ReferencedColumns(org.apache.derby.catalog.ReferencedColumns) SQLChar(org.apache.derby.iapi.types.SQLChar) ReferencedColumnsDescriptorImpl(org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) Timestamp(java.sql.Timestamp) TriggerDescriptor(org.apache.derby.iapi.sql.dictionary.TriggerDescriptor) SQLTimestamp(org.apache.derby.iapi.types.SQLTimestamp) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) UUID(org.apache.derby.catalog.UUID) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Example 4 with UserType

use of org.apache.derby.iapi.types.UserType in project derby by apache.

the class SYSCHECKSRowFactory method makeRow.

// ///////////////////////////////////////////////////////////////////////////
// 
// METHODS
// 
// ///////////////////////////////////////////////////////////////////////////
/**
 * Make a SYSCHECKS row
 *
 * @param td CheckConstraintDescriptorImpl
 *
 * @return	Row suitable for inserting into SYSCHECKS.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    DataValueDescriptor col;
    ExecIndexRow row;
    ReferencedColumns rcd = null;
    String checkDefinition = null;
    String constraintID = null;
    if (td != null) {
        CheckConstraintDescriptor cd = (CheckConstraintDescriptor) td;
        /*
			** We only allocate a new UUID if the descriptor doesn't already have one.
			** For descriptors replicated from a Source system, we already have an UUID.
			*/
        constraintID = cd.getUUID().toString();
        checkDefinition = cd.getConstraintText();
        rcd = cd.getReferencedColumnsDescriptor();
    }
    /* Build the row */
    row = getExecutionFactory().getIndexableRow(SYSCHECKS_COLUMN_COUNT);
    /* 1st column is CONSTRAINTID (UUID - char(36)) */
    row.setColumn(SYSCHECKS_CONSTRAINTID, new SQLChar(constraintID));
    /* 2nd column is CHECKDEFINITION */
    row.setColumn(SYSCHECKS_CHECKDEFINITION, dvf.getLongvarcharDataValue(checkDefinition));
    /* 3rd column is REFERENCEDCOLUMNS
		 *  (user type org.apache.derby.catalog.ReferencedColumns)
		 */
    row.setColumn(SYSCHECKS_REFERENCEDCOLUMNS, new UserType(rcd));
    return row;
}
Also used : ReferencedColumns(org.apache.derby.catalog.ReferencedColumns) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) CheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) UserType(org.apache.derby.iapi.types.UserType)

Example 5 with UserType

use of org.apache.derby.iapi.types.UserType in project derby by apache.

the class SYSSEQUENCESRowFactory method makeRow.

/**
 * Make a SYSSEQUENCES row
 *
 * @param td     a sequence descriptor
 * @param parent unused
 * @return Row suitable for inserting into SYSSEQUENCES.
 * @throws org.apache.derby.shared.common.error.StandardException
 *          thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    ExecRow row;
    String oidString = null;
    String sequenceName = null;
    String schemaIdString = null;
    TypeDescriptor typeDesc = null;
    Long currentValue = null;
    long startValue = 0;
    long minimumValue = 0;
    long maximumValue = 0;
    long increment = 0;
    boolean canCycle = false;
    if (td != null) {
        SequenceDescriptor sd = (SequenceDescriptor) td;
        UUID oid = sd.getUUID();
        oidString = oid.toString();
        sequenceName = sd.getSequenceName();
        UUID schemaId = sd.getSchemaId();
        schemaIdString = schemaId.toString();
        typeDesc = sd.getDataType().getCatalogType();
        currentValue = sd.getCurrentValue();
        startValue = sd.getStartValue();
        minimumValue = sd.getMinimumValue();
        maximumValue = sd.getMaximumValue();
        increment = sd.getIncrement();
        canCycle = sd.canCycle();
    }
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSSEQUENCES_COLUMN_COUNT);
    /* 1st column is UUID */
    row.setColumn(SYSSEQUENCES_SEQUENCEID, new SQLChar(oidString));
    /* 2nd column is SEQUENCENAME */
    row.setColumn(SYSSEQUENCES_SEQUENCENAME, new SQLVarchar(sequenceName));
    /* 3nd column is SCHEMAID */
    row.setColumn(SYSSEQUENCES_SCHEMAID, new SQLChar(schemaIdString));
    /* 4th column is SEQUENCEDATATYPE */
    row.setColumn(SYSSEQUENCES_SEQUENCEDATATYPE, new UserType(typeDesc));
    /* 5th column is CURRENTVALUE */
    SQLLongint curVal;
    if (currentValue == null) {
        curVal = new SQLLongint();
    } else {
        curVal = new SQLLongint(currentValue.longValue());
    }
    row.setColumn(SYSSEQUENCES_CURRENT_VALUE, curVal);
    /* 6th column is STARTVALUE */
    row.setColumn(SYSSEQUENCES_START_VALUE, new SQLLongint(startValue));
    /* 7th column is MINIMUMVALUE */
    row.setColumn(SYSSEQUENCES_MINIMUM_VALUE, new SQLLongint(minimumValue));
    /* 8th column is MAXIMUMVALUE */
    row.setColumn(SYSSEQUENCES_MAXIMUM_VALUE, new SQLLongint(maximumValue));
    /* 9th column is INCREMENT */
    row.setColumn(SYSSEQUENCES_INCREMENT, new SQLLongint(increment));
    /* 10th column is CYCLEOPTION */
    row.setColumn(SYSSEQUENCES_CYCLE_OPTION, new SQLChar(canCycle ? "Y" : "N"));
    return row;
}
Also used : TypeDescriptor(org.apache.derby.catalog.TypeDescriptor) DataTypeDescriptor(org.apache.derby.iapi.types.DataTypeDescriptor) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) SQLChar(org.apache.derby.iapi.types.SQLChar) SequenceDescriptor(org.apache.derby.iapi.sql.dictionary.SequenceDescriptor) UUID(org.apache.derby.catalog.UUID) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) UserType(org.apache.derby.iapi.types.UserType)

Aggregations

UserType (org.apache.derby.iapi.types.UserType)16 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)13 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)9 SQLChar (org.apache.derby.iapi.types.SQLChar)7 SQLBoolean (org.apache.derby.iapi.types.SQLBoolean)5 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)5 UUID (org.apache.derby.catalog.UUID)4 ScanController (org.apache.derby.iapi.store.access.ScanController)4 Timestamp (java.sql.Timestamp)3 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)3 SQLLongint (org.apache.derby.iapi.types.SQLLongint)3 ReferencedColumns (org.apache.derby.catalog.ReferencedColumns)2 ColPermsDescriptor (org.apache.derby.iapi.sql.dictionary.ColPermsDescriptor)2 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)2 DataTypeDescriptor (org.apache.derby.iapi.types.DataTypeDescriptor)2 Serializable (java.io.Serializable)1 Hashtable (java.util.Hashtable)1 AliasInfo (org.apache.derby.catalog.AliasInfo)1 DependableFinder (org.apache.derby.catalog.DependableFinder)1 IndexDescriptor (org.apache.derby.catalog.IndexDescriptor)1