Search in sources :

Example 66 with ExecIndexRow

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

the class SYSROUTINEPERMSRowFactory method buildIndexKeyRow.

/**
 * builds an index key row given for a given index number.
 */
public ExecIndexRow buildIndexKeyRow(int indexNumber, PermissionsDescriptor perm) throws StandardException {
    ExecIndexRow row = null;
    switch(indexNumber) {
        case GRANTEE_ALIAS_GRANTOR_INDEX_NUM:
            // RESOLVE We do not support the FOR GRANT OPTION, so rougine permission rows are unique on the
            // grantee and alias UUID columns. The grantor column will always have the name of the owner of the
            // routine. So the index key, used for searching the index, only has grantee and alias UUID columns.
            // It does not have a grantor column.
            // 
            // If we support FOR GRANT OPTION then there may be multiple routine permissions rows for a
            // (grantee, aliasID) combination. Since there is only one kind of routine permission (execute)
            // execute permission checking need not worry about multiple routine permission rows for a
            // (grantee, aliasID) combination, it only cares whether there are any. Grant and revoke must
            // look through multiple rows to see if the current user has grant/revoke permission and use
            // the full key in checking for the pre-existence of the permission being granted or revoked.
            row = getExecutionFactory().getIndexableRow(2);
            row.setColumn(1, getAuthorizationID(perm.getGrantee()));
            String routineUUIDStr = ((RoutinePermsDescriptor) perm).getRoutineUUID().toString();
            row.setColumn(2, new SQLChar(routineUUIDStr));
            break;
        case ROUTINEPERMSID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            String routinePermsUUIDStr = perm.getObjectID().toString();
            row.setColumn(1, new SQLChar(routinePermsUUIDStr));
            break;
        case ALIASID_INDEX_NUM:
            row = getExecutionFactory().getIndexableRow(1);
            routineUUIDStr = ((RoutinePermsDescriptor) perm).getRoutineUUID().toString();
            row.setColumn(1, new SQLChar(routineUUIDStr));
            break;
    }
    return row;
}
Also used : SQLChar(org.apache.derby.iapi.types.SQLChar) RoutinePermsDescriptor(org.apache.derby.iapi.sql.dictionary.RoutinePermsDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 67 with ExecIndexRow

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

the class SYSTABLESRowFactory method buildEmptyIndexRow.

/**
 * Builds an empty index row.
 *
 *	@param	indexNumber	Index to build empty row for.
 *  @param  rowLocation	Row location for last column of index row
 *
 * @return corresponding empty index row
 * @exception   StandardException thrown on failure
 */
ExecIndexRow buildEmptyIndexRow(int indexNumber, RowLocation rowLocation) throws StandardException {
    int ncols = getIndexColumnCount(indexNumber);
    ExecIndexRow row = getExecutionFactory().getIndexableRow(ncols + 1);
    row.setColumn(ncols + 1, rowLocation);
    switch(indexNumber) {
        case SYSTABLES_INDEX1_ID:
            /* 1st column is TABLENAME (varchar(128)) */
            row.setColumn(1, new SQLVarchar());
            /* 2nd column is SCHEMAID (UUID - char(36)) */
            row.setColumn(2, new SQLChar());
            break;
        case SYSTABLES_INDEX2_ID:
            /* 1st column is TABLEID (UUID - char(36)) */
            row.setColumn(1, new SQLChar());
            break;
    }
    return row;
}
Also used : SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 68 with ExecIndexRow

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

the class TabInfoImpl method deleteRows.

/**
 * @inheritDoc
 */
private int deleteRows(TransactionController tc, ExecIndexRow startKey, int startOp, Qualifier[][] qualifier, TupleFilter filter, ExecIndexRow stopKey, int stopOp, int indexNumber, boolean wait) throws StandardException {
    ConglomerateController heapCC;
    ScanController drivingScan;
    ExecIndexRow drivingIndexRow;
    RowLocation baseRowLocation;
    RowChanger rc;
    ExecRow baseRow = crf.makeEmptyRow();
    int rowsDeleted = 0;
    boolean passedFilter = true;
    rc = getRowChanger(tc, (int[]) null, baseRow);
    /*
		** If we have a start and a stop key, then we are going to 
		** get row locks, otherwise, we are getting table locks.
		** This may be excessive locking for the case where there
		** is a start key and no stop key or vice versa.
		*/
    int lockMode = ((startKey != null) && (stopKey != null)) ? TransactionController.MODE_RECORD : TransactionController.MODE_TABLE;
    /*
		** Don't use level 3 if we have the same start/stop key.
		*/
    int isolation = ((startKey != null) && (stopKey != null) && (startKey == stopKey)) ? TransactionController.ISOLATION_REPEATABLE_READ : TransactionController.ISOLATION_SERIALIZABLE;
    // Row level locking
    rc.open(lockMode, wait);
    DataValueDescriptor[] startKeyRow = startKey == null ? null : startKey.getRowArray();
    DataValueDescriptor[] stopKeyRow = stopKey == null ? null : stopKey.getRowArray();
    /* Open the heap conglomerate */
    heapCC = tc.openConglomerate(getHeapConglomerate(), false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), lockMode, TransactionController.ISOLATION_REPEATABLE_READ);
    drivingScan = tc.openScan(// conglomerate to open
    getIndexConglomerate(indexNumber), // don't hold open across commit
    false, (TransactionController.OPENMODE_FORUPDATE | ((wait) ? 0 : TransactionController.OPENMODE_LOCK_NOWAIT)), lockMode, isolation, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    startKeyRow, // startSearchOperation
    startOp, // scanQualifier
    qualifier, // stop position - through last row
    stopKeyRow, // stopSearchOperation
    stopOp);
    // Get an index row based on the base row
    drivingIndexRow = getIndexRowFromHeapRow(getIndexRowGenerator(indexNumber), heapCC.newRowLocationTemplate(), crf.makeEmptyRow());
    while (drivingScan.fetchNext(drivingIndexRow.getRowArray())) {
        baseRowLocation = (RowLocation) drivingIndexRow.getColumn(drivingIndexRow.nColumns());
        boolean base_row_exists = heapCC.fetch(baseRowLocation, baseRow.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 not found");
        }
        // only delete rows which pass the base-row filter
        if (filter != null) {
            passedFilter = filter.execute(baseRow).equals(true);
        }
        if (passedFilter) {
            rc.deleteRow(baseRow, baseRowLocation);
            rowsDeleted++;
        }
    }
    heapCC.close();
    drivingScan.close();
    rc.close();
    return rowsDeleted;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) RowChanger(org.apache.derby.iapi.sql.execute.RowChanger) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 69 with ExecIndexRow

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

