}
Level2Cache l2cache = myOM.getNucleusContext().getLevel2Cache();
if (l2cache != null && cmd.isCacheable() && !myOM.isObjectModifiedInTransaction(myID))
{
CachedPC cachedPC = null;
synchronized (l2cache)
{
cachedPC = l2cache.get(myID);
}
if (cachedPC != null)
{
int[] cacheFieldsToLoad = getFlagsSetTo(cachedPC.getLoadedFields(), fieldNumbers, false);
if (cacheFieldsToLoad != null && cacheFieldsToLoad.length > 0)
{
if (NucleusLogger.CACHE.isDebugEnabled())
{
NucleusLogger.CACHE.debug(LOCALISER.msg("026033", StringUtils.toJVMIDString(myPC), myID,
StringUtils.intArrayToString(cacheFieldsToLoad)));
}
// Connect a StateManager to the cachedPC
Object cachePC = cachedPC.getPersistableObject();
JDOStateManagerImpl cacheSM = new JDOStateManagerImpl(myOM, cmd);
// TODO Change to use a specific method - lifecycle state is not strictly correct
cacheSM.initialiseForDetached(cachePC, getExternalObjectId(myPC), getVersion(myPC));
// Copy across the specified fields into the cached object