}
// Try Level 2 since not in Level 1
if (omf.hasLevel2Cache())
{
Level2Cache l2Cache = omf.getLevel2Cache();
synchronized (l2Cache)
{
CachedPC cachedPC = l2Cache.get(id);
// Create active version of cached object with StateManager connected and same id
if (cachedPC != null)
{
sm = StateManagerFactory.newStateManagerForCachedPC(this, id, cachedPC);
pc = sm.getObject(); // Object in P_CLEAN state
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("004006",
StringUtils.toJVMIDString(pc), getIdentityAsString(id),
StringUtils.booleanArrayToString(cachedPC.getLoadedFields()),
StringUtils.objectArrayToString(cachedPC.getRelationFieldNames()),
"" + l2Cache.getSize()));
}
if (tx.isActive() && tx.getOptimistic())
{
// Optimistic txns, so return as P_NONTRANS (as per JDO2 spec)
sm.makeNontransactional();
}
else if (!tx.isActive() && getApiAdapter().isTransactional(pc))
{
// Non-tx context, so return as P_NONTRANS (as per JDO2 spec)
sm.makeNontransactional();
}
return pc;
}
else
{
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("004005",
getIdentityAsString(id), "" + l2Cache.getSize()));
}
}
}
}