* @param ownerSM The state manager
**/
public void clear(StateManager ownerSM)
{
boolean deleteElements = false;
ObjectManager om = ownerSM.getObjectManager();
if (ownerMemberMetaData.getCollection().isDependentElement())
{
// Elements are dependent and can't exist on their own, so delete them all
JPOXLogger.DATASTORE.debug(LOCALISER.msg("056034"));
deleteElements = true;
}
else
{
if (ownerMapping.isNullable() && orderMapping == null)
{
// Field is not dependent, and nullable so we null the FK
JPOXLogger.DATASTORE.debug(LOCALISER.msg("056036"));
deleteElements = false;
}
else if (ownerMapping.isNullable() && orderMapping != null && orderMapping.isNullable())
{
// Field is not dependent, and nullable so we null the FK
JPOXLogger.DATASTORE.debug(LOCALISER.msg("056036"));
deleteElements = false;
}
else
{
// Field is not dependent, and not nullable so we just delete the elements
JPOXLogger.DATASTORE.debug(LOCALISER.msg("056035"));
deleteElements = true;
}
}
if (deleteElements)
{
// Find elements present in the datastore and delete them one-by-one
Iterator elementsIter = iterator(ownerSM);
if (elementsIter != null)
{
while (elementsIter.hasNext())
{
Object element = elementsIter.next();
if (om.getApiAdapter().isPersistable(element) && om.getApiAdapter().isDeleted(element))
{
// Element is waiting to be deleted so flush it (it has the FK)
StateManager objSM = om.findStateManager(element);
objSM.flush();
}
else
{
// Element not yet marked for deletion so go through the normal process
om.deleteObjectInternal(element);
}
}
}
}
else