private boolean resolveCycles(Graph graph, Collection edges,
Collection deleteUpdates, Collection insertUpdates)
throws SQLException {
boolean recalculate = false;
for (Iterator itr = edges.iterator(); itr.hasNext();) {
Edge edge = (Edge) itr.next();
List cycle = edge.getCycle();
if (cycle != null) {
// find a nullable foreign key
Edge breakableLink = findBreakableLink(cycle);
if (breakableLink == null) {
throw new UserException(_loc.get("no-nullable-fk"));
}
// topologic node order must be re-calculated, if the
// breakable link is different from the edge where
// the circular dependency was originally detected
if (edge != breakableLink) {
recalculate = true;
}
if (!breakableLink.isRemovedFromGraph()) {
// use a primary row update to prevent setting pk and fk values
// until after flush, to get latest auto-increment values
PrimaryRow row = (PrimaryRow) breakableLink.getFrom();
if (row.getAction() == Row.ACTION_DELETE) {
addDeleteUpdate(breakableLink, deleteUpdates);
} else {
addInsertUpdate(row, breakableLink, insertUpdates);
}