// TransientTransactional : persist it
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
}
StateManager sm = findStateManager(obj);
if (sm == null)
{
throw new NucleusUserException(LOCALISER.msg("010007", getApiAdapter().getIdForObject(obj)));
}
sm.makePersistentTransactionalTransient();
}
else if (!api.isPersistent(obj))
{
// Transient : persist it
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
}
boolean merged = false;
ThreadContextInfo threadInfo = acquireThreadContextInfo();
try
{
if (threadInfo.merging)
{
AbstractClassMetaData cmd = getMetaDataManager().getMetaDataForClass(obj.getClass(), clr);
if (cmd.getIdentityType() == IdentityType.APPLICATION)
{
Object transientId = api.getNewApplicationIdentityObjectId(obj, cmd);
Object existingObj = findObject(transientId, true, true, cmd.getFullClassName());
ObjectProvider existingOP = findObjectProvider(existingObj);
((StateManager)existingOP).attach(obj);
id = transientId;
merged = true;
persistedPc = existingObj;
}
}
}
catch (NucleusObjectNotFoundException onfe)
{
// Object with this id doesn't exist, so just persist the transient (below)
}
finally
{
releaseThreadContextInfo();
}
if (!merged)
{
StateManager sm = findStateManager(obj);
if (sm == null)
{
if ((objectType == ObjectProvider.EMBEDDED_COLLECTION_ELEMENT_PC ||
objectType == ObjectProvider.EMBEDDED_MAP_KEY_PC ||
objectType == ObjectProvider.EMBEDDED_MAP_VALUE_PC ||
objectType == ObjectProvider.EMBEDDED_PC) && ownerOP != null)
{
// SCO object
sm = (StateManager) ObjectProviderFactory.newForEmbedded(this, obj, false, ownerOP, ownerFieldNum);
sm.setPcObjectType((short) objectType);
sm.makePersistent();
id = sm.getInternalObjectId();
}
else
{
// FCO object
sm = (StateManager) ObjectProviderFactory.newForPersistentNew(this, obj, preInsertChanges);
sm.makePersistent();
id = sm.getInternalObjectId();
}
}
else
{
if (sm.getReferencedPC() == null)
{
// Persist it
sm.makePersistent();
id = sm.getInternalObjectId();
}
else
{
// Being attached, so use the attached object
persistedPc = sm.getReferencedPC();
}
}
}
}
else if (api.isPersistent(obj) && api.getIdForObject(obj) == null)
{
// Embedded/Serialised : have SM but no identity, allow persist in own right
// Should we be making a copy of the object here ?
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
}
StateManager sm = findStateManager(obj);
sm.makePersistent();
id = sm.getInternalObjectId();
}
else if (api.isDeleted(obj))
{
// Deleted : (re)-persist it (permitted in JPA, but not JDO - see StateManager)
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
}
StateManager sm = findStateManager(obj);
sm.makePersistent();
id = sm.getInternalObjectId();
}
else
{
if (api.isPersistent(obj) && api.isTransactional(obj) && api.isDirty(obj) &&
isDelayDatastoreOperationsEnabled())
{
// Object provisionally persistent (but not in datastore) so re-run reachability maybe
if (NucleusLogger.PERSISTENCE.isDebugEnabled())
{
NucleusLogger.PERSISTENCE.debug(LOCALISER.msg("010015", StringUtils.toJVMIDString(obj)));
}
StateManager sm = findStateManager(obj);
sm.makePersistent();
id = sm.getInternalObjectId();
}
}
if (id != null && txCachedIds != null)
{