use of org.apache.derby.iapi.store.access.ScanController 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.ScanController 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);
}
use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class CacheLock method readProperty.
private Serializable readProperty(TransactionController tc, String key) throws StandardException {
// scan the table for a row with matching "key"
ScanController scan = openScan(tc, key, 0);
DataValueDescriptor[] row = makeNewTemplate();
// did we find at least one row?
boolean isThere = scan.fetchNext(row);
scan.close();
if (!isThere)
return null;
return (Serializable) (((UserType) row[1]).getObject());
}
use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class CacheLock method readDbProperties.
/**
* Read the database properties and add in the service set.
*/
private Dictionary<String, Object> readDbProperties(TransactionController tc) throws StandardException {
Dictionary<String, Object> set = new Hashtable<String, Object>();
// scan the table for a row with no matching "key"
ScanController scan = openScan(tc, (String) null, 0);
DataValueDescriptor[] row = makeNewTemplate();
while (scan.fetchNext(row)) {
Object key = ((UserType) row[0]).getObject();
Object value = ((UserType) row[1]).getObject();
if (SanityManager.DEBUG) {
if (!(key instanceof String))
SanityManager.THROWASSERT("Key is not a string " + key.getClass().getName());
}
set.put((String) key, value);
}
scan.close();
// add the known properties from the service properties set
String[] servicePropertyList = PropertyUtil.getServicePropertyList();
for (int i = 0; i < servicePropertyList.length; i++) {
String value = serviceProperties.getProperty(servicePropertyList[i]);
if (value != null)
set.put(servicePropertyList[i], value);
}
return set;
}
use of org.apache.derby.iapi.store.access.ScanController in project derby by apache.
the class ForeignKeyRIChecker method doCheck.
/**
* Check that the row either has a null column(s), or
* corresponds to a row in the referenced key.
* <p>
* If the referenced key is found, then it is locked
* when this method returns. The lock is held until
* the next call to doCheck() or close().
*
* @param a the activation
* @param row the row to check
* @param restrictCheckOnly
* {@code true} if the check is relevant only for RESTRICTED
* referential action.
* @param deferredRowReq
* dummy (interface obligation only)
*
* @exception StandardException on unexpected error, or
* on a foreign key violation
*/
void doCheck(Activation a, ExecRow row, boolean restrictCheckOnly, int deferredRowReq) throws StandardException {
if (// RESTRICT rule checks are not valid here.
restrictCheckOnly)
return;
/*
** If any of the columns are null, then the
** check always succeeds.
*/
if (isAnyFieldNull(row)) {
return;
}
/*
** Otherwise, we had better find this row in the
** referenced key
*/
ScanController scan = getScanController(fkInfo.refConglomNumber, refScoci, refDcoci, row);
if (!scan.next()) {
final UUID fkId = fkInfo.fkIds[0];
close();
if (fkInfo.deferrable[0] && lcc.isEffectivelyDeferred(lcc.getCurrentSQLSessionContext(a), fkId)) {
deferredRowsHashTable = DeferredConstraintsMemory.rememberFKViolation(lcc, deferredRowsHashTable, fkInfo.fkIds[0], indexQualifierRow.getRowArray(), fkInfo.schemaName, fkInfo.tableName);
} else {
StandardException se = StandardException.newException(SQLState.LANG_FK_VIOLATION, fkInfo.fkConstraintNames[0], fkInfo.tableName, StatementUtil.typeName(fkInfo.stmtType), RowUtil.toString(row, fkInfo.colArray));
throw se;
}
}
/*
** If we found the row, we are currently positioned on
** the row when we leave this method. So we hold the
** lock on the referenced key, which is very important.
*/
}
Aggregations