Search in sources :

Example 16 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger 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 17 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger 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 18 with SQLInteger

use of org.apache.derby.iapi.types.SQLInteger 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)

Example 19 with SQLInteger

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

the class T_AccessFactory method storeCost.

/**
 * Test the access level StoreCost 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 storeCost(TransactionController tc) throws StandardException, T_Fail {
    int key_value;
    REPORT("(storeCost) 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 2 column row.
    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);
    cc.close();
    tc.commit();
    // flush the cache to get the row count updated.
    flush_cache();
    // Test 1 - ASSERT(initial row count after 1 insert should be 1)
    StoreCostController scc = tc.openStoreCost(conglomid);
    if (scc.getEstimatedRowCount() != 1) {
        throw T_Fail.testFailMsg("(storeCost) estimated row count not 1:" + scc.getEstimatedRowCount());
    }
    // Test 2 - ASSERT(should be able to set arbitrary row count)
    scc.setEstimatedRowCount(5);
    if (scc.getEstimatedRowCount() != 5) {
        throw T_Fail.testFailMsg("(storeCost) estimated row count not 5");
    }
    scc.setEstimatedRowCount(1);
    // Test 3 - ASSERT(should implement getFetchFromRowLocationCost())
    // should figure out some way to determine reasonable number is
    // returned.
    double fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) null, 0);
    fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) new FormatableBitSet(0), 0);
    REPORT("fetch cost (full row) of row loc = " + fetch_cost);
    fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) new FormatableBitSet(1), 0);
    FormatableBitSet bit_set = new FormatableBitSet(2);
    REPORT("fetch cost (no cols) of row loc = " + fetch_cost);
    bit_set.set(1);
    fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) new FormatableBitSet(1), 0);
    REPORT("fetch cost (1 col) of row loc = " + fetch_cost);
    // Test 4 - ASSERT(should implement getFetchFromFullKeyCost())
    // should figure out some way to determine reasonable number is
    // returned.
    /* - RESOLVE HEAP does not implement this.
        fetch_cost = 
            scc.getFetchFromFullKeyCost((FormatableBitSet) null, (int[]) null, 0);
        REPORT("fetch full key cost (full row) of row loc = " + fetch_cost);

        fetch_cost = 
            scc.getFetchFromFullKeyCost(
                (FormatableBitSet) new FormatableBitSet(0), (int[]) null, 0);
        REPORT("fetch full key cost (no cols) of row loc = " + fetch_cost);

        fetch_cost = 
            scc.getFetchFromFullKeyCost(
                (FormatableBitSet) new FormatableBitSet(1), (int[]) null, 0);
        REPORT("fetch full key cost (no cols) of row loc = " + fetch_cost);

        bit_set = new FormatableBitSet(2);
        bit_set.set(1);
        fetch_cost = 
            scc.getFetchFromFullKeyCost(
                (FormatableBitSet) new FormatableBitSet(1), (int[]) null, 0);
        REPORT("fetch full key cost (1 col) of row loc = " + fetch_cost);
        */
    // Test 5 - ASSERT(should implement getScanCost())
    // should figure out some way to determine reasonable number is
    // returned.
    StoreCostResult cost_result = new T_StoreCostResult();
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    (FormatableBitSet) null, // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (full row) of row loc = " + cost_result);
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    new FormatableBitSet(0), // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (no cols) of row loc = " + cost_result);
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    new FormatableBitSet(1), // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (no cols) of row loc = " + cost_result);
    bit_set = new FormatableBitSet(2);
    bit_set.set(1);
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    bit_set, // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (1 cols) of row loc = " + cost_result);
    // make sure you can get a row location.
    rowloc1 = scc.newRowLocationTemplate();
    REPORT("(storeCost) 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 20 with SQLInteger

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

the class T_AccessFactory method insertAndUpdate.

// Insert a single row with a single column containing
// the first argument integer, update it to the second
// value, and make sure the update happened.
// 
protected boolean insertAndUpdate(TransactionController tc, long conglomid, int value1, int value2) throws StandardException, T_Fail {
    // Open the conglomerate.
    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);
    r1.setCol(0, new SQLInteger(value1));
    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc);
    // Update it to the second value
    DataValueDescriptor[] update_row = new DataValueDescriptor[1];
    update_row[0] = new SQLInteger(value2);
    FormatableBitSet update_desc = new FormatableBitSet(1);
    update_desc.set(0);
    cc.replace(rowloc, update_row, update_desc);
    // Create a new row (of the same type, since the interface expects
    // the callers to be keeping the row types straight.
    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("(insertAndUpdate) Fetch val not there.");
    }
    // Close the conglomerate.
    cc.close();
    // Make sure we read back the value we wrote.
    if (c2.getInt() != value2)
        throw T_Fail.testFailMsg("(insertAndUpdate) Fetch value != updated value.");
    else
        return true;
}
Also used : 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

SQLInteger (org.apache.derby.iapi.types.SQLInteger)20 RowLocation (org.apache.derby.iapi.types.RowLocation)13 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)11 SQLLongint (org.apache.derby.iapi.types.SQLLongint)10 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)9 StandardException (org.apache.derby.shared.common.error.StandardException)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)3 SQLChar (org.apache.derby.iapi.types.SQLChar)3 Properties (java.util.Properties)2 SQLBoolean (org.apache.derby.iapi.types.SQLBoolean)2 Hashtable (java.util.Hashtable)1 UUID (org.apache.derby.catalog.UUID)1 ContextManager (org.apache.derby.iapi.services.context.ContextManager)1 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)1 SubCheckConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubCheckConstraintDescriptor)1 SubConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubConstraintDescriptor)1 SubKeyConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.SubKeyConstraintDescriptor)1 CursorResultSet (org.apache.derby.iapi.sql.execute.CursorResultSet)1 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)1