Object obj = ec.findObject(api.getIdForObject(object), true, false, object.getClass().getName());
if (obj != null)
{
// PM.getObjectById creates a dummy object to represent this object and automatically
// enlists it in the txn. Evict it to avoid issues with reachability
ObjectProvider objSM = ec.findObjectProvider(obj);
if (objSM != null)
{
ec.evictFromTransaction(objSM);
}
}
exists = true;
}
catch (NucleusObjectNotFoundException onfe)
{
exists = false;
}
}
}
if (!exists)
{
// Persist the object
ec.persistObjectInternal(object, fieldValues, ObjectProvider.PC);
persisted = true;
}
}
else
{
// Persistent, but is it flushed to the datastore?
ObjectProvider objectSM = ec.findObjectProvider(object);
if (objectSM.isWaitingToBeFlushedToDatastore())
{
// Newly persistent but still not flushed (e.g in optimistic txn)
// Process any fieldValues
if (fieldValues != null)
{
objectSM.loadFieldValues(fieldValues);
}
// Now flush it
objectSM.flush();
}
}
}
return persisted;
}