Search in sources :

Example 56 with ScanController

use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.

the class DataDictionaryImpl method hashAllConglomerateDescriptorsByNumber.

/**
 * Get all of the ConglomerateDescriptors in the database and
 * hash them by conglomerate number.
 * This is useful as a performance optimization for the locking VTIs.
 * NOTE:  This method will scan SYS.SYSCONGLOMERATES at READ UNCOMMITTED.
 *
 * @param tc		TransactionController for the transaction
 *
 * @return	A Hashtable with all of the ConglomerateDescriptors
 *		in the database hashed by conglomerate number.
 *
 * @exception StandardException		Thrown on failure
 */
public Hashtable<Long, ConglomerateDescriptor> hashAllConglomerateDescriptorsByNumber(TransactionController tc) throws StandardException {
    Hashtable<Long, ConglomerateDescriptor> ht = new Hashtable<Long, ConglomerateDescriptor>();
    ConglomerateDescriptor cd = null;
    ScanController scanController;
    ExecRow outRow;
    TabInfoImpl ti = coreInfo[SYSCONGLOMERATES_CORE_NUM];
    SYSCONGLOMERATESRowFactory rf = (SYSCONGLOMERATESRowFactory) ti.getCatalogRowFactory();
    outRow = rf.makeEmptyRow();
    scanController = tc.openScan(// conglomerate to open
    ti.getHeapConglomerate(), // don't hold open across commit
    false, // for read
    0, // scans whole table.
    TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, // all fields as objects
    (FormatableBitSet) null, // keyRow.getRowArray(),   // start position - first row
    (DataValueDescriptor[]) null, // startSearchOperation
    ScanController.GE, (ScanQualifier[][]) null, // keyRow.getRowArray(),   // stop position - through last row
    (DataValueDescriptor[]) null, // stopSearchOperation
    ScanController.GT);
    // fetch() may find the row deleted or purged from the table.
    while (scanController.fetchNext(outRow.getRowArray())) {
        cd = (ConglomerateDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
        Long hashKey = cd.getConglomerateNumber();
        ht.put(hashKey, cd);
    }
    scanController.close();
    return ht;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) Hashtable(java.util.Hashtable) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) ScanQualifier(org.apache.derby.iapi.sql.execute.ScanQualifier) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 57 with ScanController

use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.

the class DataDictionaryImpl method upgrade_initSystemTableCols.

/**
 * Initialize noncore columns to fixed values
 *
 * @param tc					The TransactionController for the transaction to do the
 *								upgrade in.
 * @param isCoreTable			true if it is a core table
 * @param tableNum				the noncore table number
 * @param columnsToUpdateSet	a bit set of columns to update.  ZERO BASED
 * @param replaceRow			an object array of Orderables for the new values
 *
 * @exception StandardException		Thrown on error
 */
