Search in sources :

Example 6 with ScanController

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

the class DataDictionaryImpl method getDescriptorViaHeap.

/**
 * Return a (single or list of) catalog row descriptor(s) from a
 * system table where the access a heap scan
 *
 * @param columns                   which columns to fetch from the system
 *                                  table, or null to fetch all columns
 * @param scanQualifiers			qualifiers
 * @param ti						The TabInfoImpl to use
 * @param parentTupleDescriptor		The parentDescriptor, if applicable.
 * @param list						The list to build, if supplied.
 *									If null, then caller expects a single descriptor
 * @param returnType                The type of descriptor to look for
 *
 * @return	The last matching descriptor
 *
 * @exception StandardException		Thrown on error
 */
protected <T extends TupleDescriptor> T getDescriptorViaHeap(FormatableBitSet columns, ScanQualifier[][] scanQualifiers, TabInfoImpl ti, TupleDescriptor parentTupleDescriptor, List<? super T> list, Class<T> returnType) throws StandardException {
    CatalogRowFactory rf = ti.getCatalogRowFactory();
    ExecRow outRow;
    ScanController scanController;
    TransactionController tc;
    T td = null;
    // Get the current transaction controller
    tc = getTransactionCompile();
    outRow = rf.makeEmptyRow();
    /*
		** Table scan
		*/
    scanController = tc.openScan(// conglomerate to open
    ti.getHeapConglomerate(), // don't hold open across commit
    false, // for read
    0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, columns, // start position - first row
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // scanQualifier,
    scanQualifiers, // stop position - through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    while (scanController.fetchNext(outRow.getRowArray())) {
        td = returnType.cast(rf.buildDescriptor(outRow, parentTupleDescriptor, 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 (list == null) {
            break;
        } else {
            list.add(td);
        }
    }
    scanController.close();
    return td;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) CatalogRowFactory(org.apache.derby.iapi.sql.dictionary.CatalogRowFactory) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 7 with ScanController

use of org.apache.derby.iapi.store.access.ScanController 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 8 with ScanController

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

the class DataDictionaryImpl method getDescriptorViaIndexMinion.

private <T extends TupleDescriptor> T getDescriptorViaIndexMinion(int indexId, ExecIndexRow keyRow, ScanQualifier[][] scanQualifiers, TabInfoImpl ti, TupleDescriptor parentTupleDescriptor, List<? super T> list, Class<T> returnType, boolean forUpdate, int isolationLevel, TransactionController tc) throws StandardException {
    CatalogRowFactory rf = ti.getCatalogRowFactory();
    ConglomerateController heapCC;
    ExecIndexRow indexRow1;
    ExecRow outRow;
    RowLocation baseRowLocation;
    ScanController scanController;
    T td = null;
    if (SanityManager.DEBUG) {
        SanityManager.ASSERT(isolationLevel == TransactionController.ISOLATION_REPEATABLE_READ || isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED);
    }
    outRow = rf.makeEmptyRow();
    heapCC = tc.openConglomerate(ti.getHeapConglomerate(), false, 0, TransactionController.MODE_RECORD, isolationLevel);
    /* 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, isolationLevel, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    keyRow.getRowArray(), // startSearchOperation
    ScanController.GE, // scanQualifier,
    scanQualifiers, // stop position - through last row
    keyRow.getRowArray(), // stopSearchOperation
    ScanController.GT);
    while (true) {
        // create an index row template
        indexRow1 = getIndexRowFromHeapRow(ti.getIndexRowGenerator(indexId), heapCC.newRowLocationTemplate(), outRow);
        // from the table.
        if (!scanController.fetchNext(indexRow1.getRowArray())) {
            break;
        }
        baseRowLocation = (RowLocation) indexRow1.getColumn(indexRow1.nColumns());
        // RESOLVE paulat - remove the try catch block when track 3677 is fixed
        // just leave the contents of the try block
        // adding to get more info on track 3677
        boolean base_row_exists = false;
        try {
            base_row_exists = heapCC.fetch(baseRowLocation, outRow.getRowArray(), (FormatableBitSet) null);
        } catch (RuntimeException re) {
            if (SanityManager.DEBUG) {
                if (re instanceof AssertFailure) {
                    StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
                    strbuf.append(": An ASSERT was thrown when trying to locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
                    debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
                }
            }
            throw re;
        } catch (StandardException se) {
            if (SanityManager.DEBUG) {
                // do not want to catch lock timeout errors here
                if (se.getSQLState().equals("XSRS9")) {
                    StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
                    strbuf.append(": A StandardException was thrown when trying to locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
                    debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
                }
            }
            throw se;
        }
        if (SanityManager.DEBUG) {
            // holding scan cursor on index at ISOLATION_REPEATABLE_READ.
            if (!base_row_exists && (isolationLevel == TransactionController.ISOLATION_REPEATABLE_READ)) {
                StringBuffer strbuf = new StringBuffer("Error retrieving base row in table " + ti.getTableName());
                strbuf.append(": could not locate a row matching index row " + indexRow1 + " from index " + ti.getIndexName(indexId) + ", conglom number " + ti.getIndexConglomerate(indexId));
                debugGenerateInfo(strbuf, tc, heapCC, ti, indexId);
                // RESOLVE: for now, we are going to kill the VM
                // to help debug this problem.
                System.exit(1);
            // RESOLVE: not currently reached
            // SanityManager.THROWASSERT(strbuf.toString());
            }
        }
        if (!base_row_exists && (isolationLevel == TransactionController.ISOLATION_READ_UNCOMMITTED)) {
            // If isolationLevel == ISOLATION_READ_UNCOMMITTED we may
            // possibly see that the base row does not exist even if the
            // index row did.  This mode is currently only used by
            // TableNameInfo's call to hashAllTableDescriptorsByTableId,
            // cf. DERBY-3678, and by getStatisticsDescriptors,
            // cf. DERBY-4881.
            // 
            // For the former call, a table's schema descriptor is attempted
            // read, and if the base row for the schema has gone between
            // reading the index and the base table, the table that needs
            // this information has gone, too.  So, the table should not
            // be needed for printing lock timeout or deadlock
            // information, so we can safely just return an empty (schema)
            // descriptor. Furthermore, neither Timeout or DeadLock
            // diagnostics access the schema of a table descriptor, so it
            // seems safe to just return an empty schema descriptor for
            // the table.
            // 
            // There is a theoretical chance another row may have taken
            // the first one's place, but only if a compress of the base
            // table managed to run between the time we read the index and
            // the base row, which seems unlikely so we ignore that.
            // 
            // Even the index row may be gone in the above use case, of
            // course, and that case also returns an empty descriptor
            // since no match is found.
            td = null;
        } else {
            // normal case
            td = returnType.cast(rf.buildDescriptor(outRow, parentTupleDescriptor, this));
        }
        /* If list is null, then caller only wants a single descriptor - we're done
			 * else just add the current descriptor to the list.
			 */
        if (list == null) {
            break;
        } else if (td != null) {
            list.add(td);
        }
    }
    scanController.close();
    heapCC.close();
    return td;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) CatalogRowFactory(org.apache.derby.iapi.sql.dictionary.CatalogRowFactory) ExecIndexRow(org.apache.derby.iapi.sql.execute.ExecIndexRow) StandardException(org.apache.derby.shared.common.error.StandardException) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) AssertFailure(org.apache.derby.shared.common.sanity.AssertFailure) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 9 with ScanController

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

