* </ul>
* @param sm StateManager of the owner
*/
public void postUpdate(StateManager sm)
{
ObjectManager om = sm.getObjectManager();
Collection value = (Collection) sm.provideField(mmd.getAbsoluteFieldNumber());
if (containerIsStoredInSingleColumn())
{
// Make sure the elements are ok for proceeding
SCOUtils.validateObjectsForWriting(om, value);
return;
}
if (value == null)
{
// remove any elements in the collection and replace it with an empty SCO wrapper
((CollectionStore) storeMgr.getBackingStoreForField(om.getClassLoaderResolver(), mmd, null)).clear(sm);
replaceFieldWithWrapper(sm, null, false, false);
return;
}
if (value instanceof SCOContainer)
{
// Already have a SCO value
SCOContainer sco = (SCOContainer) value;
if (sm.getObject() == sco.getOwner() && fieldName.equals(sco.getFieldName()))
{
// Flush any outstanding updates
sco.flush();
return;
}
if (sco.getOwner() != null)
{
throw new NucleusException(LOCALISER.msg("CollectionMapping.WrongOwnerError")).setFatal();
}
}
if (!mmd.isCascadeUpdate())
{
// TODO Should this throw exception if the element doesn't exist?
// User doesn't want to update by reachability
if (NucleusLogger.REACHABILITY.isDebugEnabled())
{
NucleusLogger.REACHABILITY.debug(LOCALISER.msg("007008", mmd.getFullFieldName()));
}
return;
}
if (NucleusLogger.REACHABILITY.isDebugEnabled())
{
NucleusLogger.REACHABILITY.debug(LOCALISER.msg("007009", mmd.getFullFieldName()));
}
CollectionStore backingStore = ((CollectionStore) storeMgr.getBackingStoreForField(
om.getClassLoaderResolver(), mmd, value.getClass()));
backingStore.update(sm, value);
// Replace the field with a wrapper containing these elements
replaceFieldWithWrapper(sm, value, false, false);
}