{
StateManager stateManager = owner.jdoGetStateManager();
if (stateManager != null)
{
PersistenceManager pm = (PersistenceManager) stateManager.getPersistenceManagerInternal();
pm.acquireShareLock();
boolean modified = false;
try
{
pm.acquireFieldUpdateLock();
try
{
// Mark the field as dirty
stateManager.makeDirty(fieldName);
modified = super.add(o);
if (modified)
{
if (removed.remove(o) == false)
{
added.add(o);
}
stateManager.applyUpdates(fieldName, this);
}
return modified;
}
finally
{
pm.releaseFieldUpdateLock();
}
}
catch (JDOUserException e)
{
Object[] failedObjects = e.getFailedObjectArray();
if (modified && (failedObjects != null))
{
//
// The failedObjects array may contain objects other
// than the one added. We iterate through it to find
// the one added and remove it from the collection.
//
for (int i = 0; i < failedObjects.length; i++)
{
Object failedObject = failedObjects[i];
if (failedObject == o)
{
super.remove(failedObject);
break;
}
}
}
throw e;
}
finally
{
pm.releaseShareLock();
}
}
}
return super.add(o);