CorrespondentColumnsMapper correspondentColumnsMapping =
new CorrespondentColumnsMapper(colmdContainer, ownerIdMapping, true);
int countIdFields = ownerIdMapping.getNumberOfDatastoreMappings();
for (int i=0; i<countIdFields; i++)
{
DatastoreMapping refDatastoreMapping = ownerIdMapping.getDatastoreMapping(i);
JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(refDatastoreMapping.getJavaTypeMapping().getJavaType());
ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(((Column)refDatastoreMapping.getDatastoreField()).getIdentifier());
if (colmd == null)
{
throw new NucleusUserException(LOCALISER.msg("057035",
((Column)refDatastoreMapping.getDatastoreField()).getIdentifier(), toString())).setFatal();
}
DatastoreIdentifier identifier = null;
IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
if (colmd.getName() == null || colmd.getName().length() < 1)
{
// No user provided name so generate one
identifier = idFactory.newForeignKeyFieldIdentifier(ownerFmd,
null, refDatastoreMapping.getDatastoreField().getIdentifier(),
storeMgr.getNucleusContext().getTypeManager().isDefaultEmbeddedType(mapping.getJavaType()),
FieldRole.ROLE_OWNER);
}
else
{
// User-defined name
identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
}
DatastoreField refColumn = addDatastoreField(mapping.getJavaType().getName(), identifier, mapping, colmd);
((Column)refDatastoreMapping.getDatastoreField()).copyConfigurationTo(refColumn);
if (colmd == null || (colmd != null && colmd.getAllowsNull() == null) ||
(colmd != null && colmd.getAllowsNull() != null && colmd.isAllowsNull()))
{
// User either wants it nullable, or haven't specified anything, so make it nullable
refColumn.setNullable();
}
fkMapping.addDatastoreMapping(getStoreManager().getMappingManager().createDatastoreMapping(mapping, refColumn, refDatastoreMapping.getJavaTypeMapping().getJavaType().getName()));
((PersistableMapping)fkMapping).addJavaTypeMapping(mapping);
}
}
catch (DuplicateDatastoreFieldException dce)
{