Search in sources :

Example 91 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet 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 92 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet 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 93 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet 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)

Example 94 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class T_AccessFactory method getBtreeTemplate.

private DataValueDescriptor[] getBtreeTemplate(TransactionController tc, long baseConglomId) throws StandardException {
    // Open a scan on the base conglomerate which will return all rows.
    FormatableBitSet singleColumn = new FormatableBitSet(1);
    singleColumn.set(0);
    ScanController sc = tc.openScan(baseConglomId, false, // not for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    singleColumn, null, 0, null, null, 0);
    // Create the template for the index. This method "knows" that
    // all rows in the base table have one IntCol
    T_AccessRow template = new T_AccessRow(2);
    SQLLongint col0 = new SQLLongint(0);
    RowLocation col1 = sc.newRowLocationTemplate();
    template.setCol(0, col0);
    template.setCol(1, col1);
    sc.close();
    return (template.getRowArray());
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 95 with FormatableBitSet

use of org.apache.derby.iapi.services.io.FormatableBitSet in project derby by apache.

the class T_QualifierTest method t_scanFetchHashtable.

/**
 * Test scan which does FetchSet.
 * <p>
 * FetchSet() returns the entire result set in the hash table.
 * <p>
 *
 * @return Whether the test succeeded or not.
 *
 * @exception  StandardException  Standard exception policy.
 */
public static boolean t_scanFetchHashtable(TransactionController tc, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier[][] qualifier, DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail {
    HashSet set = null;
    long key;
    long numrows = 0;
    boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
    set = create_hash_set(input_expect_key, expect_numrows, order);
    // select entire data set into a hash table, with first column key
    int[] keyColumns = new int[1];
    keyColumns[0] = 0;
    BackingStoreHashtable result_set = tc.createBackingStoreHashtableFromScan(conglomid, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op, // no limit on total rows.
    -1, // first column is hash key column
    keyColumns, // don't remove duplicates
    false, // no estimate of rows
    -1, // put it all into memory
    -1, // use default initial capacity
    -1, // use default load factor
    -1, // don't maintain runtime statistics
    false, // don't skip null key columns
    false, // don't keep after commit
    false, // don't include row locations
    false);
    // make sure the expected result set is the same as the actual result
    // set.
    Enumeration e = result_set.elements();
    while (e.hasMoreElements()) {
        Object obj;
        DataValueDescriptor[] row = null;
        if ((obj = e.nextElement()) instanceof DataValueDescriptor[]) {
            row = (DataValueDescriptor[]) obj;
            key = ((SQLLongint) (row[2])).getLong();
            if (!set.remove(key)) {
                return (fail("(t_scanFetchHashtable-obj) wrong key, expected (" + input_expect_key + ")" + "but got (" + key + ")."));
            }
            numrows++;
        } else if (obj instanceof List) {
            List row_vect = (List) obj;
            for (int i = 0; i < row_vect.size(); i++) {
                row = (DataValueDescriptor[]) row_vect.get(i);
                key = ((SQLLongint) (row[2])).getLong();
                if (!set.remove(key)) {
                    return (fail("(t_scanFetchHashtable-vector) wrong key, expected (" + input_expect_key + ")" + "but got (" + key + ")."));
                }
                numrows++;
            }
        } else {
            return (fail("(t_scanFetchHashtable) got bad type for data: " + obj));
        }
    }
    if (numrows != expect_numrows) {
        return (fail("(t_scanFetchHashtable) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
    }
    result_set.close();
    // select entire data set into a hash table, with key being
    // the third column, which is the unique id used to verify the
    // right result set is being returned.:
    // open a new scan
    keyColumns[0] = 2;
    result_set = tc.createBackingStoreHashtableFromScan(conglomid, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op, // no limit on total rows.
    -1, // third column is hash key column
    keyColumns, // don't remove duplicates
    false, // no estimate of rows
    -1, // put it all into memory
    -1, // use default initial capacity
    -1, // use default load factor
    -1, // don't maintain runtime statistics
    false, // don't skip null key columns
    false, // don't keep after commit
    false, // don't include row locations
    false);
    Object removed_obj;
    for (numrows = 0; numrows < expect_numrows; numrows++) {
        long exp_key;
        if (order == ORDER_DESC)
            exp_key = input_expect_key - numrows;
        else
            exp_key = input_expect_key + numrows;
        if ((removed_obj = result_set.remove(new SQLLongint(exp_key))) == null) {
            fail("(t_scanFetchHashtable-2-vector) wrong key, expected (" + (exp_key) + ")" + "but did not find it.");
        }
    }
    if (numrows != expect_numrows) {
        return (fail("(t_scanFetchHashtable-2) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
    }
    return (true);
}
Also used : Enumeration(java.util.Enumeration) SQLLongint(org.apache.derby.iapi.types.SQLLongint) List(java.util.List) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) HashSet(java.util.HashSet) BackingStoreHashtable(org.apache.derby.iapi.store.access.BackingStoreHashtable)

Aggregations

FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)146 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)36 RowLocation (org.apache.derby.iapi.types.RowLocation)32 SQLLongint (org.apache.derby.iapi.types.SQLLongint)25 ScanController (org.apache.derby.iapi.store.access.ScanController)24 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)23 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)18 StandardException (org.apache.derby.shared.common.error.StandardException)17 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)15 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)13 TransactionController (org.apache.derby.iapi.store.access.TransactionController)12 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)11 SQLInteger (org.apache.derby.iapi.types.SQLInteger)11 UUID (org.apache.derby.catalog.UUID)10 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)10 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)9 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)7 SQLChar (org.apache.derby.iapi.types.SQLChar)7 Properties (java.util.Properties)6 ContextManager (org.apache.derby.iapi.services.context.ContextManager)6