CorrespondentColumnsMapper correspondentColumnsMapping =
new CorrespondentColumnsMapper(colmdContainer, ownerIdMapping, true);
int countIdFields = ownerIdMapping.getNumberOfDatastoreFields();
for (int i=0; i<countIdFields; i++)
{
DatastoreMapping refDatastoreMapping = ownerIdMapping.getDataStoreMapping(i);
JavaTypeMapping mapping = dba.getMapping(refDatastoreMapping.getJavaTypeMapping().getJavaType(), storeMgr);
ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(((Column)refDatastoreMapping.getDatastoreField()).getIdentifier());
if (colmd == null)
{
throw new JPOXUserException(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 = ((RDBMSIdentifierFactory)idFactory).newForeignKeyFieldIdentifier(ownerFmd,
null, refDatastoreMapping.getDatastoreField().getIdentifier(),
storeMgr.getOMFContext().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.isAllowsNullSet()) ||
(colmd != null && colmd.isAllowsNullSet() && colmd.isAllowsNull()))
{
// User either wants it nullable, or havent specified anything, so make it nullable
refColumn.setNullable();
}
fkMapping.addDataStoreMapping(getStoreManager().getMappingManager().createDatastoreMapping(mapping, storeMgr, refColumn, refDatastoreMapping.getJavaTypeMapping().getJavaType().getName()));
((PersistenceCapableMapping)fkMapping).addJavaTypeMapping(mapping);
}
}
catch (DuplicateColumnNameException dcne)
{