new CorrespondentColumnsMapper(columnContainer, columnMetaData, m, true);
for (int i=0; i<m.getNumberOfDatastoreFields(); i++)
{
JavaTypeMapping refDatastoreMapping =
storeMgr.getMappingManager().getMapping(m.getDataStoreMapping(i).getJavaTypeMapping().getJavaType());
ColumnMetaData colmd = correspondentColumnsMapping.getColumnMetaDataByIdentifier(
m.getDataStoreMapping(i).getDatastoreField().getIdentifier());
try
{
DatastoreIdentifier identifier = null;
if (colmd.getName() == null)
{
// User hasn't provided a name, so we use default naming
if (isReferenceField)
{
// Create reference identifier
identifier = idFactory.newReferenceFieldIdentifier(mmd,
storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(javaType, clr),
m.getDataStoreMapping(i).getDatastoreField().getIdentifier(),
storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(javaType), fieldRole);
}
else
{
// Create join table identifier (FK using destination table identifier)
AbstractMemberMetaData[] relatedMmds = mmd.getRelatedMemberMetaData(clr);
// TODO Cater for more than 1 related field
identifier = idFactory.newJoinTableFieldIdentifier(mmd,
relatedMmds != null ? relatedMmds[0] : null,
m.getDataStoreMapping(i).getDatastoreField().getIdentifier(),
storeMgr.getOMFContext().getTypeManager().isDefaultEmbeddedType(javaType), fieldRole);
}
}
else
{
// User defined name, so we use that.
identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
}
// Only add the column if not currently present
DatastoreField column = table.addDatastoreField(javaType.getName(), identifier, refDatastoreMapping, colmd);
m.getDataStoreMapping(i).getDatastoreField().copyConfigurationTo(column);
if (isPrimaryKey)
{
column.setAsPrimaryKey();
}
if (isNullable)
{
column.setNullable();
}
storeMgr.getMappingManager().createDatastoreMapping(refDatastoreMapping, column,
m.getDataStoreMapping(i).getJavaTypeMapping().getJavaTypeForDatastoreMapping(i));
}
catch (DuplicateDatastoreFieldException ex)
{
throw new NucleusUserException("Cannot create column for field "+mmd.getFullFieldName()+" column metadata "+colmd,ex);
}
((PersistenceCapableMapping) container).addJavaTypeMapping(refDatastoreMapping);
}
}
}
else
{
// Non-PC mapping
// Add column for the field
DatastoreField column = null;
ColumnMetaData colmd = null;
if (columnMetaData != null && columnMetaData.length > 0)
{
colmd = columnMetaData[0];
}
DatastoreIdentifier identifier = null;
if (colmd != null && colmd.getName() != null)
{
// User specified name
identifier = idFactory.newDatastoreFieldIdentifier(colmd.getName());
}
else
{
// No user-supplied name so generate one
identifier = idFactory.newJoinTableFieldIdentifier(mmd, null, null,