Search in sources :

Example 36 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method getFileInfoDescriptorIndex1Scan.

/**
 * Scan sysfiles_index1 (schemaid,name) for a match.
 * @return The matching descriptor or null.
 * @exception StandardException		Thrown on failure
 */
private FileInfoDescriptor getFileInfoDescriptorIndex1Scan(UUID schemaId, String name) throws StandardException {
    DataValueDescriptor schemaIDOrderable;
    DataValueDescriptor nameOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSFILES_CATALOG_NUM);
    nameOrderable = new SQLVarchar(name);
    schemaIDOrderable = getIDValueAsCHAR(schemaId);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(2);
    keyRow.setColumn(1, nameOrderable);
    keyRow.setColumn(2, schemaIDOrderable);
    FileInfoDescriptor r = getDescriptorViaIndex(SYSFILESRowFactory.SYSFILES_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, FileInfoDescriptor.class, false);
    return r;
}
Also used : FileInfoDescriptor(org.apache.derby.iapi.sql.dictionary.FileInfoDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 37 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method dropSequenceDescriptor.

/**
 * Drops a sequence descriptor
 *
 * @param descriptor The descriptor to drop
 * @param tc         The TransactionController.
 * @throws StandardException Thrown on failure
 */
public void dropSequenceDescriptor(SequenceDescriptor descriptor, TransactionController tc) throws StandardException {
    DataValueDescriptor sequenceIdOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSSEQUENCES_CATALOG_NUM);
    sequenceIdOrderable = getIDValueAsCHAR(descriptor.getUUID());
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, sequenceIdOrderable);
    ti.deleteRow(tc, keyRow, SYSSEQUENCESRowFactory.SYSSEQUENCES_INDEX1_ID);
    dropSequenceID(descriptor);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 38 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow 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 39 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method getConstraintDescriptorsScan.

/**
 * Populate the ConstraintDescriptorList for the specified TableDescriptor.
 *
 * MT synchronization: it is assumed that the caller has synchronized
 * on the CDL in the given TD.
 *
 * @param td				The TableDescriptor.
 * @param forUpdate			Whether or not to open scan for update
 *
 * @exception StandardException		Thrown on failure
 */
private void getConstraintDescriptorsScan(TableDescriptor td, boolean forUpdate) throws StandardException {
    ConstraintDescriptorList cdl = td.getConstraintDescriptorList();
    DataValueDescriptor tableIDOrderable = null;
    TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
    /* Use tableIDOrderable in both start and stop positions for scan */
    tableIDOrderable = getIDValueAsCHAR(td.getUUID());
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, tableIDOrderable);
    getConstraintDescriptorViaIndex(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID, keyRow, ti, td, cdl, forUpdate);
    cdl.setScanned(true);
}
Also used : ConstraintDescriptorList(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 40 with ExecIndexRow

use of org.apache.derby.iapi.sql.execute.ExecIndexRow in project derby by apache.

the class DataDictionaryImpl method getUncachedPermissionsDescriptor.

// end of getUncachedColPermsDescriptor
private <T extends PermissionsDescriptor> T getUncachedPermissionsDescriptor(int catalogNumber, int indexNumber, T key, Class<T> returnType) throws StandardException {
    TabInfoImpl ti = getNonCoreTI(catalogNumber);
    PermissionsCatalogRowFactory rowFactory = (PermissionsCatalogRowFactory) ti.getCatalogRowFactory();
    ExecIndexRow keyRow = rowFactory.buildIndexKeyRow(indexNumber, key);
    return getDescriptorViaIndex(indexNumber, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, returnType, false);
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Aggregations

ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)110 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)72 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)34 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)30 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)27 SQLChar (org.apache.derby.iapi.types.SQLChar)22 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)14 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RowLocation (org.apache.derby.iapi.types.RowLocation)12 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)10 ScanController (org.apache.derby.iapi.store.access.ScanController)9 UUID (org.apache.derby.catalog.UUID)8 ArrayList (java.util.ArrayList)7 ColumnDescriptorList (org.apache.derby.iapi.sql.dictionary.ColumnDescriptorList)6 ConglomerateDescriptorList (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptorList)6 ConstraintDescriptorList (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptorList)6 TransactionController (org.apache.derby.iapi.store.access.TransactionController)6 Properties (java.util.Properties)5 PermissionsDescriptor (org.apache.derby.iapi.sql.dictionary.PermissionsDescriptor)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)5