Search in sources :

Example 41 with ExecIndexRow

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

the class DataDictionaryImpl method updateConstraintDescriptor.

/**
 * Update the constraint descriptor in question.  Updates
 * every row in the base conglomerate.
 *
 * @param cd                    The Constraint descriptor
 * @param formerUUID			The UUID for this column in SYSCONSTRAINTS,
 *                              may differ from what is in {@code cd} if this
 *								is the column that is being set.
 * @param colsToSet             Array of integers of columns to be modified,
 *                              1 based.  May be null (all columns).
 * @param tc					The TransactionController to use
 *
 * @exception StandardException		Thrown on failure
 */
public void updateConstraintDescriptor(ConstraintDescriptor cd, UUID formerUUID, int[] colsToSet, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow1 = null;
    ExecRow row;
    DataValueDescriptor IDOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
    SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
    /* Use objectID/columnName in both start 
		 * and stop position for index 1 scan. 
		 */
    IDOrderable = getIDValueAsCHAR(formerUUID);
    /* Set up the start/stop position for the scan */
    keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow1.setColumn(1, IDOrderable);
    // build the row to be stuffed into SYSCONSTRAINTS.
    row = rf.makeRow(cd, null);
    /*
		** Figure out if the index in sysconstraints needs 
		** to be updated. 
		*/
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(rf.getNumIndexes() == 3, "There are more indexes on sysconstraints than expected, the code herein needs to change");
    }
    boolean[] bArray = new boolean[3];
    /*
		** Do we need to update indexes?
		*/
    if (colsToSet == null) {
        bArray[0] = true;
        bArray[1] = true;
        bArray[2] = true;
    } else {
        /*
			** Check the specific columns for indexed
			** columns.
			*/
        for (int i = 0; i < colsToSet.length; i++) {
            switch(colsToSet[i]) {
                case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_CONSTRAINTID:
                    bArray[0] = true;
                    break;
                case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_CONSTRAINTNAME:
                case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_SCHEMAID:
                    bArray[1] = true;
                    break;
                case SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_TABLEID:
                    bArray[2] = true;
                    break;
            }
        }
    }
    ti.updateRow(keyRow1, row, SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID, bArray, colsToSet, tc);
}
Also used : ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 42 with ExecIndexRow

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

the class DataDictionaryImpl method dropTriggerDescriptor.

/**
 * Drops the given TriggerDescriptor.  WARNING: does
 * not drop its SPSes!!!
 *
 * @param descriptor	The descriptor to drop
 * @param tc	The TransactionController.
 *
 * @exception StandardException		Thrown on failure
 */
public void dropTriggerDescriptor(TriggerDescriptor descriptor, TransactionController tc) throws StandardException {
    DataValueDescriptor idOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSTRIGGERS_CATALOG_NUM);
    idOrderable = getIDValueAsCHAR(descriptor.getUUID());
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
    keyRow.setColumn(1, idOrderable);
    ti.deleteRow(tc, keyRow, SYSTRIGGERSRowFactory.SYSTRIGGERS_INDEX1_ID);
}
Also used : DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 43 with ExecIndexRow

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

the class DataDictionaryImpl method getSPSDescriptorIndex2Scan.

/**
 * Scan sysstatements_index2 (stmtid) for a match.
 * Note that we do not do a lookup of parameter info.
 *
 * @return SPSDescriptor	The matching descriptor, if any.
 *
 * @exception StandardException		Thrown on failure
 */
private SPSDescriptor getSPSDescriptorIndex2Scan(String stmtUUID) throws StandardException {
    DataValueDescriptor stmtIDOrderable;
    TabInfoImpl ti = getNonCoreTI(SYSSTATEMENTS_CATALOG_NUM);
    /* Use stmtIdOrderable in both start 
		 * and stop position for scan. 
		 */
    stmtIDOrderable = new SQLChar(stmtUUID);
    /* Set up the start/stop position for the scan */
    ExecIndexRow keyRow = exFactory.getIndexableRow(1);
    keyRow.setColumn(1, stmtIDOrderable);
    SPSDescriptor spsd = getDescriptorViaIndex(SYSSTATEMENTSRowFactory.SYSSTATEMENTS_INDEX1_ID, keyRow, (ScanQualifier[][]) null, ti, (TupleDescriptor) null, (List<TupleDescriptor>) null, SPSDescriptor.class, false);
    return spsd;
}
Also used : TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor)

Example 44 with ExecIndexRow

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

the class DataDictionaryImpl method getConstraintDescriptorViaIndex.

/**
 * Return a (single or list of) ConstraintDescriptor(s) from
 * SYSCONSTRAINTS where the access is from the index to the heap.
 *
 * @param indexId	The id of the index (0 to # of indexes on table) to use
 * @param keyRow	The supplied ExecIndexRow for search
 * @param ti		The TabInfoImpl to use
 * @param td		The TableDescriptor, if supplied.
 * @param dList		The list to build, if supplied.  If null, then caller expects
 *					a single descriptor
 * @param forUpdate			Whether or not to open scan for update
 *
 * @return	The last matching descriptor
 *
 * @exception StandardException		Thrown on error
 */
