Search in sources :

Example 1 with ScanInfo

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

the class T_CreateConglomRet method t_001.

/**
 * Test BTreeController.insert()
 * <p>
 * Just verify that insert code works for a secondary index.  Just call
 * the interface and make sure the row got there.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_001(TransactionController tc) throws StandardException, T_Fail {
    REPORT("Starting t_001");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, false, 0, create_ret);
    // Open the base table
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the secondary index
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    if (!(index_cc instanceof B2IController)) {
        throw T_Fail.testFailMsg("openConglomerate returned wrong type");
    }
    if (!index_cc.isKeyed()) {
        throw T_Fail.testFailMsg("btree is not keyed.");
    }
    index_cc.checkConsistency();
    // Create a row and insert into base table, remembering it's location.
    DataValueDescriptor[] r1 = TemplateRow.newU8Row(2);
    T_SecondaryIndexRow index_row1 = new T_SecondaryIndexRow();
    RowLocation base_rowloc1 = base_cc.newRowLocationTemplate();
    index_row1.init(r1, base_rowloc1, 3);
    ((SQLLongint) r1[0]).setValue(2);
    ((SQLLongint) r1[1]).setValue(2);
    // Insert the row into the base table and remember its location.
    base_cc.insertAndFetchLocation(r1, base_rowloc1);
    // Insert the row into the secondary index.
    if (index_cc.insert(index_row1.getRow()) != 0)
        throw T_Fail.testFailMsg("insert failed");
    // Make sure we read back the value we wrote from base and index table.
    DataValueDescriptor[] r2 = TemplateRow.newU8Row(2);
    T_SecondaryIndexRow index_row2 = new T_SecondaryIndexRow();
    RowLocation base_rowloc2 = base_cc.newRowLocationTemplate();
    index_row2.init(r2, base_rowloc2, 3);
    // base table check:
    if (!base_cc.fetch(base_rowloc1, r2, (FormatableBitSet) null)) {
        return (FAIL("(t_001) insert into base table failed"));
    }
    if (((SQLLongint) r2[0]).getLong() != 2 || ((SQLLongint) r2[1]).getLong() != 2) {
        return (FAIL("(t_001) insert into base table failed"));
    }
    // index check - there should be only one record:
    ScanController scan = tc.openScan(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, null, ScanController.NA, null, null, ScanController.NA);
    scan.next();
    scan.fetch(index_row2.getRow());
    // isCurrentPositionDeleted() works.
    if (scan.isCurrentPositionDeleted())
        throw T_Fail.testFailMsg("current row should not be deleted\n");
    if (!scan.doesCurrentPositionQualify())
        throw T_Fail.testFailMsg("current row should still qualify\n");
    scan.delete();
    if (!scan.isCurrentPositionDeleted())
        throw T_Fail.testFailMsg("current row should be deleted\n");
    if (scan.doesCurrentPositionQualify())
        throw T_Fail.testFailMsg("deleted row should not qualify\n");
    // just call the debugging code to make sure it doesn't fail.
    REPORT("Calling scan.tostring(): " + scan);
    if (scan.next() || ((SQLLongint) (index_row2.getRow()[0])).getLong() != 2 || ((SQLLongint) (index_row2.getRow()[1])).getLong() != 2) {
        return (FAIL("(t_001) insert into index failed in base cols"));
    }
    // test the scaninfo interface.
    ScanInfo scan_info = scan.getScanInfo();
    Properties prop = scan_info.getAllScanInfo(null);
    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))) != 1) {
        throw T_Fail.testFailMsg("(scanInfo) wrong numRowsVisited. Expected 1, 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))));
    }
    int compare_result = base_rowloc1.compare(base_rowloc2);
    if (compare_result != 0) {
        return (FAIL("(t_001) insert into index failed in recordhandle.\n" + "\texpected RecordHandle = " + base_rowloc1 + "\n" + "\tgot      RecordHandle = " + base_rowloc2 + "\tcompare result = " + compare_result));
    }
    index_cc.checkConsistency();
    // Close the conglomerates.
    base_cc.close();
    index_cc.close();
    try {
        base_cc.insert(r1);
        return (FAIL("(t_001) insert on closed conglomerate worked"));
    } catch (StandardException e) {
    // e.printStackTrace();
    }
    try {
        if (index_cc.insert(r1) != 0)
            throw T_Fail.testFailMsg("insert failed");
        return (FAIL("(t_001) insert on closed conglomerate worked"));
    } catch (StandardException e) {
    // e.printStackTrace();
    }
    tc.commit();
    REPORT("Ending t_001");
    return true;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) ScanInfo(org.apache.derby.iapi.store.access.ScanInfo) Properties(java.util.Properties) SQLLongint(org.apache.derby.iapi.types.SQLLongint) StandardException(org.apache.derby.shared.common.error.StandardException) SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

Properties (java.util.Properties)1 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)1 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)1 ScanController (org.apache.derby.iapi.store.access.ScanController)1 ScanInfo (org.apache.derby.iapi.store.access.ScanInfo)1 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)1 RowLocation (org.apache.derby.iapi.types.RowLocation)1 SQLLongint (org.apache.derby.iapi.types.SQLLongint)1 StandardException (org.apache.derby.shared.common.error.StandardException)1