session, row.getData(), data, c.core.mainCols) == 0) {
continue;
}
}
RowIterator refiterator = c.findFkRef(session, row.getData());
if (!refiterator.hasNext()) {
refiterator.release();
continue;
}
while (refiterator.hasNext()) {
Row refRow = refiterator.getNextRow();
Object[] refData = null;
/** @todo use MATCH */
if (c.core.refIndex.compareRowNonUnique(
session, refRow.getData(), row.getData(),
c.core.mainCols) != 0) {
break;
}
if (delete && refRow.getId() == row.getId()) {
continue;
}
switch (action) {
case SchemaObject.ReferentialAction.CASCADE : {
if (delete) {
boolean result;
try {
result = navigator.addRow(refRow);
} catch (HsqlException e) {
String[] info = getConstraintInfo(c);
refiterator.release();
throw Error.error(null, ErrorCode.X_27000,
ErrorCode.CONSTRAINT, info);
}
if (result) {
performReferentialActions(session,
c.core.refTable,
navigator, refRow,
null, null, path);
}
continue;
}
refData = c.core.refTable.getEmptyRowData();
System.arraycopy(refRow.getData(), 0, refData, 0,
refData.length);
for (int j = 0; j < c.core.refCols.length; j++) {
refData[c.core.refCols[j]] =
data[c.core.mainCols[j]];
}
break;
}
case SchemaObject.ReferentialAction.SET_NULL : {
refData = c.core.refTable.getEmptyRowData();
System.arraycopy(refRow.getData(), 0, refData, 0,
refData.length);
for (int j = 0; j < c.core.refCols.length; j++) {
refData[c.core.refCols[j]] = null;
}
break;
}
case SchemaObject.ReferentialAction.SET_DEFAULT : {
refData = c.core.refTable.getEmptyRowData();
System.arraycopy(refRow.getData(), 0, refData, 0,
refData.length);
for (int j = 0; j < c.core.refCols.length; j++) {
ColumnSchema col =
c.core.refTable.getColumn(c.core.refCols[j]);
refData[c.core.refCols[j]] =
col.getDefaultValue(session);
}
break;
}
case SchemaObject.ReferentialAction.NO_ACTION :
if (navigator.containsDeletedRow(refRow)) {
continue;
}
// fall through
case SchemaObject.ReferentialAction.RESTRICT : {
int errorCode = c.core.deleteAction
== SchemaObject.ReferentialAction
.NO_ACTION ? ErrorCode.X_23504
: ErrorCode.X_23001;
String[] info = getConstraintInfo(c);
refiterator.release();
throw Error.error(null, errorCode,
ErrorCode.CONSTRAINT, info);
}
default :
continue;
}
try {
refData =
navigator.addRow(session, refRow, refData,
c.core.refTable.getColumnTypes(),
c.core.refCols);
} catch (HsqlException e) {
String[] info = getConstraintInfo(c);
refiterator.release();
throw Error.error(null, ErrorCode.X_27000,
ErrorCode.CONSTRAINT, info);
}
if (refData == null) {
// happens only with enforceDeleteOrUpdate=false and updated row is already deleted
continue;
}
if (!path.add(c)) {
continue;
}
performReferentialActions(session, c.core.refTable, navigator,
refRow, refData, c.core.refCols,
path);
path.remove(c);
}
refiterator.release();
}
}