use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class BranchControlRow method getLeftChildPageno.
/**
** Return the left child page number for the page. Leaf pages
** don't have left children, so they override this and return
** null.
*/
long getLeftChildPageno() throws StandardException {
if (this.left_child_page == null) {
this.left_child_page = new SQLLongint();
scratch_row[CR_LEFTCHILD] = this.left_child_page;
fetchDesc.setValidColumns(CR_LEFTCHILD_BITMAP);
this.page.fetchFromSlot((RecordHandle) null, CR_SLOT, scratch_row, fetchDesc, false);
}
return (left_child_page.getLong());
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method checkAConglom.
/**
* Open a scan on the conglomerate for the given conglom id, and verify
* that it has rows with the given test value. This is a way of
* verifying that we got the right conglomerate. Returns the number of
* rows that it checked (-1 if the conglomerate doesn't exist).
*/
private int checkAConglom(TransactionController tc, DataValueDescriptor[] scratch_template, long conglomId, int testValue) throws StandardException {
if (!tc.conglomerateExists(conglomId))
return -1;
ScanController sc = tc.openScan(conglomId, // don't hold
false, // not for update
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
// An empty row
T_AccessRow row = new T_AccessRow(1);
SQLLongint col = new SQLLongint(0);
row.setCol(0, col);
// Iterate through and check that the rows are still there.
// Note this part of the test will inten
int nrows = 0;
while (sc.next()) {
sc.fetch(row.getRowArray());
if (((SQLLongint) row.getCol(0)).getLong() != testValue)
return -2;
nrows++;
}
sc.close();
return nrows;
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method holdCursor.
// test various flavors of commit
protected boolean holdCursor(TransactionController tc) throws StandardException, T_Fail {
REPORT("(holdCursor)");
// Create a conglomerates and an index on that conglomerate.
long base_id = createAConglom(tc, 0, false);
// Open it.
ConglomerateController cc = tc.openConglomerate(base_id, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// insert 5 rows
T_AccessRow r1 = null;
SQLLongint c1 = null;
for (int i = 1; i < 5; i++) {
// Create a row.
r1 = new T_AccessRow(1);
c1 = new SQLLongint(i);
r1.setCol(0, c1);
// Get a location template
RowLocation rowloc = cc.newRowLocationTemplate();
// Insert the row and remember its location.
cc.insertAndFetchLocation(r1.getRowArray(), rowloc);
}
// Create an index on the base table.
long index_id = createBtree(tc, base_id, false);
tc.commit();
cc.close();
tc.commit();
// HEAP - test that scan is closed on commit of non-held cursor.
// Open scan on the base table.
ScanController base_scan = tc.openScan(base_id, // don't hold
false, // for update
TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
// Open scan on the index table.
ScanController index_scan = tc.openScan(index_id, // don't hold
false, // for update
TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
testOpsBeforeFirstNext(base_scan, r1.getRowArray());
testOpsBeforeFirstNext(index_scan, r1.getRowArray());
base_scan.next();
index_scan.next();
base_scan.next();
index_scan.next();
base_scan.next();
index_scan.next();
base_scan.next();
index_scan.next();
base_scan.next();
index_scan.next();
base_scan.next();
index_scan.next();
base_scan.next();
index_scan.next();
// should be able call get and set even after next'ing through the rows.
long row_count = base_scan.getEstimatedRowCount();
base_scan.setEstimatedRowCount(10);
row_count = base_scan.getEstimatedRowCount();
// should be able call get and set even after next'ing through the rows.
row_count = index_scan.getEstimatedRowCount();
index_scan.setEstimatedRowCount(10);
row_count = index_scan.getEstimatedRowCount();
if (row_count != 10)
throw T_Fail.testFailMsg("(holdCursor) some problem with get/set row count.");
tc.commit();
testOpsBeforeFirstNext(base_scan, r1.getRowArray());
testOpsBeforeFirstNext(index_scan, r1.getRowArray());
// see if commit closed the base_scan.
if (base_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should return false, commit should close base_scan.");
// see if commit closed the base_scan.
if (index_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should return false, commit should close base_scan.");
tc.commit();
// Open another scan on the conglomerate.
base_scan = tc.openScan(base_id, // hold cursor open across commit
true, // for update
TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
// Open scan on the index table.
index_scan = tc.openScan(index_id, // don't hold
true, // for update
TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
(FormatableBitSet) null, // start position - first row in conglomerate
null, // unused if start position is null.
0, // qualifier - accept all rows
null, // stop position - last row in conglomerate
null, // unused if stop position is null.
0);
tc.commit();
testOpsBeforeFirstNext(base_scan, r1.getRowArray());
testOpsBeforeFirstNext(index_scan, r1.getRowArray());
// move cursor to be positioned on 0
if (!base_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should not fail, commit should close hold scan.");
// move cursor to be positioned on 0
if (!index_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should not fail, commit should close hold scan.");
// the 1st next should return the 1st row - ie. 0
base_scan.fetch(r1.getRowArray());
long key_value = ((SQLLongint) r1.getCol(0)).getLong();
if (key_value != 0)
throw T_Fail.testFailMsg("(holdCursor) 1st row is not 0.");
index_scan.fetch(r1.getRowArray());
key_value = ((SQLLongint) r1.getCol(0)).getLong();
if (key_value != 0)
throw T_Fail.testFailMsg("(holdCursor) 1st row is not 0.");
// move cursor to be positioned on 1
base_scan.next();
index_scan.next();
tc.commit();
testOpsBeforeFirstNext(base_scan, r1.getRowArray());
testOpsBeforeFirstNext(index_scan, r1.getRowArray());
// should be able call get and set even after next'ing through the rows.
row_count = base_scan.getEstimatedRowCount();
base_scan.setEstimatedRowCount(5);
row_count = base_scan.getEstimatedRowCount();
// should be able call get and set even after next'ing through the rows.
row_count = index_scan.getEstimatedRowCount();
index_scan.setEstimatedRowCount(5);
row_count = index_scan.getEstimatedRowCount();
if (row_count != 5)
throw T_Fail.testFailMsg("(holdCursor) some problem with get/set row count.");
// move cursor to be positioned on 2
if (!base_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should not fail, commit should close hold base_scan.");
if (!index_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should not fail, commit should close hold base_scan.");
// the 1st next should return the 1st row - ie. 0
base_scan.fetch(r1.getRowArray());
key_value = ((SQLLongint) r1.getCol(0)).getLong();
if (key_value != 2)
throw T_Fail.testFailMsg("(holdCursor) 1st row is not 0.");
index_scan.fetch(r1.getRowArray());
key_value = ((SQLLongint) r1.getCol(0)).getLong();
if (key_value != 2)
throw T_Fail.testFailMsg("(holdCursor) 1st row is not 0.");
// move cursor to be positioned on 3
base_scan.next();
base_scan.delete();
index_scan.next();
index_scan.delete();
// move cursor to be positioned on 4
base_scan.next();
index_scan.next();
// move cursor past the end, thus closing it.
base_scan.next();
index_scan.next();
tc.commit();
// should be able call get and set even after next'ing through the rows.
row_count = base_scan.getEstimatedRowCount();
base_scan.setEstimatedRowCount(15);
row_count = base_scan.getEstimatedRowCount();
if (row_count != 15)
throw T_Fail.testFailMsg("(holdCursor) some problem with get/set row count.");
row_count = index_scan.getEstimatedRowCount();
index_scan.setEstimatedRowCount(15);
row_count = index_scan.getEstimatedRowCount();
if (row_count != 15)
throw T_Fail.testFailMsg("(holdCursor) some problem with get/set row count.");
testOpsBeforeFirstNext(base_scan, r1.getRowArray());
testOpsBeforeFirstNext(index_scan, r1.getRowArray());
if (base_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should fail, the base_scan has been closed by progressing to end.");
if (index_scan.next())
throw T_Fail.testFailMsg("(holdCursor) next() should fail, the base_scan has been closed by progressing to end.");
tc.commit();
base_scan.close();
index_scan.close();
REPORT("(holdCursor) succeeded");
return true;
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method createBtree.
private long createBtree(TransactionController tc, long baseConglomId, boolean temporary) throws StandardException {
// Create the properties for the index.
// This method knows that there is just one column in the base table
Properties indexProps = new Properties();
indexProps.put("baseConglomerateId", Long.toString(baseConglomId));
indexProps.put("nUniqueColumns", "1");
indexProps.put("rowLocationColumn", "1");
indexProps.put("nKeyFields", "2");
// 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, // just the first column.
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);
DataValueDescriptor[] baseRow = new DataValueDescriptor[1];
baseRow[0] = col0;
// Create a btree secondary index conglomerate.
long iid = tc.createConglomerate("BTREE", template.getRowArray(), null, // default collation
null, indexProps, temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT);
// Open the index so we can stuff in index rows.
ConglomerateController cc = tc.openConglomerate(iid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// build the index.
while (sc.next()) {
sc.fetch(baseRow);
sc.fetchLocation(col1);
cc.insert(template.getRowArray());
}
cc.close();
return iid;
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_QualifierTest method t_scanNext.
private static boolean t_scanNext(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;
boolean ordered = (order == T_QualifierTest.ORDER_FORWARD || order == T_QualifierTest.ORDER_DESC);
int expect_key = input_expect_key;
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);
long key = -42;
int numrows = 0;
while (scan.next()) {
scan.fetch(fetch_template);
key = ((SQLLongint) (fetch_template[2])).getLong();
if (ordered) {
if (key != expect_key) {
return (fail("(t_scanNext) 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_scanNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
}
}
numrows++;
}
scan.close();
if (numrows != expect_numrows) {
return (fail("(t_scanNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
}
return (true);
}
Aggregations