use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class T_RawStoreFactory method P031.
/**
* Insert 4-column long rows into 1K pages, each column is less than a page.
*
* @exception T_Fail Unexpected behaviour from the API
* @exception StandardException Unexpected exception from the implementation
*/
protected void P031(long segment) throws StandardException, T_Fail {
Transaction t = t_util.t_startTransaction();
long cid = t_util.t_addContainer(t, segment, 4096);
ContainerHandle c = t_util.t_openContainer(t, segment, cid, true);
Page page = t_util.t_getPage(c, ContainerHandle.FIRST_PAGE_NUMBER);
t_util.t_checkEmptyPage(page);
T_RawStoreRow r0 = new T_RawStoreRow(4);
r0.setColumn(0, 256, REC_001);
r0.setColumn(1, 256, REC_002);
r0.setColumn(2, 256, REC_003);
r0.setColumn(3, 256, REC_004);
int insertFlag = Page.INSERT_INITIAL;
insertFlag |= Page.INSERT_OVERFLOW;
RecordHandle rh0 = null;
try {
rh0 = t_util.t_insertAtSlot(page, 0, r0, (byte) insertFlag);
} catch (StandardException se) {
throw T_Fail.testFailMsg("insert of long row failed.");
}
if (rh0 == null)
throw T_Fail.testFailMsg("insert of first long row failed.");
else {
REPORT("about to check fetch...");
DataValueDescriptor column = new SQLChar();
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 0, column, false, REC_001, 256);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 1, column, false, REC_002, 256);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 2, column, false, REC_003, 256);
t_util.t_checkFetchColFromSlot(page, page.FIRST_SLOT_NUMBER, 3, column, false, REC_004, 256);
}
page.unlatch();
if (segment != ContainerHandle.TEMPORARY_SEGMENT) {
// cleanup
t_util.t_dropContainer(t, segment, cid);
}
t_util.t_commit(t);
t.close();
PASS("P031: segment = " + segment);
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class T_CreateConglomRet method t_012.
/**
* Test Special cases of split.
* <p>
* Testing: restartSplitFor() call in BranchControlRow().
*
* The second case is the same as the first except the calling code is
* trying to split a branch page and the parent branch page doesn't have
* room for the row.
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Throws T_Fail on any test failure.
*/
protected boolean t_012(TransactionController tc) throws StandardException, T_Fail {
boolean ret_val = true;
REPORT("Starting t_011");
T_CreateConglomRet create_ret = new T_CreateConglomRet();
createCongloms(tc, 2, false, true, 0, create_ret);
// Open the base conglomerate.
ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Open the index conglomerate.
ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a row.
T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
RowLocation rowloc = base_cc.newRowLocationTemplate();
DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
base_row[0] = new SQLChar("aaaaaaaaaa");
index_row.init(base_row, rowloc, 3);
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
((SQLLongint) base_row[1]).setValue(1);
base_cc.insertAndFetchLocation(base_row, rowloc);
// CAUSE BRANCH splitFor to loop:
// pick numbers so that split will happen in middle of page. Do this
// by first inserting last row in table and then insert smaller rows,
// then insert rows before it until the table is just ready to split
// the root, and finally insert some shorter rows in such a way as
// they cause a split but the split point is chosen with one of the
// larger rows as the descriminator causing 1st splitfor pass to fail
// and loop back and do a splitFor the larger row.
// insert enough rows so the tree is 3 levels, just ready to go to
// 4 levels.
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("ma", 500));
for (int i = 0; i < 3; i++) {
((SQLLongint) base_row[1]).setValue(i);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("m", 1000));
for (int i = 3; i < 23; i++) {
((SQLLongint) base_row[1]).setValue(i);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 600));
for (int i = 123; i > 111; i--) {
((SQLLongint) base_row[1]).setValue(i * 2);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
{
((SQLLongint) base_row[1]).setValue(227);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
// ((B2IController)index_cc).printTree();
tc.commit();
// Close the conglomerate.
index_cc.close();
REPORT("Ending t_012");
return (ret_val);
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class T_CreateConglomRet method t_011.
/**
* Test Special cases of split.
* <p>
* Testing: restartSplitFor() call in LeafControlRow().
*
* The first case is where we split
* down the tree and reach the leaf, pick a split point, and then find
* that there is not enough room to insert row into parent branch page.
*
* The second case is the same as the first except the calling code is
* trying to split a branch page and the parent branch page doesn't have
* room for the row.
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Throws T_Fail on any test failure.
*/
protected boolean t_011(TransactionController tc) throws StandardException, T_Fail {
boolean ret_val = true;
REPORT("Starting t_011");
T_CreateConglomRet create_ret = new T_CreateConglomRet();
createCongloms(tc, 2, false, true, 0, create_ret);
// Open the base conglomerate.
ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Open the index conglomerate.
ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a row.
T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
RowLocation rowloc = base_cc.newRowLocationTemplate();
DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
base_row[0] = new SQLChar("aaaaaaaaaa");
index_row.init(base_row, rowloc, 3);
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
((SQLLongint) base_row[1]).setValue(1);
base_cc.insertAndFetchLocation(base_row, rowloc);
// CAUSE LEAF splitFor to loop:
// pick numbers so that split will happen in middle of page. Do this
// by first inserting last row in table and then insert smaller rows,
// then insert rows before it until the table is just ready to split
// the root, and finally insert some shorter rows in such a way as
// they cause a split but the split point is chosen with one of the
// larger rows as the descriminator causing 1st splitfor pass to fail
// and loop back and do a splitFor the larger row.
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("m", 1000));
{
((SQLLongint) base_row[1]).setValue(0);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
// insert enough rows to make a 2 level btree where if another row
// with a 1000 byte string would cause a root split.
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
for (int i = 0; i < 5; i++) {
((SQLLongint) base_row[1]).setValue(i);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
// insert a shorter leaf row, such that it will fit in the root, but
// make the split point pick a longer row descriminator which won't
// fit in the root page.
((SQLChar) base_row[0]).setValue(T_b2i.repeatString("z", 500));
for (int i = 10; i > 8; i--) {
((SQLLongint) base_row[1]).setValue(i);
base_cc.insertAndFetchLocation(base_row, rowloc);
if (index_cc.insert(index_row.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
}
index_cc.checkConsistency();
// Close the conglomerate.
index_cc.close();
tc.dropConglomerate(create_ret.index_conglomid);
tc.dropConglomerate(create_ret.base_conglomid);
tc.abort();
REPORT("Ending t_011");
return (ret_val);
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class T_Recovery method R201.
/* recover test 201 */
protected void R201() throws T_Fail, StandardException {
long[] cid = new long[4];
cid[0] = find(key(201, 1));
if (cid[0] < 0) {
REPORT("R201 not run");
return;
}
cid[1] = find(key(201, 2));
cid[2] = find(key(201, 3));
cid[3] = find(key(201, 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);
t_util.t_checkRecordCount(page, 1, 0);
// record has the following fields: REC_001, REC_002, null
DataValueDescriptor column = new SQLChar();
t_util.t_checkFetchColFromSlot(page, 0, 0, column, false, REC_001);
t_util.t_checkFetchColFromSlot(page, 0, 1, column, false, REC_002);
t_util.t_checkFetchColFromSlot(page, 0, 2, column, false, null);
}
} finally {
t_util.t_commit(t);
t.close();
}
PASS("R201 passed: container1 " + cid[0] + " container2 " + cid[1] + " container3 " + cid[2] + " container4 " + cid[3]);
}
use of org.apache.derby.iapi.types.SQLChar in project derby by apache.
the class T_CreateConglomRet method t_018.
/**
* Test BTree.openScan(), BtreeScan.init(), BtreeScan.next(),
* BtreeScan.fetch() with alternating ascending and descending coulmn
* sort order indexes.
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Throws T_Fail on any test failure.
*/
protected boolean t_018(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_018");
// 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];
// Ascending
order[0] = new T_ColumnOrderingImpl(0, true);
// descending
order[1] = new T_ColumnOrderingImpl(1, false);
// Ascending
order[2] = new T_ColumnOrderingImpl(2, true);
// 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_ascdesc_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_ascdesc_scan_test_cases(tc, index_conglomid, template);
// Close the conglomerate.
index_cc.close();
tc.commit();
REPORT("Ending t_018");
return (ret_val);
}
Aggregations