Search in sources :

Example 56 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method partialScan.

/**
 * Test partial scans.
 * <p>
 *
 * @return true if the test succeeded.
 *
 * @param tc The transaction controller to use in the test.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail Unexpected behaviour from the API
 */
protected boolean partialScan(TransactionController tc) throws StandardException, T_Fail {
    int key_value;
    REPORT("(partialScan) starting");
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(2);
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a 1 column row. int column = 1.
    T_AccessRow r1 = new T_AccessRow(2);
    SQLInteger c1 = new SQLInteger(1);
    SQLInteger c2 = new SQLInteger(100);
    r1.setCol(0, c1);
    r1.setCol(1, c2);
    // Get a location template
    RowLocation rowloc1 = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);
    // create another 2 column row. int column = 2.
    // Get a location template
    r1.setCol(0, new SQLInteger(2));
    r1.setCol(1, new SQLInteger(200));
    RowLocation rowloc2 = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc2);
    cc.delete(rowloc2);
    tc.commit();
    // Try a partial Row scan with no columns.
    // only get the 2nd column.
    FormatableBitSet validColumns = new FormatableBitSet();
    ScanController scan = tc.openScan(conglomid, // don't hold
    false, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // only get the second column
    validColumns, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    if (!scan.next()) {
        throw T_Fail.testFailMsg("(partialScan) did not see first row.");
    }
    if (scan.next()) {
        throw T_Fail.testFailMsg("(partialScan) saw more than one row.");
    }
    // RESOLVE - should test the btree one also.
    REPORT("(partialScan) finishing");
    return true;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 57 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method scanInfo.

/**
 * Test the access level ScanInfo interface.
 * <p>
 *
 * @return true if the test succeeded.
 *
 * @param tc The transaction controller to use in the test.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail Unexpected behaviour from the API
 */
protected boolean scanInfo(TransactionController tc) throws StandardException, T_Fail {
    int key_value;
    REPORT("(scanInfo) starting");
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(2);
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a 1 column row. int column = 1.
    T_AccessRow r1 = new T_AccessRow(2);
    SQLInteger c1 = new SQLInteger(1);
    SQLInteger c2 = new SQLInteger(100);
    r1.setCol(0, c1);
    r1.setCol(1, c2);
    // Get a location template
    RowLocation rowloc1 = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);
    // create another 2 column row. int column = 2.
    // Get a location template
    r1.setCol(0, new SQLInteger(2));
    r1.setCol(1, new SQLInteger(200));
    RowLocation rowloc2 = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc2);
    cc.delete(rowloc2);
    if (tc.isPristine() || tc.isIdle()) {
        throw T_Fail.testFailMsg("(scanInfo) bad xact state after update xact.");
    }
    tc.commit();
    ScanController scan = tc.openScan(conglomid, // don't hold
    false, // for read
    0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    if (!scan.isTableLocked()) {
        throw T_Fail.testFailMsg("(scanInfo) table should be table locked.");
    }
    while (scan.next()) {
        scan.fetch(r1.getRowArray());
    }
    ScanInfo scan_info = scan.getScanInfo();
    Properties prop = scan_info.getAllScanInfo(null);
    if (!tc.isPristine() || tc.isIdle()) {
        throw T_Fail.testFailMsg("(scanInfo) bad xact state after update xact.");
    }
    REPORT(("return from full row scan heap.getScanInfo() = " + prop));
    if (Integer.parseInt(prop.getProperty(MessageService.getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED))) != 1) {
        throw T_Fail.testFailMsg("(scanInfo) wrong numPagesVisited.  Expected 1, got " + Integer.parseInt(prop.getProperty(MessageService.getTextMessage(SQLState.STORE_RTS_NUM_PAGES_VISITED))));
    }
    if (Integer.parseInt(prop.getProperty(MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED))) != 2) {
        throw T_Fail.testFailMsg("(scanInfo) wrong numRowsVisited. Expected 2, got " + Integer.parseInt(prop.getProperty(MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_VISITED))));
    }
    if (Integer.parseInt(prop.getProperty(MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_QUALIFIED))) != 1) {
        throw T_Fail.testFailMsg("(scanInfo) wrong numRowsQualified. Expected 1, got " + Integer.parseInt(prop.getProperty(MessageService.getTextMessage(SQLState.STORE_RTS_NUM_ROWS_QUALIFIED))));
    }
    // Try a partial Row scan
    // only get the 2nd column.
    FormatableBitSet validColumns = new FormatableBitSet(3);
    validColumns.set(1);
    scan = tc.openScan(conglomid, // don't hold
    false, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // only get the second column
    validColumns, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    if (scan.isTableLocked()) {
        throw T_Fail.testFailMsg("(scanInfo) table should be row locked.");
    }
    scan_info = scan.getScanInfo();
    prop = scan_info.getAllScanInfo(null);
    REPORT(("return from partial scan heap.getScanInfo() = " + prop));
    // RESOLVE - should test the btree one also.
    REPORT("(scanInfo) finishing");
    return true;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) Properties(java.util.Properties) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 58 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method positionAtRowLocation.