protected ConstraintDescriptor getConstraintDescriptorViaIndex(int indexId, ExecIndexRow keyRow, TabInfoImpl ti, TableDescriptor td, ConstraintDescriptorList dList, boolean forUpdate) throws StandardException {
    SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
    ConglomerateController heapCC;
    ConstraintDescriptor cd = null;
    ExecIndexRow indexRow1;
    ExecRow outRow;
    RowLocation baseRowLocation;
    ScanController scanController;
    TransactionController tc;
    // Get the current transaction controller
    tc = getTransactionCompile();
    outRow = rf.makeEmptyRow();
    heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
    /* Scan the index and go to the data pages for qualifying rows to
		 * build the column descriptor.
		 */
    scanController = tc.openScan(// conglomerate to open
    ti.getIndexConglomerate(indexId), // don't hold open across commit
    false, (forUpdate) ? TransactionController.OPENMODE_FORUPDATE : 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position - exact key match.
    keyRow.getRowArray(), // startSearchOperation
    ScanController.GE, // scanQualifier,
    null, // stop position - exact key match.
    keyRow.getRowArray(), // stopSearchOperation
    ScanController.GT);
    while (scanController.next()) {
        SubConstraintDescriptor subCD = null;
        // create an index row template
        indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
        scanController.fetch(indexRow1.getRowArray());
        baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.nColumns());
        boolean base_row_exists = heapCC.fetch(baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null);
        if (SanityManager.DEBUG) {
            // it can not be possible for heap row to disappear while
            // holding scan cursor on index at ISOLATION_REPEATABLE_READ.
            SanityManager.ASSERT(base_row_exists, "base row doesn't exist");
        }
        switch(rf.getConstraintType(outRow)) {
            case DataDictionary.PRIMARYKEY_CONSTRAINT:
            case DataDictionary.FOREIGNKEY_CONSTRAINT:
            case DataDictionary.UNIQUE_CONSTRAINT:
                subCD = getSubKeyConstraint(rf.getConstraintId(outRow), rf.getConstraintType(outRow));
                break;
            case DataDictionary.CHECK_CONSTRAINT:
                subCD = getSubCheckConstraint(rf.getConstraintId(outRow));
                break;
            default:
                if (SanityManager.DEBUG) {
                    SanityManager.THROWASSERT("unexpected value " + "from rf.getConstraintType(outRow)" + rf.getConstraintType(outRow));
                }
        }
        if (SanityManager.DEBUG) {
            SanityManager.ASSERT(subCD != null, "subCD is expected to be non-null");
        }
        /* Cache the TD in the SCD so that
			 * the row factory doesn't need to go
			 * out to disk to get it.
			 */
        subCD.setTableDescriptor(td);
        cd = (ConstraintDescriptor) rf.buildDescriptor(outRow, subCD, this);
        /* If dList is null, then caller only wants a single descriptor - we're done
			 * else just add the current descriptor to the list.
			 */
        if (dList == null) {
            break;
        } else {
            dList.add(cd);
        }
    }
    scanController.close();
    heapCC.close();
    return cd;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SubConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor) ConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor) ReferencedKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor) KeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.KeyConstraintDescriptor) SubKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor) CheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.CheckConstraintDescriptor) ForeignKeyConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.ForeignKeyConstraintDescriptor) SubCheckConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor) SubConstraintDescriptor(org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) TransactionController(org.apache.derby.iapi.store.access.TransactionController) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 45 with ExecIndexRow

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

the class SYSTABLEPERMSRowFactory method buildIndexKeyRow.

/**
 * builds a key row given for a given index number.
 */
public ExecIndexRow buildIndexKeyRow(int indexNumber, PermissionsDescriptor perm) throws StandardException {
    ExecIndexRow row = null;
    switch(indexNumber) {
        case GRANTEE_TABLE_GRANTOR_INDEX_NUM:
            // RESOLVE We do not support the FOR GRANT OPTION, so table permission rows are unique on the
            // grantee and table UUID columns. The grantor column will always have the name of the owner of the
            // table. So the index key, used for searching the index, only has grantee and table UUID columns.
            // It does not have a grantor column.
            // 
            // If we support FOR GRANT OPTION then there may be multiple table permissions rows for a
            // (grantee, tableID) combination. We must either handle the multiple rows, which is necessary for
            // checking permissions, or add a grantor column to the key, which is necessary for granting or revoking
            // permissions.
            row = getExecutionFactory().getIndexableRow(2);
            row.setColumn(1, getAuthorizationID(perm.getGrantee()));
            String tableUUIDStr = ((TablePermsDescriptor) perm).getTableUUID().toString();
            row.setColumn(2, new SQLChar(tableUUIDStr));
            break;
        case TABLEPERMSID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            String tablePermsUUIDStr = perm.getObjectID().toString();
            row.setColumn(1, new SQLChar(tablePermsUUIDStr));
            break;
        case TABLEID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            tableUUIDStr = ((TablePermsDescriptor) perm).getTableUUID().toString();
            row.setColumn(1, new SQLChar(tableUUIDStr));
            break;
    }
    return row;
}
Also used : SQLChar(org.apache.derby.iapi.types.SQLChar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TablePermsDescriptor(org.apache.derby.iapi.sql.dictionary.TablePermsDescriptor)

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