createPKVectorsFromMap(reference, mapping);
// loop over each pk vector and get object from cache - then add to collection and set on object
Object value = null;
if(!mapping.isWriteOnly()) {
for (Iterator pkIt = ((Vector)reference.getPrimaryKey()).iterator(); pkIt.hasNext();) {
CacheId primaryKey = (CacheId) pkIt.next();
value = getValue(session, reference, primaryKey);
if (value != null) {
cPolicy.addInto(value, container, session);
}
}
}
// for each reference, get the source object and add it to the container policy
// when finished, set the policy on the mapping
mapping.setAttributeValueInObject(referenceSourceObject, container);
XMLInverseReferenceMapping inverseReferenceMapping = mapping.getInverseReferenceMapping();
if(inverseReferenceMapping != null && value != null) {
AttributeAccessor backpointerAccessor = inverseReferenceMapping.getAttributeAccessor();
ContainerPolicy backpointerContainerPolicy = inverseReferenceMapping.getContainerPolicy();
if(backpointerContainerPolicy == null) {
backpointerAccessor.setAttributeValueInObject(value, referenceSourceObject);
} else {
Object backpointerContainer = backpointerAccessor.getAttributeValueFromObject(value);
if(backpointerContainer == null) {
backpointerContainer = backpointerContainerPolicy.containerInstance();
backpointerAccessor.setAttributeValueInObject(value, backpointerContainer);
}
backpointerContainerPolicy.addInto(referenceSourceObject, backpointerContainer, session);
}
}
} else if (reference.getMapping() instanceof XMLObjectReferenceMapping) {
CacheId primaryKey = (CacheId) reference.getPrimaryKey();
Object value = getValue(session, reference, primaryKey);
XMLObjectReferenceMapping mapping = (XMLObjectReferenceMapping)reference.getMapping();
if (value != null) {
mapping.setAttributeValueInObject(reference.getSourceObject(), value);
}