the class TabInfoImpl method getIndexRowFromHeapRow.

/**
 * Get an index row based on a row from the heap.
 *
 * @param irg		IndexRowGenerator to use
 * @param rl		RowLocation for heap
 * @param heapRow	Row from the heap
 *
 * @return ExecIndexRow	Index row.
 *
 * @exception StandardException		Thrown on error
 */
private ExecIndexRow getIndexRowFromHeapRow(IndexRowGenerator irg, RowLocation rl, ExecRow heapRow) throws StandardException {
    ExecIndexRow indexRow;
    indexRow = irg.getIndexRowTemplate();
    // Get an index row based on the base row
    irg.getIndexRow(heapRow, rl, indexRow, (FormatableBitSet) null);
    return indexRow;
}
Also used : ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 70 with ExecIndexRow

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

the class DataDictionaryImpl method updateConglomerateDescriptor.

/**
 * Update the conglomerateNumber for an array of ConglomerateDescriptors.
 * In case of more than one ConglomerateDescriptor, each descriptor
 * should be updated separately, conglomerate id is not same for all
 * the descriptors. Even when indexes are sharing the same
 * conglomerate(conglomerate number), conglomerate ids are unique.
 *
 * This is useful, in 1.3, when doing a bulkInsert into an
 * empty table where we insert into a new conglomerate.
 * (This will go away in 1.4.)
 *
 * @param cds					The array of ConglomerateDescriptors
 * @param conglomerateNumber	The new conglomerate number
 * @param tc					The TransactionController to use
 *
 * @exception StandardException		Thrown on failure
 */
public void updateConglomerateDescriptor(ConglomerateDescriptor[] cds, long conglomerateNumber, TransactionController tc) throws StandardException {
    ExecIndexRow keyRow1 = null;
    ExecRow row;
    DataValueDescriptor conglomIDOrderable;
    TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM];
    SYSCONGLOMERATESRowFactory rf = (SYSCONGLOMERATESRowFactory) ti.getCatalogRowFactory();
    boolean[] bArray = { false, false, false };
    for (int i = 0; i < cds.length; i++) {
        /* Use conglomIDOrderable in both start 
			 * and stop position for index 1 scan. 
			 */
        conglomIDOrderable = getIDValueAsCHAR(cds[i].getUUID());
        /* Set up the start/stop position for the scan */
        keyRow1 = (ExecIndexRow) exFactory.getIndexableRow(1);
        keyRow1.setColumn(1, conglomIDOrderable);
        cds[i].setConglomerateNumber(conglomerateNumber);
        // build the row to be stuffed into SYSCONGLOMERATES.
        row = rf.makeRow(cds[i], null);
        // update row in catalog (no indexes)
        ti.updateRow(keyRow1, row, SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX1_ID, bArray, (int[]) null, 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)

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