📄 t_b2i.java
字号:
// |x = 5 and y > 2 |{5,2} |GT|{5} |GT|{5,4} .. {5,6}|{5,2} .. {9,1}| // +------------------------------------------------------------------+ REPORT("scan (x = 5 and y > 2)"); start_key = TemplateRow.newU8Row(2); stop_key = TemplateRow.newU8Row(1); ((SQLLongint)start_key[0]).setValue(5); ((SQLLongint)start_key[1]).setValue(2); ((SQLLongint)stop_key[0]).setValue(5); if (!T_QualifierTest.t_scan(tc, index_conglomid, template.getRow(), template.getRow(), start_key, ScanController.GT, null, stop_key, ScanController.GT, 2, 17, T_QualifierTest.ORDER_FORWARD)) { ret_val = false; } // +------------------------------------------------------------------+ // |pred |start|key|stop |key|rows returned|rows locked | // | |value|op |value|op | |(serialized) | // +-----------------+------+--+-----+--+--------------+--------------+ // |x = 5 and y >= 2 | {5,2}|GE| {5} |GT|{5,2} .. {5,6}|{4,6} .. {9,1}| // +------------------------------------------------------------------+ REPORT("scan (x = 5 and y >= 2)"); start_key = TemplateRow.newU8Row(2); stop_key = TemplateRow.newU8Row(1); ((SQLLongint)start_key[0]).setValue(5); ((SQLLongint)start_key[1]).setValue(2); ((SQLLongint)stop_key[0]).setValue(5); if (!T_QualifierTest.t_scan(tc, index_conglomid, template.getRow(), template.getRow(), start_key, ScanController.GE, null, stop_key, ScanController.GT, 3, 16, T_QualifierTest.ORDER_FORWARD)) { ret_val = false; } // +------------------------------------------------------------------+ // |pred |start|key|stop |key|rows returned|rows locked | // | |value|op |value|op | |(serialized) | // +-----------------+------+--+-----+--+--------------+--------------+ // |x = 5 and y < 5 | {5} |GE|{5,5}|GE|{5,2} .. {5,4}|{4,6} .. {5,4}| // +------------------------------------------------------------------+ REPORT("scan (x = 5 and y < 5)"); start_key = TemplateRow.newU8Row(1); stop_key = TemplateRow.newU8Row(2); ((SQLLongint)start_key[0]).setValue(5); ((SQLLongint)stop_key[0]).setValue(5); ((SQLLongint)stop_key[1]).setValue(5); if (!T_QualifierTest.t_scan(tc, index_conglomid, template.getRow(), template.getRow(), start_key, ScanController.GE, null, stop_key, ScanController.GE, 2, 16, T_QualifierTest.ORDER_FORWARD)) { ret_val = false; } // +------------------------------------------------------------------+ // |pred |start|key|stop |key|rows returned|rows locked | // | |value|op |value|op | |(serialized) | // +-----------------+------+--+-----+--+--------------+--------------+ // |x = 2 | {2} |GE| {2} |GT|none |{1,1} .. {1,1}| // +------------------------------------------------------------------+ REPORT("scan (x = 2)"); start_key = TemplateRow.newU8Row(1); stop_key = TemplateRow.newU8Row(1); ((SQLLongint)start_key[0]).setValue(2); ((SQLLongint)stop_key[0]).setValue(2); if (!T_QualifierTest.t_scan(tc, index_conglomid, template.getRow(), template.getRow(), start_key, ScanController.GE, null, stop_key, ScanController.GT, 0, 0, T_QualifierTest.ORDER_FORWARD)) { ret_val = false; } // +-----------------------------+ // |max on btree - row locked | // +-----------------------------+ // REPORT("max on btree, row locked."); if (!tc.fetchMaxOnBtree( index_conglomid, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, template.getRow())) { throw T_Fail.testFailMsg("found no max."); } else { // make sure right max was found. long key = ((SQLLongint) template.getRow()[2]).getLong(); if (key != 21) { throw T_Fail.testFailMsg("wrong max found."); } } // +-----------------------------+ // |max on btree - table locked | // +-----------------------------+ // REPORT("max on btree, table locked."); if (!tc.fetchMaxOnBtree( index_conglomid, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, template.getRow())) { throw T_Fail.testFailMsg("found no max."); } else { // make sure right max was found. long key = ((SQLLongint) template.getRow()[2]).getLong(); if (key != 21) { throw T_Fail.testFailMsg("wrong max found."); } } // +-----------------------------+ // |max on btree - row locked | // +-----------------------------+ // REPORT("max on btree, row locked."); if (!tc.fetchMaxOnBtree( index_conglomid, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_COMMITTED, (FormatableBitSet) null, template.getRow())) { throw T_Fail.testFailMsg("found no max."); } else { // make sure right max was found. long key = ((SQLLongint) template.getRow()[2]).getLong(); if (key != 21) { throw T_Fail.testFailMsg("wrong max found."); } } // +-----------------------------+ // |max on btree - table locked | // +-----------------------------+ // REPORT("max on btree, table locked."); if (!tc.fetchMaxOnBtree( index_conglomid, 0, TransactionController.MODE_TABLE, TransactionController.ISOLATION_READ_COMMITTED, (FormatableBitSet) null, template.getRow())) { throw T_Fail.testFailMsg("found no max."); } else { // make sure right max was found. long key = ((SQLLongint) template.getRow()[2]).getLong(); if (key != 21) { throw T_Fail.testFailMsg("wrong max found."); } } return(ret_val); } /** * 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( "heap", // create a heap conglomerate base_row, // base table template row null, //column sort order - not required for heap null, // default properties TransactionController.IS_DEFAULT); // not temporary // 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( null, // no current properties list false, // don't allow duplicates 5, // 4 columns in index row 5, // non-unique index true, // maintain parent links base_conglomid, // base conglom id 4); // row loc in last column long index_conglomid = tc.createConglomerate( "BTREE", // create a btree secondary index_row.getRow(), // row template null, //column sort order - default properties, // properties TransactionController.IS_DEFAULT); // not temporary // 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); // Insert the row. // System.out.println("Adding record (" + -(i - (col1.length -1)) + // ")" + 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); // insert and delete some interesting rows, deleted space management // 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); // Insert the row. // System.out.println("Adding record (" + -(i - (col1.length -1)) + // ")" + 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); } /** * Test qualifiers. * * @exception StandardException Standard exception policy. * @exception T_Fail Throws T_Fail on any test failure. */ protected boolean t_004(TransactionController tc) throws StandardException, T_Fail
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -