if (elemCmd.hasDiscriminatorStrategy()) {
collDiscName = elemCmd.getDiscriminatorColumnName();
if (embmd != null && embmd.getDiscriminatorMetaData() != null) {
// Override if specified under <embedded>
DiscriminatorMetaData dismd = embmd.getDiscriminatorMetaData();
ColumnMetaData discolmd = dismd.getColumnMetaData();
if (discolmd != null && discolmd.getName() != null) {
collDiscName = discolmd.getName();
}
}
if (collDiscName == null) {
collDiscName = getPropertyNameForMember(mmd) + ".discrim";
}
}
for (int i=0;i<collSize;i++) {
Class elementCls = elementType;
if (collDiscName != null) {
Object discVal = datastoreEntity.getProperty(collDiscName + "." + i);
String className =
org.datanucleus.metadata.MetaDataUtils.getClassNameFromDiscriminatorValue((String)discVal,
elemCmd.getDiscriminatorMetaDataRoot(), ec);
elementCls = clr.classForName(className);
}
ObjectProvider embeddedOP = getEmbeddedObjectProvider(elementCls, fieldNumber, null);
fieldManagerStateStack.addFirst(new FieldManagerState(embeddedOP, embmd, i));
try {
embeddedOP.replaceFields(embeddedOP.getClassMetaData().getAllMemberPositions(), this);
} finally {
fieldManagerStateStack.removeFirst();
}
coll.add(embeddedOP.getObject());
}
return getObjectProvider().wrapSCOField(fieldNumber, coll, false, false, true);
} else if (mmd.hasArray()) {
// Embedded arrays
String arrPropName = getPropertyNameForMember(mmd) + ".size";
Long arrSize = (Long)datastoreEntity.getProperty(arrPropName);
if (arrSize == null || arrSize == -1) {
// Size of array not stored or stored as -1, so null on persist
return null;
}
Class elementType = clr.classForName(mmd.getArray().getElementType());
AbstractClassMetaData elemCmd = mmd.getArray().getElementClassMetaData(clr, ec.getMetaDataManager());
EmbeddedMetaData embmd =
mmd.getElementMetaData() != null ? mmd.getElementMetaData().getEmbeddedMetaData() : null;
Object value = Array.newInstance(elementType, arrSize.intValue());
// Use discriminator for elements if available
String arrDiscName = null;
if (elemCmd.hasDiscriminatorStrategy()) {
arrDiscName = elemCmd.getDiscriminatorColumnName();
if (embmd != null && embmd.getDiscriminatorMetaData() != null) {
// Override if specified under <embedded>
DiscriminatorMetaData dismd = embmd.getDiscriminatorMetaData();
ColumnMetaData discolmd = dismd.getColumnMetaData();
if (discolmd != null && discolmd.getName() != null) {
arrDiscName = discolmd.getName();
}
}
if (arrDiscName == null) {
arrDiscName = getPropertyNameForMember(mmd) + ".discrim";
}