// Loop through each id column in the reference table and add the same here
// applying the required names from the columnContainer
for (int j = 0; j < mapping.getNumberOfDatastoreFields(); j++) {
JavaTypeMapping m = masterMapping;
DatastoreField refColumn = mapping.getDataStoreMapping(j).getDatastoreField();
if (mapping instanceof PersistenceCapableMapping) {
m = storeMgr.getMappingManager()
.getMapping(clr.classForName(refColumn.getJavaTypeMapping().getType()));
((PersistenceCapableMapping) masterMapping).addJavaTypeMapping(m);
}
ColumnMetaData userdefinedColumn = null;
if (userdefinedCols != null) {
for (ColumnMetaData userdefinedCol : userdefinedCols) {
if (refColumn.getIdentifier().toString().equals(userdefinedCol.getTarget())) {
userdefinedColumn = userdefinedCol;
break;
}
}
if (userdefinedColumn == null && nextUserdefinedCol < userdefinedCols.length) {
userdefinedColumn = userdefinedCols[nextUserdefinedCol++];
}
}
// Add this application identity column
DatastoreField idColumn;
if (userdefinedColumn != null) {
// User has provided a name for this column
// Currently we only use the column namings from the users definition but we could easily
// take more of their details.
idColumn = addDatastoreField(refColumn.getStoredJavaType(),
storeMgr.getIdentifierFactory().newIdentifier(IdentifierType.COLUMN,
userdefinedColumn.getName()),
m, refColumn.getColumnMetaData());
} else {
// No name provided so take same as superclass
idColumn = addDatastoreField(refColumn.getStoredJavaType(), refColumn.getIdentifier(),
m, refColumn.getColumnMetaData());
}
if (mapping != null
&& mapping.getDataStoreMapping(j).getDatastoreField().getColumnMetaData() != null) {
refColumn.copyConfigurationTo(idColumn);
}
idColumn.setAsPrimaryKey();
// Set the column type based on the field.getType()
getStoreManager().getMappingManager()
.createDatastoreMapping(m, idColumn, refColumn.getJavaTypeMapping().getType());
}