the class DataDictionaryImpl method getAllDependencyDescriptorsList.

/**
 * Build and return an List with DependencyDescriptors for
 * all of the stored dependencies.
 * This is useful for consistency checking.
 *
 * @return List		List of all DependencyDescriptors.
 *
 * @exception StandardException		Thrown on failure
 */
public List<TupleDescriptor> getAllDependencyDescriptorsList() throws StandardException {
    ScanController scanController;
    TransactionController tc;
    ExecRow outRow;
    ExecRow templateRow;
    List<TupleDescriptor> ddl = newSList();
    TabInfoImpl ti = getNonCoreTI(SYSDEPENDS_CATALOG_NUM);
    SYSDEPENDSRowFactory rf = (SYSDEPENDSRowFactory) ti.getCatalogRowFactory();
    // Get the current transaction controller
    tc = getTransactionCompile();
    outRow = rf.makeEmptyRow();
    scanController = tc.openScan(// conglomerate to open
    ti.getHeapConglomerate(), // don't hold open across commit
    false, // for read
    0, // scans entire table.
    TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    null, // startSearchOperation
    ScanController.GE, null, // stop position - through last row
    null, // stopSearchOperation
    ScanController.GT);
    while (scanController.fetchNext(outRow.getRowArray())) {
        DependencyDescriptor dependencyDescriptor;
        dependencyDescriptor = (DependencyDescriptor) rf.buildDescriptor(outRow, (TupleDescriptor) null, this);
        ddl.add(dependencyDescriptor);
    }
    scanController.close();
    return ddl;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) DependencyDescriptor(org.apache.derby.iapi.sql.dictionary.DependencyDescriptor) TupleDescriptor(org.apache.derby.iapi.sql.dictionary.TupleDescriptor) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 10 with ScanController

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

the class DataDictionaryImpl method getConstraintDescriptorViaHeap.

/**
 * Return a (single or list of) catalog row descriptor(s) from
 * SYSCONSTRAINTS through a heap scan
 *
 * @param scanQualifiers			qualifiers
 * @param ti						The TabInfoImpl to use
 * @param parentTupleDescriptor		The parentDescriptor, if applicable.
 * @param list						The list to build, if supplied.
 *									If null, then caller expects a single descriptor
 *
 * @return	The last matching descriptor
 *
 * @exception StandardException		Thrown on error
 */
protected TupleDescriptor getConstraintDescriptorViaHeap(ScanQualifier[][] scanQualifiers, TabInfoImpl ti, TupleDescriptor parentTupleDescriptor, ConstraintDescriptorList list) throws StandardException {
    SYSCONSTRAINTSRowFactory rf = (SYSCONSTRAINTSRowFactory) ti.getCatalogRowFactory();
    ExecRow outRow;
    ScanController scanController;
    TransactionController tc;
    ConstraintDescriptor cd = null;
    // Get the current transaction controller
    tc = getTransactionCompile();
    outRow = rf.makeEmptyRow();
    /*
		** Table scan
		*/
    scanController = tc.openScan(// conglomerate to open
    ti.getHeapConglomerate(), // don't hold open across commit
    false, // for read
    0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_REPEATABLE_READ, // all fields as objects
    (FormatableBitSet) null, // start position - first row
    (DataValueDescriptor[]) null, // startSearchOperation - none
    0, // scanQualifier,
    scanQualifiers, // stop position -through last row
    (DataValueDescriptor[]) null, // stopSearchOperation - none
    0);
    try {
        while (scanController.fetchNext(outRow.getRowArray())) {
            SubConstraintDescriptor subCD = null;
            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");
            }
            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 (list == null) {
                break;
            } else {
                list.add(cd);
            }
        }
    } finally {
        scanController.close();
    }
    return cd;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) 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)

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