* @return Persistence Capable object (with connected StateManager).
*/
public Object getObjectFromCache(Object id)
{
Object pc = null;
StateManager sm = null;
// Try Level 1 first
if (cache != null)
{
sm = (StateManager)cache.get(id);
if (sm != null)
{
pc = sm.getObject();
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("003008", StringUtils.toJVMIDString(pc),
getIdentityAsString(id),
StringUtils.booleanArrayToString(sm.getLoadedFields()),
"" + cache.size()));
}
// Wipe the detach state that may have been added if the object has been serialised in the meantime
sm.resetDetachState();
return pc;
}
else
{
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("003007", getIdentityAsString(id), "" + cache.size()));
}
}
}
// Try Level 2 since not in Level 1
if (context.hasLevel2Cache())
{
Level2Cache l2Cache = context.getLevel2Cache();
CachedPC cachedPC = null;
synchronized (l2Cache)
{
cachedPC = l2Cache.get(id);
}
// Create active version of cached object with StateManager connected and same id
if (cachedPC != null)
{
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("004015",
getIdentityAsString(id),
StringUtils.booleanArrayToString(cachedPC.getLoadedFields()),
StringUtils.objectArrayToString(cachedPC.getRelationFieldNames())));
}
sm = (StateManager) ObjectProviderFactory.newForCachedPC(this, id, cachedPC);
pc = sm.getObject(); // Object in P_CLEAN state
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("004006",
getIdentityAsString(id), StringUtils.toJVMIDString(pc)));
}
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