}
boolean cleanReadAhead = manager.getMetaData().isCleanReadAheadOnLoad();
boolean loaded = false;
JDBCCMRFieldBridge onlyOneSingleValuedCMR = null;
// iterate over the keys in the preloaded map
Iterator iter = preloadDataMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
Object field = entry.getKey();
// get the value that was preloaded for this field
Object value = entry.getValue();
// if we didn't get a value something is seriously hosed
if (value == null) {
throw new IllegalStateException("Preloaded value not found");
}
if (cleanReadAhead) {
// remove this value from the preload cache as it is about to be loaded
iter.remove();
}
// check for null value standin
if (value == NULL_VALUE) {
value = null;
}
if (field instanceof JDBCCMPFieldBridge) {
JDBCCMPFieldBridge cmpField = (JDBCCMPFieldBridge) field;
if (!cmpField.isLoaded(ctx)) {
if (log.isTraceEnabled()) {
log.trace("Preloading data:" +
" entity=" + manager.getEntityBridge().getEntityName() +
" pk=" + ctx.getPrimaryKey() +
" cmpField=" + cmpField.getFieldName());
}
// set the value
cmpField.setInstanceValue(ctx, value);
// mark this field clean as it's value was just loaded
cmpField.setClean(ctx);
loaded = true;
} else {
if (log.isTraceEnabled()) {
log.trace("CMPField already loaded:" +
" entity=" + manager.getEntityBridge().getEntityName() +
" pk=" + ctx.getPrimaryKey() +
" cmpField=" + cmpField.getFieldName());
}
}
} else if (field instanceof JDBCCMRFieldBridge) {
JDBCCMRFieldBridge cmrField = (JDBCCMRFieldBridge) field;
if (!cmrField.isLoaded(ctx)) {
if (log.isTraceEnabled()) {
log.trace("Preloading data:" +
" entity=" + manager.getEntityBridge().getEntityName() +
" pk=" + ctx.getPrimaryKey() +
" cmrField=" + cmrField.getFieldName());
}
// set the value
cmrField.load(ctx, (List) value);
// add the loaded list to the related entity's readahead cache
JDBCStoreManager relatedManager = (JDBCStoreManager) cmrField.getRelatedCMRField().getManager();
ReadAheadCache relatedReadAheadCache =
relatedManager.getReadAheadCache();
relatedReadAheadCache.addFinderResults(
(List) value, cmrField.getReadAhead());
if (!loaded) {
// this is a hack to fix on-load read-ahead for 1:m relationships
if (cmrField.isSingleValued() && onlyOneSingleValuedCMR == null) {
onlyOneSingleValuedCMR = cmrField;
} else {
loaded = true;
}
}
} else {
if (log.isTraceEnabled()) {
log.trace("CMRField already loaded:" +
" entity=" + manager.getEntityBridge().getEntityName() +
" pk=" + ctx.getPrimaryKey() +
" cmrField=" + cmrField.getFieldName());
}
}
}
}