// test position at row location, in terms of holdability
protected boolean positionAtRowLocation(TransactionController tc) throws StandardException, T_Fail {
    REPORT("(positionAtRowLocation)");
    // Create a conglomerate with one row:
    long base_id = createAConglom(tc, 0, false);
    // Open it.
    ConglomerateController cc = tc.openConglomerate(base_id, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    T_AccessRow accessRow = null;
    for (int i = 1; i < 5; i++) {
        // Create a row.
        accessRow = new T_AccessRow(1);
        SQLLongint c1 = new SQLLongint(i);
        accessRow.setCol(0, c1);
        // Insert the row and remember its location.
        cc.insert(accessRow.getRowArray());
    }
    tc.commit();
    cc.close();
    // Open scan on the table:
    ScanController base_scan = tc.openScan(base_id, // do hold
    true, // for update
    TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    (FormatableBitSet) null, // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // qualifier - accept all rows
    null, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0);
    // Move to the first row
    base_scan.next();
    // Get the RowLocation for the first row:
    RowLocation firstRow = base_scan.newRowLocationTemplate();
    base_scan.fetchLocation(firstRow);
    base_scan.fetch(accessRow.getRowArray());
    long key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 0) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_1) 1st row is not 0 it is:" + key_value);
    }
    // Move to some other rows:
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 1) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_2) 2nd row is not 1 it is:" + key_value);
    }
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 2) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_3) 3d row is not 2 it is:" + key_value);
    }
    if (!base_scan.positionAtRowLocation(firstRow)) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_4) Failed to position at RowLocation");
    }
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 0) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_5) 1st row is not 0 it is:" + key_value);
    }
    // Commit and check holdability:
    tc.commit();
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 1) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_6) 2nd row is not 1 it is:" + key_value);
    }
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 2) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_7) 3d row is not 2 it is:" + key_value);
    }
    if (!base_scan.positionAtRowLocation(firstRow)) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_8) Failed to position at " + "RowLocation after commit");
    }
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 0) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_9) 1st row is not 0 it is:" + key_value);
    }
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 1) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_10) 2nd row is not 1 it is:" + key_value);
    }
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 2) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_10) 3d row is not 2 it is:" + key_value);
    }
    // Using reopenScanByRowLocation(..)
    // instead of positionAtRowLocation(..):
    base_scan.reopenScanByRowLocation(firstRow, null);
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 0) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_11) 1st row is not 0 it is:" + key_value);
    }
    tc.commit();
    // Compress the conglomerate
    tc.compressConglomerate(base_id);
    tc.commit();
    base_scan.next();
    base_scan.fetch(accessRow.getRowArray());
    key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
    if (key_value != 1) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_12) 2nd row is not 1 it is:" + key_value);
    }
    // that they are holdable
    if (base_scan.positionAtRowLocation(firstRow)) {
        throw T_Fail.testFailMsg("(positionAtRowLocation_err_12) Unexpectedly succeeded at " + "positioning at RowLocation after compress");
    }
    base_scan.close();
    REPORT("(positionAtRowLocation) succeeded");
    return true;
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Example 59 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method commitTest.

// test various flavors of commit
protected boolean commitTest(TransactionController tc) throws StandardException, T_Fail {
    REPORT("(commitTest)");
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(1);
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    tc.commit();
    // Open it.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_AccessRow r1 = new T_AccessRow(1);
    SQLInteger c1 = new SQLInteger(0);
    r1.setCol(0, c1);
    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc);
    // now commit nosync without releasing the row lock
    tc.commitNoSync(TransactionController.KEEP_LOCKS);
    // cc should be closed
    try {
        cc.newRowLocationTemplate();
        throw T_Fail.testFailMsg("conglomerate controller is not closed after commit");
    } catch (StandardException se) {
    // expect fail
    }
    // get another transaction going
    ContextManager cm2 = getContextService().newContextManager();
    getContextService().setCurrentContextManager(cm2);
    TransactionController tc2 = null;
    ConglomerateController cc2 = null;
    try {
        tc2 = store.getTransaction(cm2);
        cc2 = tc2.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        // try to lock the row, it should fail
        // Mikem RESOLVE: this does not get a row lock
        // cc2.fetch(rowloc, r1.getRowArray(), (FormatableBitSet)null)
        cc2.delete(rowloc);
        throw T_Fail.testFailMsg("expected time out did not happen");
    } catch (StandardException lfe) {
        if (!lfe.getMessageId().equals(SQLState.LOCK_TIMEOUT))
            throw lfe;
    } finally {
        getContextService().resetCurrentContextManager(cm2);
    }
    // see whether anyone is blocked at all
    if (tc.anyoneBlocked()) {
        throw T_Fail.testFailMsg("No transactions should be blocked");
    }
    // now really commit the transaction
    tc.commit();
    getContextService().setCurrentContextManager(cm2);
    try {
        cc2.fetch(rowloc, r1.getRowArray(), (FormatableBitSet) null);
        // get rid of the other transaction
        tc2.commitNoSync(TransactionController.RELEASE_LOCKS);
        tc2.destroy();
    } finally {
        getContextService().resetCurrentContextManager(cm2);
    }
    REPORT("(commitTest) succeeded");
    return true;
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) ContextManager(org.apache.derby.iapi.services.context.ContextManager) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 60 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method insertAndFetch.

