// first check for no action... bail out if no flattened processing is needed
if (relationship.getDeleteRule() == DeleteRule.NO_ACTION && !processFlattened) {
continue;
}
ArcProperty property = (ArcProperty) descriptor.getProperty(relationship
.getName());
Collection relatedObjects = toCollection(property.readProperty(object));
// no related object, bail out
if (relatedObjects.size() == 0) {
continue;
}
// process DENY rule first...
if (relationship.getDeleteRule() == DeleteRule.DENY) {
object.setPersistenceState(oldState);
String message = relatedObjects.size() == 1
? "1 related object"
: relatedObjects.size() + " related objects";
throw new DeleteDenyException(object, relationship.getName(), message);
}
// process flattened with dependent join tables...
// joins must be removed even if they are non-existent or ignored in the
// object graph
if (processFlattened) {
Iterator iterator = relatedObjects.iterator();
while (iterator.hasNext()) {
Persistent relatedObject = (Persistent) iterator.next();
context.getGraphManager().arcDeleted(object.getObjectId(), relatedObject
.getObjectId(), relationship.getName());
}
}
// process remaining rules
switch (relationship.getDeleteRule()) {
case DeleteRule.NO_ACTION:
break;
case DeleteRule.NULLIFY:
ArcProperty reverseArc = property.getComplimentaryReverseArc();
if (reverseArc == null) {
// nothing we can do here
break;
}
final Collection finalRelatedObjects = relatedObjects;
reverseArc.visit(new PropertyVisitor() {
public boolean visitAttribute(AttributeProperty property) {
return false;
}