if (managesField(fmd.getFullFieldName())) {
if (!fmd.getClassName(true).equals(curCmd.getFullClassName())) {
throw new UnsupportedOperationException("Overrides not currently supported.");
}
} else {
MetaDataManager mmgr = storeMgr.getMetaDataManager();
// Manage the field if not already managed (may already exist if overriding a superclass field)
JavaTypeMapping mapping = null;
if (fmd.getPersistenceModifier() == FieldPersistenceModifier.PERSISTENT) {
boolean isPrimary = true;
if (fmd.getTable() != null && fmd.getJoinMetaData() == null) {
// Field has a table specified and is not a 1-N with join table so is mapped to a secondary table
isPrimary = false;
}
if (isPrimary) {
// Add the field to this table
mapping = dba.getMappingManager(storeMgr).getMapping(this, fmd, clr, FieldRole.ROLE_FIELD);
addFieldMapping(mapping);
embeddedFieldMappingsMap.put(fmd, fieldMappingsMap.get(fmd));
} else {
throw new UnsupportedOperationException("No support for secondary tables.");
}
} else if (fmd.getPersistenceModifier() != FieldPersistenceModifier.TRANSACTIONAL) {
throw new NucleusException("Invalid persistence-modifier for field ").setFatal();
}
// Calculate if we need a FK adding due to a 1-N relationship TODO Remove this when no longer supporting old storageVersion
// Note that we ignore any "join" setting since we don't use join tables
boolean needsFKToContainerOwner = false;
RelationType relationType = fmd.getRelationType(clr);
if (relationType == RelationType.ONE_TO_MANY_BI) {
/*AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
if (fmd.getJoinMetaData() == null && relatedMmds[0].getJoinMetaData() == null) {*/
needsFKToContainerOwner = true;
/*}*/
} else if (relationType == RelationType.ONE_TO_MANY_UNI) {
/*if (fmd.getJoinMetaData() == null) {*/
needsFKToContainerOwner = true;
/*}*/
} else if (relationType == RelationType.ONE_TO_ONE_BI) {
if (fmd.getMappedBy() != null && MetaDataUtils.isOwnedRelation(fmd, storeMgr)) {
// This element type has a many-to-one pointing back.
// We assume that our pk is part of the pk of the element type.
DatastoreTable dt = storeMgr.getDatastoreClass(fmd.getAbstractClassMetaData().getFullClassName(), clr);
dt.runCallBacks();
dt.markFieldAsParentKeyProvider(fmd.getName());
}
} else if (relationType == RelationType.MANY_TO_ONE_BI) {
}
if (needsFKToContainerOwner) {
// 1-N uni/bidirectional using FK, so update the element side with a FK
if ((fmd.getCollection() != null && !SCOUtils.collectionHasSerialisedElements(fmd)) ||
(fmd.getArray() != null && !SCOUtils.arrayIsStoredInSingleColumn(fmd, mmgr))) {
// 1-N ForeignKey collection/array, so add FK to element table
AbstractClassMetaData elementCmd;
if (fmd.hasCollection()) {
// Collection
elementCmd = mmgr.getMetaDataForClass(fmd.getCollection().getElementType(), clr);
} else {
// Array
elementCmd = mmgr.getMetaDataForClass(fmd.getType().getComponentType(), clr);
}
if (elementCmd == null) {
// Elements that are reference types or non-PC will come through here
} else {
AbstractClassMetaData[] elementCmds;
// TODO : Cater for interface elements, and get the metadata for the implementation classes here
if (elementCmd.getInheritanceMetaData().getStrategy() == InheritanceStrategy.SUBCLASS_TABLE) {
elementCmds = storeMgr.getClassesManagingTableForClass(elementCmd, clr);
} else {
elementCmds = new ClassMetaData[1];
elementCmds[0] = elementCmd;
}
// Run callbacks for each of the element classes.
for (AbstractClassMetaData elementCmd1 : elementCmds) {
callbacks.put(elementCmd1.getFullClassName(), new CallBack(fmd, cmd.getFullClassName()));
DatastoreTable dt =
(DatastoreTable) storeMgr.getDatastoreClass(elementCmd1.getFullClassName(), clr);
dt.runCallBacks();
if (fmd.getMappedBy() != null && MetaDataUtils.isOwnedRelation(fmd, storeMgr)) {
// This element type has a many-to-one pointing back.
// We assume that our pk is part of the pk of the element type.
dt.markFieldAsParentKeyProvider(fmd.getMappedBy());
}
}
}
} else if (fmd.getMap() != null && !SCOUtils.mapHasSerialisedKeysAndValues(fmd)) {
// 1-N ForeignKey map, so add FK to value table
if (fmd.getKeyMetaData() != null && fmd.getKeyMetaData().getMappedBy() != null) {
// Key is stored in the value table so add the FK to the value table
AbstractClassMetaData valueCmd = mmgr.getMetaDataForClass(fmd.getMap().getValueType(), clr);
if (valueCmd == null) {
// Interface elements will come through here and java.lang.String and others as well
}
} else if (fmd.getValueMetaData() != null
&& fmd.getValueMetaData().getMappedBy() != null) {
// Value is stored in the key table so add the FK to the key table
AbstractClassMetaData keyCmd = mmgr.getMetaDataForClass(fmd.getMap().getKeyType(), clr);
if (keyCmd == null) {
// Interface elements will come through here and java.lang.String and others as well
} else {
}
}