// Insert a single row with a single column containing
// the argument integer, and fetch it back, making sure that
// we read the correct value.
// 
protected boolean insertAndFetch(TransactionController tc, long conglomid, int value) throws StandardException, T_Fail {
    StaticCompiledOpenConglomInfo static_info = tc.getStaticCompiledConglomInfo(conglomid);
    DynamicCompiledOpenConglomInfo dynamic_info = tc.getDynamicCompiledConglomInfo(conglomid);
    String curr_xact_name = tc.getTransactionIdString();
    REPORT("(insertAndFetch) xact id = " + curr_xact_name);
    // Open the conglomerate.
    ConglomerateController cc = tc.openCompiledConglomerate(false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, static_info, dynamic_info);
    // Create a row.
    T_AccessRow r1 = new T_AccessRow(1);
    SQLInteger c1 = new SQLInteger(value);
    r1.setCol(0, c1);
    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc);
    // quick test to make sure we can hash insert and find row location.
    Hashtable<RowLocation, RowLocation> test_rowloc_hash = new Hashtable<RowLocation, RowLocation>();
    test_rowloc_hash.put(rowloc, rowloc);
    RowLocation hash_find = test_rowloc_hash.get(rowloc);
    if (!hash_find.equals(rowloc))
        throw T_Fail.testFailMsg("(insertAndFetch) bad hash lookup 1");
    hash_find = test_rowloc_hash.remove(rowloc);
    if (!hash_find.equals(rowloc))
        throw T_Fail.testFailMsg("(insertAndFetch) bad hash lookup 2");
    hash_find = test_rowloc_hash.remove(rowloc);
    if (hash_find != null)
        throw T_Fail.testFailMsg("(insertAndFetch) bad hash lookup 3");
    // Create a new row of the same type (since the interface expects
    // the callers to be keeping the row types straight), but with
    // a different column value.
    T_AccessRow r2 = new T_AccessRow(1);
    SQLInteger c2 = new SQLInteger(0);
    r2.setCol(0, c2);
    // Fetch the stored value.
    if (!cc.fetch(rowloc, r2.getRowArray(), (FormatableBitSet) null)) {
        throw T_Fail.testFailMsg("(insertAndFetch) fetch found no row.");
    }
    // Fetch using the fetch partial column interface
    SQLInteger c3 = new SQLInteger(0);
    FormatableBitSet singleColumn = new FormatableBitSet(1);
    singleColumn.set(0);
    DataValueDescriptor[] c3row = new DataValueDescriptor[1];
    c3row[0] = c3;
    if (!cc.fetch(rowloc, c3row, singleColumn)) {
        throw T_Fail.testFailMsg("(insertAndFetch) fetch found no row.");
    }
    // Close the conglomerate.
    cc.close();
    // Make sure we read back the value we wrote.
    if (c2.getInt() != value)
        throw T_Fail.testFailMsg("(insertAndFetch) Fetched value != inserted value.");
    if (c3.getInt() != value)
        throw T_Fail.testFailMsg("(insertAndFetch) Fetched value != inserted value.");
    return true;
}
Also used : Hashtable(java.util.Hashtable) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Aggregations

RowLocation (org.apache.derby.iapi.types.RowLocation)89 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)54 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)40 SQLLongint (org.apache.derby.iapi.types.SQLLongint)35 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)32 ScanController (org.apache.derby.iapi.store.access.ScanController)29 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)27 Properties (java.util.Properties)16 SQLInteger (org.apache.derby.iapi.types.SQLInteger)13 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)12 StandardException (org.apache.derby.shared.common.error.StandardException)11 SQLChar (org.apache.derby.iapi.types.SQLChar)10 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)7 TransactionController (org.apache.derby.iapi.store.access.TransactionController)7 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)6 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)4 UUID (org.apache.derby.catalog.UUID)3 ContextManager (org.apache.derby.iapi.services.context.ContextManager)3 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)3