use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class T_QualifierTest method t_scanFetchNext.
/**
* Test scan which does FetchNext with all of the fields.
* <p>
* FetchNext() may be optimized by the underlying scan code to try and
* not do multiple fetches of the same row for the user, but if the user
* asks for one column, but the stop position depends on the whole row
* this optimization is not possible.
* <p>
*
* @return Whether the test succeeded or not.
*
* @exception StandardException Standard exception policy.
*/
public static boolean t_scanFetchNext(TransactionController tc, long conglomid, DataValueDescriptor[] init_scan_template, 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;
boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC);
if (!ordered) {
set = create_hash_set(input_expect_key, expect_numrows, order);
}
/**
********************************************************************
* Forward scan test case
**********************************************************************
*/
ScanController scan = tc.openScan(conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op);
int expect_key = input_expect_key;
long key = -42;
long numrows = 0;
while (scan.fetchNext(fetch_template)) {
scan.fetch(init_scan_template);
// make sure all columns from fetchNext() match subsequent fetch().
for (int i = 0; i < init_scan_template.length; i++) {
if ((fetch_template[i]).compare((init_scan_template[i])) != 0) {
return (fail("(t_scanFetchNext) wrong key, expected (" + fetch_template[i] + ")" + "but got (" + init_scan_template[i] + ")."));
}
}
// see if we are getting the right keys.
key = ((SQLLongint) (init_scan_template[2])).getLong();
if (ordered) {
if (key != expect_key) {
return (fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
} else {
if (order == ORDER_DESC)
expect_key--;
else
expect_key++;
}
} else {
if (!set.remove(key)) {
return (fail("(t_scanFetchNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
}
}
numrows++;
}
scan.close();
if (numrows != expect_numrows) {
return (fail("(t_scanFetchNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
}
return (true);
}
use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class T_CreateConglomRet method t_delete.
/**
* delete a single key, given key value. assumes 3 column table, first
* column = 1, second column is a unique key, and 3rd column is a
* RecordHandle into the base table.
*
* @exception StandardException Standard exception policy.
*/
protected boolean t_delete(TransactionController tc, long conglomid, DataValueDescriptor[] search_key, boolean useUpdateLocks) throws StandardException {
SQLLongint column0 = new SQLLongint(-1);
SQLLongint column1 = new SQLLongint(-1);
int openmode = TransactionController.OPENMODE_FORUPDATE;
if (useUpdateLocks) {
openmode |= TransactionController.OPENMODE_USE_UPDATE_LOCKS;
}
// open a new scan
ScanController scan = tc.openScan(conglomid, false, openmode, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, search_key, ScanController.GE, null, search_key, ScanController.GT);
long expect_key = ((SQLLongint) search_key[1]).getLong();
int numrows = 0;
DataValueDescriptor[] partialRow = new DataValueDescriptor[2];
partialRow[0] = column0;
partialRow[1] = column1;
while (scan.next()) {
numrows++;
scan.fetch(partialRow);
if (column0.getLong() != 1)
return (FAIL("(t_delete) column[0] value is not 1"));
if (column1.getLong() != expect_key)
return (FAIL("(t_delete) column[1] value is not " + expect_key));
if (!scan.delete()) {
return (FAIL("(t_delete): delete of row failed"));
}
if (scan.delete()) {
return (FAIL("(t_delete): re-delete of row succeeded"));
}
}
scan.close();
// This function expects unique keys, so scan should find single row.
if (numrows != 1) {
return (FAIL("(t_delete) wrong number of rows. Expected " + "1 row, but got " + numrows + "rows."));
}
return (true);
}
use of org.apache.derby.iapi.store.access.ScanController 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);
}
use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class T_CreateConglomRet method t_006.
/**
* Test unimplemented interfaces.
*
* The following ScanController interfaces are not supported by the
* btree implementation, because row locations are not returned outside
* the interface. At some point we may package a key as a row location
* but that does not really give any more functionality than using scan
* to find your key:
* ScanController.fetchLocation()
* ScanController.newRowLocationTemplate()
* ScanController.replace()
* ConglomerateController.delete()
* ConglomerateController.fetch()
* ConglomerateController.insertAndFetchLocation()
* ConglomerateController.newRowLocationTemplate()
* ConglomerateController.replace()
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Throws T_Fail on any test failure.
*/
protected boolean t_006(TransactionController tc) throws StandardException, T_Fail {
REPORT("Starting t_006");
T_CreateConglomRet create_ret = new T_CreateConglomRet();
createCongloms(tc, 2, false, false, 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 base row template.
DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
RowLocation base_rowloc = base_cc.newRowLocationTemplate();
T_SecondaryIndexRow index_row_from_base_row = new T_SecondaryIndexRow();
index_row_from_base_row.init(base_row, base_rowloc, 3);
((SQLLongint) base_row[0]).setValue(1);
// Create a row.
T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
index_row.init(TemplateRow.newU8Row(2), base_cc.newRowLocationTemplate(), 3);
// test: make sure scan position is right after inserts before scan
// no split case. In this case the slot position of the current
// position should change, but the code will keep a record handle
// and not need to reposition by key.
// before keys: 1000, 3000
// last key gotten froms scan : 0
// insert keys:1-900
// next key from scan should be: 5
// insert 1000
((SQLLongint) base_row[1]).setValue(1000);
base_cc.insertAndFetchLocation(base_row, base_rowloc);
if (index_cc.insert(index_row_from_base_row.getRow()) != 0) {
throw T_Fail.testFailMsg("insert failed");
}
// try each of the unsupported interfaces:
try {
index_cc.delete(null);
return (FAIL("t_006: ConglomerateController.delete() succeeded."));
} catch (StandardException e) {
}
try {
if (!index_cc.fetch(null, RowUtil.EMPTY_ROW, (FormatableBitSet) null)) {
return (FAIL("t_006: ConglomerateController.fetch() bad ret."));
}
return (FAIL("t_006: ConglomerateController.fetch() succeeded."));
} catch (StandardException e) {
}
try {
index_cc.insertAndFetchLocation((DataValueDescriptor[]) null, null);
return (FAIL("t_006: ConglomerateController.insertAndFetchLocation() succeeded."));
} catch (StandardException e) {
}
try {
RowLocation rowloc = index_cc.newRowLocationTemplate();
return (FAIL("t_006: ConglomerateController.newRowLocationTemplate() succeeded."));
} catch (StandardException e) {
}
try {
index_cc.replace(null, null, null);
return (FAIL("t_006: ConglomerateController.replace() succeeded."));
} catch (StandardException e) {
}
index_cc.close();
// open a new scan
ScanController scan = tc.openScan(create_ret.index_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, null, ScanController.NA, null, null, ScanController.NA);
int numrows = 0;
while (scan.next()) {
numrows++;
scan.fetch(index_row_from_base_row.getRow());
try {
scan.fetchLocation(null);
return (FAIL("t_006: scan.fetchLocation() succeeded"));
} catch (StandardException e) {
}
try {
RowLocation rowloc = scan.newRowLocationTemplate();
return (FAIL("t_006: scan.newRowLocationTemplate() succeeded"));
} catch (StandardException e) {
}
try {
scan.replace(index_row_from_base_row.getRow(), (FormatableBitSet) null);
return (FAIL("t_006: scan.replace() succeeded"));
} catch (StandardException e) {
}
}
// make sure that scan.next() continues to return false
if (scan.next())
return (FAIL("t_006: scan.next() returned true after false."));
scan.close();
if (numrows != 1) {
return (FAIL("(t_scan) wrong number of rows. Expected " + "1 row, but got " + numrows + "rows."));
}
REPORT("Ending t_006");
return (true);
}
use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class T_CreateConglomRet method t_scan.
/**
* Test a single scan.
*
* @exception StandardException Standard exception policy.
*/
protected boolean t_scan(TransactionController tc, long conglomid, DataValueDescriptor[] template, DataValueDescriptor[] start_key, int start_op, Qualifier[][] qualifier, DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int expect_key) throws StandardException {
// open a new scan
ScanController scan = tc.openScan(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op);
long key = -42;
long numrows = 0;
while (scan.next()) {
scan.fetch(template);
key = ((SQLLongint) template[2]).getLong();
if (key != expect_key) {
return (FAIL("(t_scan) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
} else {
expect_key++;
numrows++;
}
}
((B2IForwardScan) scan).checkConsistency();
scan.close();
if (numrows != expect_numrows) {
return (FAIL("(t_scan) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
}
return (true);
}
Aggregations