// TODO Handle creation of columns in join table for map of PCs as values
}
else
{
// Either one end of a 1-1 relation, or the N end of a N-1
MappedStoreManager storeMgr = datastoreContainer.getStoreManager();
AbstractClassMetaData refCmd = storeMgr.getOMFContext().getMetaDataManager().getMetaDataForClass(mmd.getType(), clr);
JavaTypeMapping referenceMapping = null;
if (refCmd.getInheritanceMetaData() != null &&
refCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE)
{
// Find the actual tables storing the other end (can be multiple subclasses)
AbstractClassMetaData[] cmds = storeMgr.getClassesManagingTableForClass(refCmd, clr);
if (cmds != null && cmds.length > 0)
{
if (cmds.length > 1)
{
NucleusLogger.PERSISTENCE.warn("Field " + mmd.getFullFieldName() + " represents either a 1-1 relation, " +
"or a N-1 relation where the other end uses \"subclass-table\" inheritance strategy and more " +
"than 1 subclasses with a table. This is not fully supported by JPOX");
}
}
else
{
// No subclasses of the class using "subclasses-table" so no mapping!
// TODO Throw an exception ?
return;
}
// TODO We need a mapping for each of the possible subclass tables
referenceMapping = storeMgr.getDatastoreClass(cmds[0].getFullClassName(), clr).getIDMapping();
}
else
{
referenceMapping = storeMgr.getDatastoreClass(mmd.getType().getName(), clr).getIDMapping();
}
// Generate a mapping from the columns of the referenced object to this mapping's ColumnMetaData
CorrespondentColumnsMapper correspondentColumnsMapping = new CorrespondentColumnsMapper(mmd, referenceMapping, true);
// Find any related field where this is part of a bidirectional relation
int relationType = mmd.getRelationType(clr);
boolean createDatastoreMappings = true;
if (relationType == Relation.MANY_TO_ONE_BI)
{
AbstractMemberMetaData[] relatedMmds = mmd.getRelatedMemberMetaData(clr);
// TODO Cater for more than 1 related field
createDatastoreMappings = (relatedMmds[0].getJoinMetaData() == null);
}
else if (relationType == Relation.ONE_TO_ONE_BI)
{
// Put the FK at the end without "mapped-by"
createDatastoreMappings = (mmd.getMappedBy() == null);
}
// Loop through the datastore fields in the referenced class and create a datastore field for each
for (int i=0; i<referenceMapping.getNumberOfDatastoreFields(); i++)
{
DatastoreMapping refDatastoreMapping = referenceMapping.getDataStoreMapping(i);
JavaTypeMapping mapping = storeMgr.getMappingManager().getMapping(refDatastoreMapping.getJavaTypeMapping().getJavaType());
this.addJavaTypeMapping(mapping);
// Create physical datastore columns where we require a FK link to the related table.
if (createDatastoreMappings)
{