if (ec.getApiAdapter().isDetached(element)) // User passed in detached object to collection.remove()!
{
// Find an attached equivalent of this detached object (DON'T attach the object itself)
elementToRemove = ec.findObject(ec.getApiAdapter().getIdForObject(element), true, false, element.getClass().getName());
}
ObjectProvider elementSM = ec.findObjectProvider(elementToRemove);
Object oldOwner = null;
if (ownerFieldNumber >= 0)
{
if (!ec.getApiAdapter().isDeleted(elementToRemove))
{
// Find the existing owner if the record hasn't already been deleted
ec.getApiAdapter().isLoaded(elementSM, ownerFieldNumber);
oldOwner = elementSM.provideField(ownerFieldNumber);
}
}
else
{
// TODO Check if the element is managed by a different owner now
}
// Owner of the element has been changed
if (ownerFieldNumber >= 0 && oldOwner != ownerSM.getObject() && oldOwner != null)
{
return false;
}
boolean deleteElement = checkRemovalOfElementShouldDelete(ownerSM);
if (deleteElement)
{
if (ec.getApiAdapter().isPersistable(elementToRemove) && ec.getApiAdapter().isDeleted(elementToRemove))
{
// Element is waiting to be deleted so flush it (it has the FK)
elementSM.flush();
}
else
{
// Element not yet marked for deletion so go through the normal process
ec.deleteObjectInternal(elementToRemove);