getEagerMappings().clear();
getRelationshipMappings().clear();
for (Enumeration mappings = this.descriptor.getMappings().elements();
mappings.hasMoreElements();) {
DatabaseMapping mapping = (DatabaseMapping)mappings.nextElement();
// Add attribute to mapping association
if (!mapping.isWriteOnly()) {
getMappingsByAttribute().put(mapping.getAttributeName(), mapping);
}
// Cache mappings that require cloning.
if (mapping.isCloningRequired()) {
getCloningMappings().add(mapping);
}
// Cache eager mappings.
if (mapping.isForeignReferenceMapping() && ((ForeignReferenceMapping)mapping).usesIndirection() && (!mapping.isLazy())) {
getEagerMappings().add(mapping);
}
// Cache relationship mappings.
if (!mapping.isDirectToFieldMapping()) {
getRelationshipMappings().add(mapping);
}
// Add field to mapping association
for (DatabaseField field : mapping.getFields()) {
if (mapping.isReadOnly()) {
List readOnlyMappings = getReadOnlyMappingsByField().get(field);
if (readOnlyMappings == null) {
readOnlyMappings = new ArrayList();
getReadOnlyMappingsByField().put(field, readOnlyMappings);
}
readOnlyMappings.add(mapping);
} else {
if (mapping.isAggregateObjectMapping()) {
// For Embeddable class, we need to test read-only
// status of individual fields in the embeddable.
ObjectBuilder aggregateObjectBuilder = ((AggregateObjectMapping)mapping).getReferenceDescriptor().getObjectBuilder();
// Look in the non-read-only fields mapping
DatabaseMapping aggregatedFieldMapping = aggregateObjectBuilder.getMappingForField(field);
if (aggregatedFieldMapping == null) { // mapping must be read-only
List readOnlyMappings = getReadOnlyMappingsByField().get(field);
if (readOnlyMappings == null) {
readOnlyMappings = new ArrayList();
getReadOnlyMappingsByField().put(field, readOnlyMappings);
}
readOnlyMappings.add(mapping);
} else {
getMappingsByField().put(field, mapping);
}
} else { // Not an embeddable mapping
if (!getMappingsByField().containsKey(field)) {
getMappingsByField().put(field, mapping);
}
}
}
}
}
this.isSimple = getRelationshipMappings().isEmpty();
initializePrimaryKey(session);
initializeJoinedAttributes();
if (this.descriptor.usesSequenceNumbers()) {
DatabaseMapping sequenceMapping = getMappingForField(this.descriptor.getSequenceNumberField());
if ((sequenceMapping != null) && sequenceMapping.isDirectToFieldMapping()) {
setSequenceMapping((AbstractDirectMapping)sequenceMapping);
}
}
}