if (mmd.getFieldTypes() != null && mmd.getFieldTypes().length > 0)
{
// Embedded type has field-type defined so use that as our embedded type
embeddedType = ec.getClassLoaderResolver().classForName(mmd.getFieldTypes()[0]);
}
ObjectProvider embSM = ObjectProviderFactory.newForHollow(ec, embeddedType, (Object)null);
embSM.setPcObjectType(objectType);
value = embSM.getObject();
String nullColumn = null;
String nullValue = null;
if (emd != null)
{
nullColumn = emd.getNullIndicatorColumn();
nullValue = emd.getNullIndicatorValue();
}
int n = 0;
for (int i=0; i<javaTypeMappings.size(); i++)
{
JavaTypeMapping mapping = ((JavaTypeMapping)javaTypeMappings.get(i));
int embAbsFieldNum = embCmd.getAbsolutePositionOfMember(mapping.getMemberMetaData().getName());
if (mapping instanceof EmbeddedPCMapping)
{
// We have a nested embedded
int numSubParams = mapping.getNumberOfDatastoreMappings();
int[] subParam = new int[numSubParams];
int k = 0;
for (int j=n;j<n+numSubParams;j++)
{
subParam[k++] = param[j];
}
n += numSubParams;
// Use the sub-object mapping to extract the value for that object
Object subValue = mapping.getObject(ec, rs, subParam, embSM, embAbsFieldNum);
if (subValue != null)
{
embSM.replaceFieldMakeDirty(embAbsFieldNum, subValue);
}
// TODO Check the null column and its value in the sub-embedded ?
}
else
{
// Extract the value(s) for this field and update the PC if it is not null
int[] posMapping = new int[mapping.getNumberOfDatastoreMappings()];
for (int j=0; j<posMapping.length; j++)
{
posMapping[j] = param[n++];
}
Object fieldValue = mapping.getObject(ec, rs, posMapping);
if (fieldValue != null)
{
embSM.replaceFieldMakeDirty(embAbsFieldNum, fieldValue);
}
else
{
// If the value is null, but the field is not a primitive update it
AbstractMemberMetaData embFmd = embCmd.getMetaDataForManagedMemberAtAbsolutePosition(embAbsFieldNum);
if (!embFmd.getType().isPrimitive())
{
embSM.replaceFieldMakeDirty(embAbsFieldNum, fieldValue);
}
}
// Check for the null column and its value
if (nullColumn != null &&
mapping.getMemberMetaData().getColumnMetaData()[0].getName().equals(nullColumn))
{
if ((nullValue == null && fieldValue == null) ||
(nullValue != null && fieldValue.toString().equals(nullValue)))
{
value = null;
break;
}
}
}
}
// Update owner field in the element (if present)
if (emd != null)
{
String ownerField = emd.getOwnerMember();
if (ownerField != null)
{
int ownerFieldNumberInElement = embCmd.getAbsolutePositionOfMember(ownerField);
if (ownerFieldNumberInElement >= 0)
{
embSM.replaceFieldMakeDirty(ownerFieldNumberInElement, ownerSM.getObject());
}
}
}
// Register our owner now that we have our values set
if (value != null && ownerSM != null)
{
embSM.addEmbeddedOwner(ownerSM, ownerFieldNumber);
}
return value;
}