void upgrade_initSystemTableCols(TransactionController tc, boolean isCoreTable, int tableNum, FormatableBitSet columnsToUpdateSet, DataValueDescriptor[] replaceRow) throws StandardException {
    TabInfoImpl ti = (isCoreTable) ? coreInfo[tableNum] : getNonCoreTIByNumber(tableNum);
    if (!isCoreTable)
        faultInTabInfo(ti);
    /* Scan the entire heap */
    ScanController sc = tc.openScan(ti.getHeapConglomerate(), false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, RowUtil.EMPTY_ROW_BITSET, (DataValueDescriptor[]) null, ScanController.NA, (Qualifier[][]) null, (DataValueDescriptor[]) null, ScanController.NA);
    while (sc.next()) {
        /* Replace the column in the table */
        sc.replace(replaceRow, columnsToUpdateSet);
    }
    sc.close();
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Example 58 with ScanController

use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.

the class DataDictionaryImpl method getConstraints.

/**
 * Return an List which of the relevant column matching
 * the indexed criteria.  If nothing matches, returns an
 * empty List (never returns null).
 *
 * @param uuid	The id of the constraint
 * @param indexId		The index id in SYS.SYSCONSTRAINTS
 * @param columnNum		The column to retrieve
 *
 * @return a list of UUIDs in an List.
 *
 * @exception StandardException		Thrown on error
 */
public List<UUID> getConstraints(UUID uuid, int indexId, int columnNum) throws StandardException {
    ExecIndexRow indexRow1;
    ExecRow outRow;
    RowLocation baseRowLocation;
    ConglomerateController heapCC = null;
    ScanController scanController = null;
    TransactionController tc;
    TabInfoImpl ti = getNonCoreTI(SYSCONSTRAINTS_CATALOG_NUM);
    SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
    TableDescriptor td = null;
    List<UUID> slist = new ArrayList<UUID>();
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(indexId == SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX1_ID || indexId == SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_INDEX3_ID, "bad index id, must be one of the indexes on a uuid");
        SanityManager.ASSERT(columnNum > 0 && columnNum <= SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT, "invalid column number for column to be retrieved");
    }
    try {
        /* Use tableIDOrderable in both start and stop positions for scan */
        DataValueDescriptor orderable = getIDValueAsCHAR(uuid);
        /* Set up the start/stop position for the scan */
        ExecIndexRow keyRow = (ExecIndexRow) exFactory.getIndexableRow(1);
        keyRow.setColumn(1, orderable);
        // Get the current transaction controller
        tc = getTransactionCompile();
        outRow = rf.makeEmptyRow();
        heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
        // create an index row template
        indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
        // just interested in one column
        DataValueDescriptor[] rowTemplate = new DataValueDescriptor[SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT];
        FormatableBitSet columnToGetSet = new FormatableBitSet(SYSCONSTRAINTSRowFactory.SYSCONSTRAINTS_COLUMN_COUNT);
        columnToGetSet.set(columnNum - 1);
        rowTemplate[columnNum - 1] = new SQLChar();
        // Scan the index and go to the data pages for qualifying rows
        scanController = tc.openScan(// conglomerate to open
        ti.getIndexConglomerate(indexId), // don't hold open across commit
        false, // for read
        0, TransactionController.MODE_RECORD, // RESOLVE: should be level 2
        TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
        (FormatableBitSet) null, // start position - exact key match.
        keyRow.getRowArray(), // startSearchOperation
        ScanController.GE, // scanQualifier (none)
        null, // stop position - exact key match.
        keyRow.getRowArray(), // stopSearchOperation
        ScanController.GT);
        while (scanController.fetchNext(indexRow1.getRowArray())) {
            baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.nColumns());
            // get the row and grab the uuid
            boolean base_row_exists = heapCC.fetch(baseRowLocation, rowTemplate, columnToGetSet);
            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");
            }
            slist.add(uuidFactory.recreateUUID((String) ((DataValueDescriptor) rowTemplate[columnNum - 1]).getObject()));
        }
    } finally {
        if (heapCC != null) {
            heapCC.close();
        }
        if (scanController != null) {
            scanController.close();
        }
    }
    return slist;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ArrayList(java.util.ArrayList) SQLChar(org.apache.derby.iapi.types.SQLChar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) TableDescriptor(org.apache.derby.iapi.sql.dictionary.TableDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) TransactionController(org.apache.derby.iapi.store.access.TransactionController) UUID(org.apache.derby.catalog.UUID) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 59 with ScanController

use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.

the class DataDictionaryImpl method visitRoleGrants.

/**
 * Scan the {roleid, grantee, grantor} index on SYSROLES,
 * locate rows containing authId in column columnNo.
 *
 * The action argument can be either <code>EXISTS</code> or
 * <code>DROP</code> (to check for existence, or to drop that row).
 *
 * If the scan proves too slow, we should add more indexes.  only.
 *
 * @param ti <code>TabInfoImpl</code> for SYSROLES.
 * @param rf row factory for SYSROLES
 * @param columnNo the column number to match <code>authId</code> against
 * @param tc transaction controller
 * @param action drop matching rows (<code>DROP</code>), or return
 *        <code>true</code> if there is a matching row
 *        (<code>EXISTS</code>)
 *
 * @return action=EXISTS: return {@code true} if there is a matching row
 *      else return {@code false}.
 * @exception StandardException
 */
