return super.loadAll(sms, state, load, fetch, edata);
Map unloaded = null;
List smList = null;
Map caches = new HashMap();
OpenJPAStateManager sm;
DataCache cache;
DataCachePCData data;
BitSet fields;
for (Iterator itr = sms.iterator(); itr.hasNext();) {
sm = (OpenJPAStateManager) itr.next();
cache = sm.getMetaData().getDataCache();
if (cache == null || sm.isEmbedded()) {
unloaded = addUnloaded(sm, null, unloaded);
continue;
}
if (sm.getManagedInstance() == null
|| load != FORCE_LOAD_NONE
|| sm.getPCState() == PCState.HOLLOW) {
smList = (List) caches.get(cache);
if (smList == null) {
smList = new ArrayList();
caches.put(cache, smList);
}
smList.add(sm);
} else if (!cache.contains(sm.getObjectId()))
unloaded = addUnloaded(sm, null, unloaded);
}
for (Iterator itr = caches.keySet().iterator(); itr.hasNext();) {
cache = (DataCache) itr.next();
smList = (List) caches.get(cache);
List oidList = new ArrayList(smList.size());
for (itr=smList.iterator();itr.hasNext();) {
sm = (OpenJPAStateManager) itr.next();
oidList.add((OpenJPAId) sm.getObjectId());
}
Map dataMap = cache.getAll(oidList);
for (itr=smList.iterator();itr.hasNext();) {
sm = (OpenJPAStateManager) itr.next();
data = (DataCachePCData) dataMap.get(
(OpenJPAId) sm.getObjectId());
if (sm.getManagedInstance() == null) {
if (data != null) {
//### the 'data.type' access here probably needs
//### to be addressed for bug 511
sm.initialize(data.getType(), state);
data.load(sm, fetch, edata);
} else
unloaded = addUnloaded(sm, null, unloaded);
} else if (load != FORCE_LOAD_NONE
|| sm.getPCState() == PCState.HOLLOW) {
data = cache.get(sm.getObjectId());
if (data != null) {
// load unloaded fields
fields = sm.getUnloaded(fetch);
data.load(sm, fields, fetch, edata);
if (fields.length() > 0)
unloaded = addUnloaded(sm, fields, unloaded);
} else
unloaded = addUnloaded(sm, null, unloaded);
}
}
}
if (unloaded == null)
return Collections.EMPTY_LIST;
// load with delegate
Collection failed = super.loadAll(unloaded.keySet(), state, load,
fetch, edata);
if (!_ctx.getPopulateDataCache())
return failed;
// for each loaded instance, merge loaded state into cached data
Map.Entry entry;
boolean isNew;
for (Iterator itr = unloaded.entrySet().iterator(); itr.hasNext();) {
entry = (Map.Entry) itr.next();
sm = (OpenJPAStateManager) entry.getKey();
fields = (BitSet) entry.getValue();
cache = sm.getMetaData().getDataCache();
if (cache == null || sm.isEmbedded() || (failed != null
&& failed.contains(sm.getId())))
continue;
// make sure that we're not trying to cache an old version
cache.writeLock();
try {
data = cache.get(sm.getObjectId());
if (data != null && compareVersion(sm, sm.getVersion(),
data.getVersion()) == VERSION_EARLIER)
continue;
isNew = data == null;
if (isNew)