protected Collection flush(RowManager rowMgr,
PreparedStatementManager psMgr,
Collection exceps) {
RowManagerImpl rmimpl = (RowManagerImpl) rowMgr;
// first take care of all secondary table deletes and 'all row' deletes
// (which are probably secondary table deletes), since no foreign
// keys ever rely on secondary table pks
flush(rmimpl.getAllRowDeletes(), psMgr);
flush(rmimpl.getSecondaryDeletes(), psMgr);
// now do any 'all row' updates, which typically null keys
flush(rmimpl.getAllRowUpdates(), psMgr);
// gather any updates we need to avoid fk constraints on deletes
Collection constraintUpdates = null;
for (Iterator itr = rmimpl.getDeletes().iterator(); itr.hasNext();) {
try {
constraintUpdates = analyzeDeleteConstraints(rmimpl,
(PrimaryRow) itr.next(), constraintUpdates);
} catch (SQLException se) {
exceps = addException(exceps, SQLExceptions.getStore
(se, dict));
}
}
if (constraintUpdates != null) {
flush(constraintUpdates, psMgr);
constraintUpdates.clear();
}
// flush primary rows in order
for (Iterator itr = rmimpl.getOrdered().iterator(); itr.hasNext();) {
try {
constraintUpdates = flushPrimaryRow(rmimpl, (PrimaryRow)
itr.next(), psMgr, constraintUpdates);
} catch (SQLException se) {
exceps = addException(exceps, SQLExceptions.getStore
(se, dict));
}
}
if (constraintUpdates != null)
flush(constraintUpdates, psMgr);
// take care of all secondary table inserts and updates last, since
// they may rely on previous inserts or updates, but nothing relies
// on them
flush(rmimpl.getSecondaryUpdates(), psMgr);
// flush any left over prepared statements
psMgr.flush();
return exceps;
}
|