private static int loadOnFindCMRFields(Object pk, List<LeftJoinCMRNode> onFindCMRNodes, ResultSet rs, int index, Logger log) {
Object[] ref = new Object[1];
for (LeftJoinCMRNode node : onFindCMRNodes) {
JDBCCMRFieldBridge cmrField = node.cmrField;
ReadAheadCache myCache = cmrField.getJDBCStoreManager().getReadAheadCache();
JDBCEntityBridge relatedEntity = cmrField.getRelatedJDBCEntity();
ReadAheadCache relatedCache = cmrField.getRelatedManager().getReadAheadCache();
// load related id
ref[0] = null;
index = relatedEntity.loadPrimaryKeyResults(rs, index, ref);
Object relatedId = ref[0];
boolean cacheRelatedData = relatedId != null;
if (pk != null) {
if (cmrField.getMetaData().getRelatedRole().isMultiplicityOne()) {
// cacheRelatedData the value
myCache.addPreloadData(pk,
cmrField,
relatedId == null ? Collections.EMPTY_LIST : Collections.singletonList(relatedId));
} else {
Collection<Object> cachedValue = myCache.getCachedCMRValue(pk, cmrField);
if (cachedValue == null) {
cachedValue = new ArrayList<Object>();
myCache.addPreloadData(pk, cmrField, cachedValue);
}
if (relatedId != null) {
if (cachedValue.contains(relatedId)) {
cacheRelatedData = false;
} else {
cachedValue.add(relatedId);
}
}
}
}
// load eager load group
if (node.eagerLoadMask != null) {
JDBCFieldBridge[] tableFields = relatedEntity.getTableFields();
for (int fieldInd = 0; fieldInd < tableFields.length; ++fieldInd) {
if (node.eagerLoadMask[fieldInd]) {
JDBCFieldBridge field = tableFields[fieldInd];
ref[0] = null;
index = field.loadArgumentResults(rs, index, ref);
if (cacheRelatedData) {
if (log.isTraceEnabled()) {
log.trace("Caching " +
relatedEntity.getEntityName() +
'[' +
relatedId +
"]." +
field.getFieldName() + "=" + ref[0]);
}