private boolean visitRoleGrants(TabInfoImpl ti, SYSROLESRowFactory rf, int columnNo, String authId, TransactionController tc, int action) throws StandardException {
    ConglomerateController heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ);
    DataValueDescriptor authIdOrderable = new SQLVarchar(authId);
    ScanQualifier[][] scanQualifier = exFactory.getScanQualifier(1);
    scanQualifier[0][0].setQualifier(columnNo - 1, /* to zero-based */
    authIdOrderable, Orderable.ORDER_OP_EQUALS, false, false, false);
    ScanController sc = tc.openScan(ti.getIndexConglomerate(rf.SYSROLES_INDEX_ID_EE_OR_IDX), // don't hold open across commit
    false, // for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position -
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // 
    scanQualifier, // stop position -through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    try {
        ExecRow outRow = rf.makeEmptyRow();
        ExecIndexRow indexRow = getIndexRowFromHeapRow(ti.getIndexRowGenerator(rf.SYSROLES_INDEX_ID_EE_OR_IDX), heapCC.newRowLocationTemplate(), outRow);
        while (sc.fetchNext(indexRow.getRowArray())) {
            if (action == DataDictionaryImpl.EXISTS) {
                return true;
            } else if (action == DataDictionaryImpl.DROP) {
                ti.deleteRow(tc, indexRow, rf.SYSROLES_INDEX_ID_EE_OR_IDX);
            }
        }
    } finally {
        if (sc != null) {
            sc.close();
        }
        if (heapCC != null) {
            heapCC.close();
        }
    }
    return false;
}
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) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow)

Example 60 with ScanController

use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.

the class CacheLock method openScan.

/**
 * Open a scan on the properties conglomerate looking for "key".
 * <p>
 * Open a scan on the properties conglomerate qualified to
 * find the row with value key in column 0.  Both column 0
 * and column 1 are included in the scan list.
 *
 * @return an open ScanController on the PropertyConglomerate.
 *
 * @param tc        The transaction to do the Conglomerate work under.
 * @param key       The "key" of the property that is being requested.
 * @param open_mode Whether we are setting or getting the property.
 *
 * @exception  StandardException  Standard exception policy.
 */
private ScanController openScan(TransactionController tc, String key, int open_mode) throws StandardException {
    Qualifier[][] qualifiers = null;
    if (key != null) {
        // Set up qualifier to look for the row with key value in column[0]
        qualifiers = new Qualifier[1][];
        qualifiers[0] = new Qualifier[1];
        qualifiers[0][0] = new UTFQualifier(0, key);
    }
    // open the scan, clients will do the fetches and close.
    ScanController scan = tc.openScan(propertiesConglomId, // don't hold over the commit
    false, open_mode, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, // start key
    (DataValueDescriptor[]) null, ScanController.NA, qualifiers, // stop key
    (DataValueDescriptor[]) null, ScanController.NA);
    return (scan);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor)

Aggregations

ScanController (org.apache.derby.iapi.store.access.ScanController)61 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)35 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)32 RowLocation (org.apache.derby.iapi.types.RowLocation)29 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)24 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)22 SQLLongint (org.apache.derby.iapi.types.SQLLongint)20 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)9 StandardException (org.apache.derby.shared.common.error.StandardException)9 TransactionController (org.apache.derby.iapi.store.access.TransactionController)8 Properties (java.util.Properties)7 GroupFetchScanController (org.apache.derby.iapi.store.access.GroupFetchScanController)7 SQLChar (org.apache.derby.iapi.types.SQLChar)6 UUID (org.apache.derby.catalog.UUID)5 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)5 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)5 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 HashSet (java.util.HashSet)3 Hashtable (java.util.Hashtable)3 ReferencedKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ReferencedKeyConstraintDescriptor)3