use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method createAConglom.
private long createAConglom(TransactionController tc, int testValue, boolean temporary) throws StandardException {
// Create a heap conglomerate.
long cid = tc.createConglomerate(// create a heap conglomerate
"heap", // 1 SQLInteger() column template.
new T_AccessRow(1).getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT);
ConglomerateController cc = tc.openConglomerate(cid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a row.
T_AccessRow row = new T_AccessRow(1);
SQLLongint col = new SQLLongint(testValue);
row.setCol(0, col);
// Stuff in the test value so we can recognize this conglom later.
cc.insert(row.getRowArray());
cc.close();
return cid;
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method positionAtRowLocation.
// test position at row location, in terms of holdability
protected boolean positionAtRowLocation(TransactionController tc) throws StandardException, T_Fail {
REPORT("(positionAtRowLocation)");
// Create a conglomerate with one row:
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);
T_AccessRow accessRow = null;
for (int i = 1; i < 5; i++) {
// Create a row.
accessRow = new T_AccessRow(1);
SQLLongint c1 = new SQLLongint(i);
accessRow.setCol(0, c1);
// Insert the row and remember its location.
cc.insert(accessRow.getRowArray());
}
tc.commit();
cc.close();
// Open scan on the table:
ScanController base_scan = tc.openScan(base_id, // do 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);
// Move to the first row
base_scan.next();
// Get the RowLocation for the first row:
RowLocation firstRow = base_scan.newRowLocationTemplate();
base_scan.fetchLocation(firstRow);
base_scan.fetch(accessRow.getRowArray());
long key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 0) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_1) 1st row is not 0 it is:" + key_value);
}
// Move to some other rows:
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 1) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_2) 2nd row is not 1 it is:" + key_value);
}
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 2) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_3) 3d row is not 2 it is:" + key_value);
}
if (!base_scan.positionAtRowLocation(firstRow)) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_4) Failed to position at RowLocation");
}
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 0) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_5) 1st row is not 0 it is:" + key_value);
}
// Commit and check holdability:
tc.commit();
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 1) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_6) 2nd row is not 1 it is:" + key_value);
}
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 2) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_7) 3d row is not 2 it is:" + key_value);
}
if (!base_scan.positionAtRowLocation(firstRow)) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_8) Failed to position at " + "RowLocation after commit");
}
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 0) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_9) 1st row is not 0 it is:" + key_value);
}
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 1) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_10) 2nd row is not 1 it is:" + key_value);
}
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 2) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_10) 3d row is not 2 it is:" + key_value);
}
// Using reopenScanByRowLocation(..)
// instead of positionAtRowLocation(..):
base_scan.reopenScanByRowLocation(firstRow, null);
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 0) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_11) 1st row is not 0 it is:" + key_value);
}
tc.commit();
// Compress the conglomerate
tc.compressConglomerate(base_id);
tc.commit();
base_scan.next();
base_scan.fetch(accessRow.getRowArray());
key_value = ((SQLLongint) accessRow.getCol(0)).getLong();
if (key_value != 1) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_12) 2nd row is not 1 it is:" + key_value);
}
// that they are holdable
if (base_scan.positionAtRowLocation(firstRow)) {
throw T_Fail.testFailMsg("(positionAtRowLocation_err_12) Unexpectedly succeeded at " + "positioning at RowLocation after compress");
}
base_scan.close();
REPORT("(positionAtRowLocation) succeeded");
return true;
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method transactionalProperties.
/**
* Test transactional properties
*
* @exception StandardException test failure
* @exception T_Fail test failure
*/
protected boolean transactionalProperties(TransactionController tc) throws StandardException, T_Fail {
REPORT("start transactionalProperties");
// put a couple of properties in with different values and types
tc.setProperty("T_Key_Frog", new SQLLongint(479), false);
tc.setProperty("T_Key_Tiger", "Roar, ROAR", false);
long lvalue = ((SQLLongint) (tc.getProperty("T_Key_Frog"))).getLong();
if (lvalue != 479)
throw T_Fail.testFailMsg("setProperty() - expected 479 - got " + lvalue);
String svalue = (String) tc.getProperty("T_Key_Tiger");
if (!svalue.equals("Roar, ROAR"))
throw T_Fail.testFailMsg("setProperty() - expected 'Roar, ROAR' - got " + svalue);
tc.commit();
// should still be accessable after the commit
lvalue = ((SQLLongint) (tc.getProperty("T_Key_Frog"))).getLong();
if (lvalue != 479)
throw T_Fail.testFailMsg("setProperty() - expected 479 - got " + lvalue);
svalue = (String) tc.getProperty("T_Key_Tiger");
if (!svalue.equals("Roar, ROAR"))
throw T_Fail.testFailMsg("setProperty() - expected 'Roar, ROAR' - got " + svalue);
tc.commit();
// see if update works
tc.setProperty("T_Key_Tiger", "mieow, mieow", false);
svalue = (String) tc.getProperty("T_Key_Tiger");
if (!svalue.equals("mieow, mieow"))
throw T_Fail.testFailMsg("setProperty() - expected 'mieow, mieow' - got " + svalue);
tc.commit();
svalue = (String) tc.getProperty("T_Key_Tiger");
if (!svalue.equals("mieow, mieow"))
throw T_Fail.testFailMsg("setProperty() - expected 'mieow, mieow' - got " + svalue);
// see if an update to a different type works
tc.setProperty("T_Key_Tiger", new SQLLongint(570), false);
lvalue = ((SQLLongint) (tc.getProperty("T_Key_Tiger"))).getLong();
if (lvalue != 570)
throw T_Fail.testFailMsg("setProperty() - expected 570 - got " + lvalue);
tc.commit();
lvalue = ((SQLLongint) (tc.getProperty("T_Key_Tiger"))).getLong();
if (lvalue != 570)
throw T_Fail.testFailMsg("setProperty() - expected 570 - got " + lvalue);
tc.commit();
// delete a key
tc.setProperty("T_Key_Frog", (Serializable) null, false);
if (tc.getProperty("T_Key_Frog") != null)
throw T_Fail.testFailMsg("setProperty() - delete failed");
tc.commit();
if (tc.getProperty("T_Key_Frog") != null)
throw T_Fail.testFailMsg("setProperty() - delete failed");
tc.commit();
// now see if rollback works.
tc.setProperty("T_Key_Tiger", new SQLLongint(457), false);
tc.abort();
lvalue = ((SQLLongint) (tc.getProperty("T_Key_Tiger"))).getLong();
if (lvalue != 570)
throw T_Fail.testFailMsg("setProperty() - expected 570 - got " + lvalue);
tc.commit();
PASS("transactionalProperties");
return true;
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_AccessFactory method getBtreeTemplate.
private DataValueDescriptor[] getBtreeTemplate(TransactionController tc, long baseConglomId) throws StandardException {
// 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, // all columns, all as objects
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);
sc.close();
return (template.getRowArray());
}
use of org.apache.derby.iapi.types.SQLLongint in project derby by apache.
the class T_QualifierTest method t_scanFetchNextGroup.
/**
* Test scan which does FetchNextGroup with all of the fields.
* <p>
*
* @return Whether the test succeeded or not.
*
* @exception StandardException Standard exception policy.
*/
public static boolean t_scanFetchNextGroup(TransactionController tc, int group_size, 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 == ORDER_FORWARD || order == ORDER_DESC);
if (!ordered) {
set = create_hash_set(input_expect_key, expect_numrows, order);
}
/**
********************************************************************
* Forward scan test case
**********************************************************************
*/
GroupFetchScanController scan = tc.openGroupFetchScan(conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op);
// create an array of "group_size" rows to use in the fetch group call.
DataValueDescriptor[][] row_array = new DataValueDescriptor[group_size][];
row_array[0] = TemplateRow.newRow(fetch_template);
int expect_key = input_expect_key;
long key = -42;
long numrows = 0;
int group_row_count = 0;
// loop asking for "group_size" rows at a time.
while ((group_row_count = scan.fetchNextGroup(row_array, (RowLocation[]) null)) != 0) {
// loop through the rows returned into the row_array.
for (int i = 0; i < group_row_count; i++) {
// see if we are getting the right keys.
key = ((SQLLongint) (row_array[i][2])).getLong();
if (ordered) {
if (key != expect_key) {
return (fail("(t_scanFetchNextGroup-forward) wrong key, expect (" + expect_key + ")" + "but got (" + key + "). num rows = " + numrows));
} else {
if (order == ORDER_DESC)
expect_key--;
else
expect_key++;
}
} else {
if (!set.remove(key)) {
return (fail("(t_scanFetchNextGroup-forward) wrong key, expected (" + expect_key + ")" + "but got (" + key + ")."));
}
}
numrows++;
}
}
scan.close();
if (numrows != expect_numrows) {
return (fail("(t_scanFetchNextGroup-forward) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows."));
}
return (true);
}
Aggregations