use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.
the class T_AccessFactory method deletetest.
// Insert a single row with a single column containing
// the first argument integer, delete it, make sure subsequent
// delete, replace, and replace a single column return false.
//
protected boolean deletetest(TransactionController tc, long conglomid, int value1, int value2) throws StandardException, T_Fail {
boolean ret_val;
// Open the conglomerate.
ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a row.
T_AccessRow r1 = new T_AccessRow(1);
r1.setCol(0, new SQLInteger(value1));
// Get a location template
RowLocation rowloc = cc.newRowLocationTemplate();
// Insert the row and remember its location.
cc.insertAndFetchLocation(r1.getRowArray(), rowloc);
// delete it.
if (!cc.delete(rowloc)) {
throw T_Fail.testFailMsg("(deleteTest) delete of row failed");
}
// subsequent replace, update a single column, and delete
// should return false
// update single column
DataValueDescriptor[] update_row = new DataValueDescriptor[1];
FormatableBitSet update_desc = new FormatableBitSet(1);
update_desc.set(0);
if (cc.replace(rowloc, update_row, update_desc)) {
throw T_Fail.testFailMsg("(deleteTest) partial column row replace returned true on del row");
}
// update whole row.
if (cc.replace(rowloc, r1.getRowArray(), (FormatableBitSet) null)) {
throw T_Fail.testFailMsg("(deleteTest) update returned true on del row");
}
if (cc.delete(rowloc)) {
throw T_Fail.testFailMsg("(deleteTest) delete returned true on del row");
}
// Close the conglomerate.
cc.close();
return true;
}
use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.
the class T_AccessFactory method sortCost.
/**
* Test the access level SortCost interface.
* <p>
*
* @return true if the test succeeded.
*
* @param tc The transaction controller to use in the test.
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Unexpected behaviour from the API
*/
protected boolean sortCost(TransactionController tc) throws StandardException, T_Fail {
int key_value;
REPORT("(sortCost) starting");
// Create a heap conglomerate.
T_AccessRow template_row = new T_AccessRow(2);
long conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", // 1 column template.
template_row.getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// Open the conglomerate.
ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a 2 column row.
T_AccessRow r1 = new T_AccessRow(2);
SQLInteger c1 = new SQLInteger(1);
SQLInteger c2 = new SQLInteger(100);
r1.setCol(0, c1);
r1.setCol(1, c2);
// Get a location template
RowLocation rowloc1 = cc.newRowLocationTemplate();
// Insert the row and remember its location.
cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);
cc.close();
tc.commit();
// flush the cache to get the row count updated.
flush_cache();
// Test 1 - Just call for various types of sorts. Not sure how
// to test the validity.
SortCostController scc = tc.openSortCostController();
double estimated_cost = scc.getSortCost(template_row.getRowArray(), null, false, 10000, 100, 100);
if (estimated_cost <= 0) {
throw T_Fail.testFailMsg("(storeCost) estimated sort cost :" + estimated_cost);
}
REPORT("(sortCost) finishing");
return true;
}
use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.
the class T_AccessFactory method updatelocks_0.
protected boolean updatelocks_0(TransactionController tc, int isolation_level) throws StandardException, T_Fail {
// Create a 2 column row.
T_AccessRow r1 = new T_AccessRow(2);
SQLInteger c1 = new SQLInteger(1);
SQLInteger c2 = new SQLInteger(100);
r1.setCol(0, c1);
r1.setCol(1, c2);
// Create a heap conglomerate.
long orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", r1.getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
// add rows 1 and 2
ConglomerateController cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// insert (1, 100)
r1.setCol(0, new SQLInteger(1));
r1.setCol(1, new SQLInteger(100));
cc.insert(r1.getRowArray());
// insert (2, 200)
r1.setCol(0, new SQLInteger(2));
r1.setCol(1, new SQLInteger(200));
cc.insert(r1.getRowArray());
// insert (3, 300)
r1.setCol(0, new SQLInteger(3));
r1.setCol(1, new SQLInteger(300));
cc.insert(r1.getRowArray());
cc.close();
tc.commit();
REPORT("(updatelocks ending.)");
ScanController sc = tc.openScan(orig_conglomid, // don't hold
false, (TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_USE_UPDATE_LOCKS), 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);
int key_value;
boolean found_row_2 = false;
while (sc.next()) {
sc.fetch(r1.getRowArray());
key_value = ((SQLInteger) r1.getCol(0)).getInt();
switch(key_value) {
case 1:
{
// delete first row
sc.delete();
break;
}
case 2:
{
// leave second alone - no update, lock will get coverted
// down.
found_row_2 = true;
break;
}
case 3:
{
// update the third row.
T_AccessRow update_row = new T_AccessRow(2);
r1.setCol(0, new SQLInteger(30));
r1.setCol(1, new SQLInteger(3000));
sc.replace(r1.getRowArray(), null);
break;
}
default:
{
throw T_Fail.testFailMsg("(updatelock) bad row value found in table.");
}
}
}
if (!found_row_2)
throw T_Fail.testFailMsg("(updatelock) did not find row in first scan.");
// reposition the scan
sc.reopenScan(// 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);
found_row_2 = false;
while (sc.next()) {
sc.fetch(r1.getRowArray());
key_value = ((SQLInteger) r1.getCol(0)).getInt();
switch(key_value) {
case 2:
{
// leave second alone - no update, lock will get coverted
// down.
found_row_2 = true;
break;
}
case 30:
{
// update the third row.
T_AccessRow update_row = new T_AccessRow(2);
r1.setCol(0, new SQLInteger(40));
r1.setCol(1, new SQLInteger(4000));
sc.replace(r1.getRowArray(), null);
break;
}
default:
{
throw T_Fail.testFailMsg("(updatelock) bad row value found in table.");
}
}
}
if (!found_row_2)
throw T_Fail.testFailMsg("(updatelock) did not find row in second scan.");
sc.close();
tc.commit();
// try the scan after the first xact has completed.
sc = tc.openScan(orig_conglomid, // don't hold
false, (TransactionController.OPENMODE_FORUPDATE | TransactionController.OPENMODE_USE_UPDATE_LOCKS), 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);
found_row_2 = false;
while (sc.next()) {
sc.fetch(r1.getRowArray());
key_value = ((SQLInteger) r1.getCol(0)).getInt();
switch(key_value) {
case 2:
{
// leave second alone - no update, lock will get coverted
// down.
found_row_2 = true;
break;
}
case 40:
{
// update the third row.
T_AccessRow update_row = new T_AccessRow(2);
r1.setCol(0, new SQLInteger(30));
r1.setCol(1, new SQLInteger(3000));
sc.replace(r1.getRowArray(), null);
break;
}
default:
{
throw T_Fail.testFailMsg("(updatelock) bad row value found in table.");
}
}
}
if (!found_row_2)
throw T_Fail.testFailMsg("(updatelock) did not find row in first scan.");
return (true);
}
use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.
the class T_AccessFactory method insert_bench.
// Simple insert into heap performance test
protected boolean insert_bench(TransactionController tc) throws StandardException, T_Fail {
ConglomerateController cc = null;
ScanController scan = null;
long conglomid = -1;
long before, after;
// Create a row.
T_AccessRow r1 = new T_AccessRow(1);
long iter = 100;
for (int numcols = 1; numcols < 101; numcols *= 10) {
// Create a heap conglomerate.
conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", // 1 SQLInteger() column template.
new T_AccessRow(numcols).getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
tc.commit();
// Open the conglomerate.
cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
for (int i = 0; i < numcols; i++) {
r1.setCol(i, new SQLInteger(numcols));
}
// time before
before = System.currentTimeMillis();
for (int i = 0; i < iter; i++) {
if (cc.insert(r1.getRowArray()) != 0)
throw T_Fail.testFailMsg("(insert_bench) insert failed ");
}
// time after
after = System.currentTimeMillis();
REPORT("insert " + iter + " rows of " + numcols + " integer cols = " + (after - before) + " milliseconds.\n");
// time before
before = System.currentTimeMillis();
for (int i = 0; i < iter; i++) {
if (cc.insert(r1.getRowArray()) != 0)
throw T_Fail.testFailMsg("(insert_bench) insert failed ");
}
// time after
after = System.currentTimeMillis();
REPORT("second insert " + iter + " rows of " + numcols + " integer cols = " + (after - before) + " milliseconds.\n");
// Open a scan on the conglomerate.
before = System.currentTimeMillis();
scan = 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);
// time before
before = System.currentTimeMillis();
// Iterate through and check that the rows are still there.
while (scan.next()) {
scan.fetch(r1.getRowArray());
}
// time after
after = System.currentTimeMillis();
REPORT("scan " + (2 * iter) + " rows of " + numcols + " integer cols = " + (after - before) + " milliseconds.\n");
// Close the conglomerate.
cc.close();
tc.commit();
}
return (true);
}
use of org.apache.derby.iapi.types.SQLInteger in project derby by apache.
the class T_AccessFactory method readUncommitted.
/**
* Test critical cases for read uncommitted.
* <p>
* test 1 - test heap fetch, delete and replace of row on page which does not exist.
* test 2 - test heap fetch, delete and replace of row on page where row does not exist.
*
* @exception StandardException Standard exception policy.
*/
protected boolean readUncommitted(TransactionController tc) throws StandardException, T_Fail {
REPORT("(readUncommitted)");
/*
* TEST 1 - test heap fetch of row on page which does not exist.
* <p>
* Do this by inserting a few pages worth of data and then deleting
* all the rows, while remembering the rowlocation of one of the pages.
* You need to at least get to the 2nd page, because the 1st page is
* never totally reclaimed and deleted by the system in a heap (it has
* some internal catalog information stored internally in row "0").
*/
String twok_string = new String("0123456789012345");
for (int i = 0; i < 7; i++) {
twok_string += twok_string;
}
T_AccessRow big_row = new T_AccessRow(2);
big_row.setCol(1, new SQLChar(twok_string));
// Create a heap conglomerate.
long orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", big_row.getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
ConglomerateController cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED);
for (int i = 0; i < 10; i++) {
big_row.setCol(0, new SQLInteger(i));
cc.insert(big_row.getRowArray());
}
cc.close();
// Open another scan on the conglomerate.
ScanController base_scan = tc.openScan(orig_conglomid, // 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);
// now delete all the rows and remember the row location of the
// last row.
RowLocation deleted_page_rowloc = base_scan.newRowLocationTemplate();
for (int i = 0; i < 10; i++) {
base_scan.next();
base_scan.fetchLocation(deleted_page_rowloc);
base_scan.delete();
tc.commit();
}
base_scan.close();
tc.commit();
// at this point the post commit thread should have reclaimed all the 5
// pages. Open it, at read uncommitted level.
cc = tc.openConglomerate(orig_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED);
// Test heap fetch of row on page which does not exist.
if (cc.fetch(deleted_page_rowloc, big_row.getRowArray(), null)) {
throw T_Fail.testFailMsg("(readUncommitted) fetch should ret false for reclaimed page.");
}
// Test heap replace of row on page which does not exist.
FormatableBitSet update_desc = new FormatableBitSet(1);
if (cc.replace(deleted_page_rowloc, big_row.getRowArray(), update_desc)) {
throw T_Fail.testFailMsg("(readUncommitted) delete should ret false for reclaimed page.");
}
// Test heap fetch (overloaded call) of row on page which does not exist.
if (cc.fetch(deleted_page_rowloc, big_row.getRowArray(), null, true)) {
throw T_Fail.testFailMsg("(readUncommitted) fetch should ret false for reclaimed page.");
}
// Test heap delete of row on page which does not exist.
if (cc.delete(deleted_page_rowloc)) {
throw T_Fail.testFailMsg("(readUncommitted) delete should ret false for reclaimed page.");
}
cc.close();
/*
* TEST 2 - test heap fetch of row on page where row does not exist.
* <p>
* Do this by inserting enough rows to put 1 row on the 2nd page.
* Then delete this one row, which will queue a post commit to reclaim
* the row and page. Then insert one more row on the same page in
* the same xact. Now commit the xact, which will cause post commit
* to run which will reclaim the row but not the page. Then try and
* fetch the row which was deleted.
*/
// string column will be 1500 bytes, allowing 2 rows per page to fit.
SQLChar stringcol = new SQLChar();
stringcol.setValue(T_AccessFactory.repeatString("012345678901234", 100));
big_row.setCol(1, stringcol);
// Create a heap conglomerate.
orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", big_row.getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED);
for (int i = 0; i < 3; i++) {
big_row.setCol(0, new SQLInteger(i));
cc.insert(big_row.getRowArray());
}
// Open another scan on the conglomerate.
base_scan = tc.openScan(orig_conglomid, // 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);
// now delete all the rows and remember the row location of the
// last row.
RowLocation deleted_row_rowloc = base_scan.newRowLocationTemplate();
for (int i = 0; i < 3; i++) {
base_scan.next();
base_scan.fetchLocation(deleted_row_rowloc);
base_scan.delete();
}
// insert another row on page 2 to make sure page does not go away.
cc.insert(big_row.getRowArray());
cc.close();
base_scan.close();
tc.commit();
// at this point the post commit thread should have reclaimed all the
// deleted row on page 2, but not the page.
//
// Open it, at read uncommitted level.
cc = tc.openConglomerate(orig_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED);
// test heap fetch of row on page where row does not exist.
if (cc.fetch(deleted_row_rowloc, big_row.getRowArray(), null)) {
throw T_Fail.testFailMsg("(readUncommitted) fetch should ret false for reclaimed row.");
}
// test heap replace of row on page where row does not exist.
if (cc.replace(deleted_page_rowloc, big_row.getRowArray(), update_desc)) {
throw T_Fail.testFailMsg("(readUncommitted) delete should ret false for reclaimed page.");
}
// test heap fetch (overloaded) of row on page where row does not exist.
if (cc.fetch(deleted_page_rowloc, big_row.getRowArray(), null, true)) {
throw T_Fail.testFailMsg("(readUncommitted) fetch should ret false for reclaimed page.");
}
// test heap delete of row on page where row does not exist.
if (cc.delete(deleted_page_rowloc)) {
throw T_Fail.testFailMsg("(readUncommitted) delete should ret false for reclaimed page.");
}
cc.close();
/*
* TEST 3 - test heap scan fetch of row on page prevents page from
* disappearing, but handles row being deleted.
* <p>
* A heap scan will maintain a scan lock on a page even if it is doing
* a read uncommitted scan. This will prevent the row/page from being
* reclaimed by post commit while the scan is positioned on the page.
* This presents no other concurrency issues for read uncommitted, it
* should be invisible to the user (deletes can still happen and the
* read uncommitted scanner will not block anyone).
*
* You need to at least get to the 2nd page, because the 1st page is
* never totally reclaimed and deleted by the system in a heap (it has
* some internal catalog information stored internally in row "0").
*/
big_row = new T_AccessRow(2);
big_row.setCol(1, new SQLChar(twok_string));
// Create a heap conglomerate.
orig_conglomid = tc.createConglomerate(// create a heap conglomerate
"heap", big_row.getRowArray(), // column sort order not required for heap
null, // default collation
null, // default properties
null, // not temporary
TransactionController.IS_DEFAULT);
cc = tc.openConglomerate(orig_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED);
for (int i = 0; i < 10; i++) {
big_row.setCol(0, new SQLInteger(i));
cc.insert(big_row.getRowArray());
}
cc.close();
// Open scan on the conglomerate, and position it on the second page.
base_scan = tc.openScan(orig_conglomid, // hold cursor open across commit
true, // for read
0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_READ_UNCOMMITTED, // 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);
base_scan.next();
base_scan.next();
base_scan.next();
if (!base_scan.doesCurrentPositionQualify())
throw T_Fail.testFailMsg("(readUncommitted) doesCurrentPositionQualify() failed.");
base_scan.fetch(big_row.getRowArray());
base_scan.fetchLocation(deleted_row_rowloc);
if (base_scan.isCurrentPositionDeleted())
throw T_Fail.testFailMsg("(readUncommitted) isCurrentPositionDeleted() failed.");
// Open another scan on the conglomerate.
ScanController delete_scan = tc.openScan(orig_conglomid, // 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);
for (int i = 0; i < 10; i++) {
delete_scan.next();
delete_scan.fetchLocation(deleted_page_rowloc);
delete_scan.delete();
}
delete_scan.close();
if (base_scan.doesCurrentPositionQualify())
throw T_Fail.testFailMsg("(readUncommitted) doesCurrentPositionQualify() failed.");
try {
base_scan.fetch(big_row.getRowArray());
throw T_Fail.testFailMsg("(readUncommitted) fetch of deleted row should throw exception.");
} catch (StandardException se) {
if (!se.getMessageId().equals(SQLState.AM_RECORD_NOT_FOUND)) {
throw T_Fail.testFailMsg("(readUncommitted) fetch of deleted row should throw SQLState.AM_RECORD_NOT_FOUND.");
}
}
base_scan.fetchLocation(deleted_row_rowloc);
if (!base_scan.isCurrentPositionDeleted())
throw T_Fail.testFailMsg("(readUncommitted) isCurrentPositionDeleted() failed.");
base_scan.close();
tc.commit();
REPORT("(readUncommitted) succeeded");
return true;
}
Aggregations