use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.
the class T_CreateConglomRet method t_019.
/**
* 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_019(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_019");
// 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];
// Descending
order[0] = new T_ColumnOrderingImpl(0, false);
// Ascending
order[1] = new T_ColumnOrderingImpl(1, true);
// 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_ascdesc1_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_ascdesc1_scan_test_cases(tc, index_conglomid, template);
// Close the conglomerate.
index_cc.close();
tc.commit();
REPORT("Ending t_019");
return (ret_val);
}
use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.
the class T_CreateConglomRet method createCongloms.
/**
* Utility routine to create base table for tests.
* <p>
* A little utility routine to create base tables for tests. Just
* here to make tests a little more readable. It currently just
* creates a heap table with "num_cols" SQLLongint columns.
*
* @param num_cols the number of columns in the base table.
*
* @exception StandardException Standard exception policy.
*/
void createCongloms(TransactionController tc, int num_cols, boolean unique, boolean varying_first_col, int max_btreerows_per_page, T_CreateConglomRet ret_val) throws StandardException {
T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
DataValueDescriptor[] base_row = TemplateRow.newU8Row(num_cols);
if (varying_first_col) {
SQLChar string_col = new SQLChar();
base_row[0] = string_col;
}
long base_conglomid = 0;
// create the base table
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
RowLocation base_rowloc = base_cc.newRowLocationTemplate();
index_row.init(base_row, base_rowloc, num_cols + 1);
// create the secondary index
Properties properties = createProperties(// no current properties list
null, // don't allow duplicates
false, // index on all base row cols + row location
num_cols + 1, // non-unique index
(unique ? num_cols : num_cols + 1), // maintain parent links
true, // base conglomid
base_conglomid, // row loc in last column
num_cols);
if (max_btreerows_per_page > 1) {
if (BTree.PROPERTY_MAX_ROWS_PER_PAGE_PARAMETER != null) {
properties.put(BTree.PROPERTY_MAX_ROWS_PER_PAGE_PARAMETER, String.valueOf(max_btreerows_per_page));
}
}
long index_conglomid = tc.createConglomerate(// create a btree secondary
"BTREE", // index row template
index_row.getRow(), // column sort order - default
null, // default collation
null, // properties
properties, // not temporary
TransactionController.IS_DEFAULT);
// return values to caller
ret_val.base_conglomid = base_conglomid;
ret_val.index_conglomid = index_conglomid;
// RESOLVE (mikem - 04/29/98 - why is following line commented out?
// ret_val.base_template_row = TemplateRow.newU8Row(num_cols);
ret_val.index_template_row = index_row.getRow();
return;
}
use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.
the class T_CreateConglomRet method t_009.
/**
* Test unique/nonunique indexes - both positive and negative cases.
* <p>
*
* @exception StandardException Standard exception policy.
* @exception T_Fail Throws T_Fail on any test failure.
*/
protected boolean t_009(TransactionController tc) throws StandardException, T_Fail {
ScanController scan = null;
REPORT("Starting t_009");
// NON-UNIQUE INDEX
T_CreateConglomRet create_ret = new T_CreateConglomRet();
createCongloms(tc, 2, false, false, 2, create_ret);
// Open the base table
ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Open the secondary index
ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a row and insert into base table, remembering it's location.
DataValueDescriptor[] r1 = TemplateRow.newU8Row(2);
T_SecondaryIndexRow index_row1 = new T_SecondaryIndexRow();
RowLocation base_rowloc1 = base_cc.newRowLocationTemplate();
index_row1.init(r1, base_rowloc1, 3);
((SQLLongint) r1[0]).setValue(1);
((SQLLongint) r1[1]).setValue(1000);
// Insert the row into the base table;remember its location.
base_cc.insertAndFetchLocation(r1, base_rowloc1);
// Insert the row into the secondary index.
if (index_cc.insert(index_row1.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
if (index_cc.insert(index_row1.getRow()) != ConglomerateController.ROWISDUPLICATE) {
throw T_Fail.testFailMsg("insert of duplicate returned wrong return value:");
}
// Delete the only entry and make sure it can be reinserted in same
// xact.
DataValueDescriptor[] delete_key = TemplateRow.newU8Row(2);
((SQLLongint) delete_key[0]).setValue(1);
((SQLLongint) delete_key[1]).setValue(1000);
if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
throw T_Fail.testFailMsg("t_008: could not delete key.");
}
if (index_cc.insert(index_row1.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
tc.commit();
// UNIQUE INDEX
create_ret = new T_CreateConglomRet();
// Create the btree so that it only allows 2 rows per page.
createCongloms(tc, 2, true, false, 2, create_ret);
// Open the base table
base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Open the secondary index
index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
// Create a row and insert into base table, remembering it's location.
r1 = TemplateRow.newU8Row(2);
index_row1 = new T_SecondaryIndexRow();
base_rowloc1 = base_cc.newRowLocationTemplate();
index_row1.init(r1, base_rowloc1, 3);
((SQLLongint) r1[0]).setValue(1);
((SQLLongint) r1[1]).setValue(1000);
// Insert the row into the base table;remember its location.
base_cc.insertAndFetchLocation(r1, base_rowloc1);
// Insert the row into the secondary index.
if (index_cc.insert(index_row1.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
// Insert the row into the base table;remember its location.
base_cc.insertAndFetchLocation(r1, base_rowloc1);
// Insert the row into the secondary index.
if (index_cc.insert(index_row1.getRow()) != ConglomerateController.ROWISDUPLICATE) {
throw T_Fail.testFailMsg("insert of duplicate returned wrong return value:");
}
// Delete the only entry and make sure it can be reinserted in same
// xact.
delete_key = TemplateRow.newU8Row(2);
((SQLLongint) delete_key[0]).setValue(1);
((SQLLongint) delete_key[1]).setValue(1000);
if (!t_delete(tc, create_ret.index_conglomid, delete_key, false)) {
throw T_Fail.testFailMsg("t_008: could not delete key.");
}
if (index_cc.insert(index_row1.getRow()) != 0)
throw T_Fail.testFailMsg("insert failed");
REPORT("Ending t_009");
return (true);
}
use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.
the class RAMTransaction method closeControllers.
/**
************************************************************************
* Private/Protected methods of This class:
**************************************************************************
*/
// XXX (nat) currently closes all controllers.
protected void closeControllers(boolean closeHeldControllers) throws StandardException {
if (!scanControllers.isEmpty()) {
// loop from end to beginning, removing scans which are not held.
for (int i = scanControllers.size() - 1; i >= 0; i--) {
ScanManager sc = scanControllers.get(i);
if (sc.closeForEndTransaction(closeHeldControllers)) {
// TODO - now counting on scan's removing themselves by
// calling the closeMe() method.
/* scanControllers.removeElementAt(i); */
}
}
if (closeHeldControllers) {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(scanControllers.isEmpty());
}
// just to make sure everything has been closed and removed.
scanControllers.clear();
}
}
if (!conglomerateControllers.isEmpty()) {
// loop from end to beginning, removing scans which are not held.
for (int i = conglomerateControllers.size() - 1; i >= 0; i--) {
ConglomerateController cc = conglomerateControllers.get(i);
if (cc.closeForEndTransaction(closeHeldControllers)) {
// TODO - now counting on cc's removing themselves by
// calling the closeMe() method.
/* conglomerateControllers.removeElementAt(i); */
}
}
if (closeHeldControllers) {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(scanControllers.isEmpty());
}
// just to make sure everything has been closed and removed.
conglomerateControllers.clear();
}
}
if ((sortControllers != null) && !sortControllers.isEmpty()) {
if (closeHeldControllers) {
// element from the list.
for (int i = sortControllers.size() - 1; i >= 0; i--) {
SortController sc = sortControllers.get(i);
sc.completedInserts();
}
sortControllers.clear();
}
}
if ((sorts != null) && (!sorts.isEmpty())) {
if (closeHeldControllers) {
// element from the list.
for (int i = sorts.size() - 1; i >= 0; i--) {
Sort sort = sorts.get(i);
if (sort != null)
sort.drop(this);
}
sorts.clear();
freeSortIds.clear();
}
}
}
use of org.apache.derby.iapi.store.access.ConglomerateController in project derby by apache.
the class RAMTransaction method debugOpened.
/**
* Return a string with debug information about opened congloms/scans/sorts.
* <p>
* Return a string with debugging information about current opened
* congloms/scans/sorts which have not been close()'d.
* Calls to this routine are only valid under code which is conditional
* on SanityManager.DEBUG.
* <p>
*
* @return String with debugging information.
*
* @exception StandardException Standard exception policy.
*/
public String debugOpened() throws StandardException {
String str = null;
if (SanityManager.DEBUG) {
str = "";
for (Iterator<ScanManager> it = scanControllers.iterator(); it.hasNext(); ) {
ScanController sc = it.next();
str += "open scan controller: " + sc + "\n";
}
for (Iterator<ConglomerateController> it = conglomerateControllers.iterator(); it.hasNext(); ) {
ConglomerateController cc = (ConglomerateController) it.next();
str += "open conglomerate controller: " + cc + "\n";
}
if (sortControllers != null) {
for (Iterator<SortController> it = sortControllers.iterator(); it.hasNext(); ) {
SortController sc = it.next();
str += "open sort controller: " + sc + "\n";
}
}
if (sorts != null) {
for (int i = 0; i < sorts.size(); i++) {
Sort sort = sorts.get(i);
if (sort != null) {
str += "sorts created by createSort() in current xact:" + sort + "\n";
}
}
}
if (tempCongloms != null) {
for (Iterator<Long> it = tempCongloms.keySet().iterator(); it.hasNext(); ) {
Long conglomId = it.next();
Conglomerate c = tempCongloms.get(conglomId);
str += "temp conglomerate id = " + conglomId + ": " + c;
}
}
}
return (str);
}
Aggregations