Search in sources :

Example 21 with SQLChar

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

the class T_Recovery method R004.

/* recover test 4 */
protected void R004() throws T_Fail, StandardException {
    long cid = find(key(4, 1));
    if (cid < 0) {
        REPORT("R004 not run");
        return;
    }
    Transaction t = t_util.t_startTransaction();
    try {
        ContainerHandle c = t_util.t_openContainer(t, 0, cid, false);
        Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
        // first row should contain (null, REC_001, REC_002, null, REC_005)
        DataValueDescriptor column = new SQLChar();
        t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, null);
        t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_001);
        t_util.t_checkFetchColFromSlot(page, 0, 2, column, false, REC_002);
        t_util.t_checkFetchColFromSlot(page, 0, 3, column, false, null);
        t_util.t_checkFetchColFromSlot(page, 0, 4, column, false, REC_005);
        page.unlatch();
    } finally {
        t_util.t_commit(t);
        t.close();
    }
    PASS("R004: containerId " + cid);
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle)

Example 22 with SQLChar

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

the class T_Recovery method R100.

/* recover S100 */
protected void R100() throws T_Fail, StandardException {
    long[] cid = new long[4];
    cid[0] = find(key(100, 1));
    if (cid[0] < 0) {
        REPORT("R100 not run");
        return;
    }
    cid[1] = find(key(100, 2));
    cid[2] = find(key(100, 3));
    cid[3] = find(key(100, 4));
    Transaction t = t_util.t_startTransaction();
    try {
        ContainerHandle c;
        Page page;
        for (int i = 0; i < 4; i++) {
            c = t_util.t_openContainer(t, 0, cid[i], false);
            page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
            if (i == 3)
                t_util.t_checkRecordCount(page, 1, 0);
            else
                t_util.t_checkRecordCount(page, 1, 1);
            t_util.t_checkFieldCount(page, 0, 2);
            // each row has REC_005, REC_004
            DataValueDescriptor column = new SQLChar();
            t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, REC_005);
            t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_004);
            page.unlatch();
        }
        PASS("R100 passed: container1 " + cid[0] + " container2 " + cid[1] + " container3 " + cid[2] + " container4 " + cid[3]);
    } finally {
        t_util.t_commit(t);
        t.close();
    }
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle)

Example 23 with SQLChar

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

the class T_Recovery method S003.

/*
	 *  test 3 -  update row
	 */
protected void S003() throws T_Fail, StandardException {
    Transaction t = t_util.t_startTransaction();
    try {
        long cid = t_util.t_addContainer(t, 0);
        t_util.t_commit(t);
        ContainerHandle c = t_util.t_openContainer(t, 0, cid, true);
        Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
        T_RawStoreRow row1 = new T_RawStoreRow(REC_001);
        RecordHandle r1 = t_util.t_insertAtSlot(page, 0, row1);
        t_util.t_checkFetch(page, r1, row1);
        // REPORT("grows the #column in row");
        T_RawStoreRow upd1 = new T_RawStoreRow(3);
        upd1.setColumn(0, (String) null);
        upd1.setColumn(1, REC_003);
        upd1.setColumn(2, REC_004);
        r1 = page.updateAtSlot(0, upd1.getRow(), (FormatableBitSet) null);
        // REPORT("update that shrinks the #columns in row");
        T_RawStoreRow row2 = new T_RawStoreRow(3);
        row2.setColumn(0, REC_001);
        row2.setColumn(1, REC_002);
        row2.setColumn(2, REC_003);
        T_RawStoreRow upd2 = new T_RawStoreRow(REC_005);
        RecordHandle r2 = t_util.t_insertAtSlot(page, 1, row2);
        if (r2 != null) {
            r2 = page.updateAtSlot(1, upd2.getRow(), (FormatableBitSet) null);
        }
        t_util.t_checkFetch(page, r1, upd1);
        // first row should contain (null, REC_003, REC_004)
        DataValueDescriptor column = new SQLChar();
        // page, slot, field, column, forUpdate, data
        t_util.t_checkFetchColFromSlot(page, 0, 0, column, true, null);
        t_util.t_checkFetchColFromSlot(page, 0, 1, column, true, REC_003);
        t_util.t_checkFetchColFromSlot(page, 0, 2, column, true, REC_004);
        if (r2 != null) {
            t_util.t_checkFetch(page, r2, upd2);
            // second row should contain (REC_005)
            t_util.t_checkFetchColFromSlot(page, 1, 0, column, true, REC_005);
        }
        REPORT("setup S003: containerId " + cid + " recordCount " + page.recordCount());
        register(key(3, 1), cid);
        register(key(3, 2), page.recordCount());
        page.unlatch();
    } finally {
        t_util.t_commit(t);
        t.close();
    }
}
Also used : RawTransaction(org.apache.derby.iapi.store.raw.xact.RawTransaction) SQLChar(org.apache.derby.iapi.types.SQLChar) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RawContainerHandle(org.apache.derby.iapi.store.raw.data.RawContainerHandle)

Example 24 with SQLChar

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

the class T_CreateConglomRet method t_003.

/**
 * Test BTree.openScan(), BtreeScan.init(), BtreeScan.next(),
 * BtreeScan.fetch().
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_003(TransactionController tc) throws StandardException, T_Fail {
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    // base row template - last column is just to make row long so that
    // multiple pages are spanned.
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(4);
    base_row[3] = new SQLChar();
    String string_1500char = new String();
    for (int i = 0; i < 300; i++) string_1500char += "mikem";
    boolean ret_val = true;
    long value = -1;
    long[] col1 = { 1, 3, 4, 4, 4, 5, 5, 5, 6, 7, 9 };
    long[] col2 = { 1, 1, 2, 4, 6, 2, 4, 6, 1, 1, 1 };
    long[] col3 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
    // set of deleted rows to make scans more interesting
    long[] d_col1 = { 0, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 10, 11, 12 };
    long[] d_col2 = { 1, 1, 2, 3, 5, 0, 3, 5, 0, 0, 1, 42, 42, 1 };
    long[] d_col3 = { 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104 };
    REPORT("Starting t_003");
    // create the base table
    long base_conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // base table template row
    base_row, // column sort order - not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the base table
    ConglomerateController base_cc = tc.openConglomerate(base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // initialize the secondary index row - pointing it at base row
    index_row.init(base_row, base_cc.newRowLocationTemplate(), 5);
    Properties properties = createProperties(// no current properties list
    null, // don't allow duplicates
    false, // 4 columns in index row
    5, // non-unique index
    5, // maintain parent links
    true, // base conglom id
    base_conglomid, // row loc in last column
    4);
    long index_conglomid = tc.createConglomerate(// create a btree secondary
    "BTREE", // row template
    index_row.getRow(), // column sort order - default
    null, // default collation
    null, // properties
    properties, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow template = new T_SecondaryIndexRow();
    RowLocation row_loc = base_cc.newRowLocationTemplate();
    template.init(base_row, row_loc, 5);
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = col1.length - 1; i >= 0; i--) {
        ((SQLLongint) (template.getRow()[0])).setValue(col1[i]);
        ((SQLLongint) (template.getRow()[1])).setValue(col2[i]);
        ((SQLLongint) (template.getRow()[2])).setValue(col3[i]);
        base_row[3] = new SQLChar(string_1500char);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        // ")" + template);
        if (index_cc.insert(template.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    index_cc.checkConsistency();
    ((B2IController) index_cc).debugConglomerate();
    ret_val = t_003_scan_test_cases(tc, index_conglomid, template);
    // may or may not clean these up.
    for (int i = d_col1.length - 1; i >= 0; i--) {
        ((SQLLongint) (template.getRow()[0])).setValue(d_col1[i]);
        ((SQLLongint) (template.getRow()[1])).setValue(d_col2[i]);
        ((SQLLongint) (template.getRow()[2])).setValue(d_col3[i]);
        base_row[3] = new SQLChar(string_1500char);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        // ")" + template);
        if (index_cc.insert(template.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
        // now delete the row.
        base_cc.delete(row_loc);
        ScanController delete_scan = tc.openScan(index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, template.getRow(), ScanController.GE, null, template.getRow(), ScanController.GT);
        if (!delete_scan.next()) {
            throw T_Fail.testFailMsg("delete could not find key");
        } else {
            delete_scan.delete();
            if (delete_scan.next())
                throw T_Fail.testFailMsg("delete found more than one key");
        }
        delete_scan.close();
    }
    ret_val = t_003_scan_test_cases(tc, index_conglomid, template);
    // Close the conglomerate.
    index_cc.close();
    tc.commit();
    REPORT("Ending t_003");
    return (ret_val);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLChar(org.apache.derby.iapi.types.SQLChar) Properties(java.util.Properties) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLLongint(org.apache.derby.iapi.types.SQLLongint) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 25 with SQLChar

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

the class T_CreateConglomRet method t_017.

/**
 * Test BTree.openScan(), BtreeScan.init(), BtreeScan.next(),
 * BtreeScan.fetch() with descending indexes.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_017(TransactionController tc) throws StandardException, T_Fail {
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    // base row template - last column is just to make row long so that
    // multiple pages are spanned.
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(4);
    base_row[3] = new SQLChar();
    String string_1500char = new String();
    for (int i = 0; i < 300; i++) string_1500char += "mikem";
    boolean ret_val = true;
    long value = -1;
    long[] col1 = { 1, 3, 4, 4, 4, 5, 5, 5, 6, 7, 9 };
    long[] col2 = { 1, 1, 2, 4, 6, 2, 4, 6, 1, 1, 1 };
    long[] col3 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
    // set of deleted rows to make scans more interesting
    long[] d_col1 = { 0, 2, 3, 4, 4, 5, 5, 5, 6, 7, 8, 10, 11, 12 };
    long[] d_col2 = { 1, 1, 2, 3, 5, 0, 3, 5, 0, 0, 1, 42, 42, 1 };
    long[] d_col3 = { 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104 };
    REPORT("Starting t_017");
    // create the base table
    long base_conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // base table template row
    base_row, // column sort order - not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the base table
    ConglomerateController base_cc = tc.openConglomerate(base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // initialize the secondary index row - pointing it at base row
    index_row.init(base_row, base_cc.newRowLocationTemplate(), 5);
    Properties properties = createProperties(// no current properties list
    null, // don't allow duplicates
    false, // 4 columns in index row
    5, // non-unique index
    5, // maintain parent links
    true, // base conglom id
    base_conglomid, // row loc in last column
    4);
    // create the index with all the columns in descending order
    ColumnOrdering[] order = new ColumnOrdering[5];
    // descending
    order[0] = new T_ColumnOrderingImpl(0, false);
    // descending
    order[1] = new T_ColumnOrderingImpl(1, false);
    // descending
    order[2] = new T_ColumnOrderingImpl(2, false);
    // descending
    order[3] = new T_ColumnOrderingImpl(3, false);
    // asccending
    order[4] = new T_ColumnOrderingImpl(4, true);
    long index_conglomid = tc.createConglomerate(// create a btree secondary
    "BTREE", // row template
    index_row.getRow(), // column sort order - default
    order, // default collation
    null, // properties
    properties, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow template = new T_SecondaryIndexRow();
    RowLocation row_loc = base_cc.newRowLocationTemplate();
    template.init(base_row, row_loc, 5);
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = col1.length - 1; i >= 0; i--) {
        ((SQLLongint) (template.getRow()[0])).setValue(col1[i]);
        ((SQLLongint) (template.getRow()[1])).setValue(col2[i]);
        ((SQLLongint) (template.getRow()[2])).setValue(col3[i]);
        base_row[3] = new SQLChar(string_1500char);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        // ")" + template);
        if (index_cc.insert(template.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    index_cc.checkConsistency();
    ((B2IController) index_cc).debugConglomerate();
    ret_val = t_desc_scan_test_cases(tc, index_conglomid, template);
    // may or may not clean these up.
    for (int i = d_col1.length - 1; i >= 0; i--) {
        ((SQLLongint) (template.getRow()[0])).setValue(d_col1[i]);
        ((SQLLongint) (template.getRow()[1])).setValue(d_col2[i]);
        ((SQLLongint) (template.getRow()[2])).setValue(d_col3[i]);
        base_row[3] = new SQLChar(string_1500char);
        base_cc.insertAndFetchLocation(base_row, row_loc);
        // ")" + template);
        if (index_cc.insert(template.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
        // now delete the row.
        base_cc.delete(row_loc);
        ScanController delete_scan = tc.openScan(index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, template.getRow(), ScanController.GE, null, template.getRow(), ScanController.GT);
        if (!delete_scan.next()) {
            throw T_Fail.testFailMsg("delete could not find key");
        } else {
            delete_scan.delete();
            if (delete_scan.next())
                throw T_Fail.testFailMsg("delete found more than one key");
        }
        delete_scan.close();
    }
    ret_val = t_desc_scan_test_cases(tc, index_conglomid, template);
    // Close the conglomerate.
    index_cc.close();
    tc.commit();
    REPORT("Ending t_017");
    return (ret_val);
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ColumnOrdering(org.apache.derby.iapi.store.access.ColumnOrdering) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLChar(org.apache.derby.iapi.types.SQLChar) Properties(java.util.Properties) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLLongint(org.apache.derby.iapi.types.SQLLongint) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

SQLChar (org.apache.derby.iapi.types.SQLChar)60 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)42 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)22 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)21 SQLVarchar (org.apache.derby.iapi.types.SQLVarchar)18 UUID (org.apache.derby.catalog.UUID)15 SQLLongint (org.apache.derby.iapi.types.SQLLongint)13 RawContainerHandle (org.apache.derby.iapi.store.raw.data.RawContainerHandle)12 RawTransaction (org.apache.derby.iapi.store.raw.xact.RawTransaction)12 RowLocation (org.apache.derby.iapi.types.RowLocation)10 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)9 TupleDescriptor (org.apache.derby.iapi.sql.dictionary.TupleDescriptor)8 StandardException (org.apache.derby.shared.common.error.StandardException)8 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)7 UserType (org.apache.derby.iapi.types.UserType)7 ScanController (org.apache.derby.iapi.store.access.ScanController)6 ArrayList (java.util.ArrayList)5 Properties (java.util.Properties)5 TableDescriptor (org.apache.derby.iapi.sql.dictionary.TableDescriptor)4 LinkedList (java.util.LinkedList)3