{
AbstractMemberMetaData fmd = candidateCmd.getMetaDataForManagedMemberAtAbsolutePosition(fieldNumber);
String fieldName = fmd.getName();
Class fieldType = fmd.getType();
JavaTypeMapping m = null;
if (fmd.getPersistenceModifier() != FieldPersistenceModifier.NONE)
{
if (tbl != null)
{
// Get the field mapping from the candidate table
m = tbl.getMemberMapping(fmd);
}
else
{
// Fall back to generating a mapping for this type - does this ever happen?
m = storeMgr.getMappingManager().getMappingWithDatastoreMapping(
fieldType, false, false, clr);
}
if (m.includeInFetchStatement())
{
// Set mapping for this field since it can potentially be returned from a fetch
String columnName = null;
if (fmd.getColumnMetaData() != null && fmd.getColumnMetaData().length > 0)
{
for (int colNum = 0;colNum<fmd.getColumnMetaData().length;colNum++)
{
columnName = fmd.getColumnMetaData()[colNum].getName();
columnFieldNumberMap.put(columnName, Integer.valueOf(fieldNumber));
}
}
else
{
columnName = storeMgr.getIdentifierFactory().newDatastoreFieldIdentifier(
fieldName, ec.getNucleusContext().getTypeManager().isDefaultEmbeddedType(fieldType),
FieldRole.ROLE_NONE).getIdentifierName();
columnFieldNumberMap.put(columnName, Integer.valueOf(fieldNumber));
}
}
else
{
// Don't put anything in this position (field has no column in the result set)
}
}
else
{
// Don't put anything in this position (field has no column in the result set)
}
stmtMappings[fieldNumber] = new StatementMappingIndex(m);
}
if (columnFieldNumberMap.size() == 0)
{
// None of the fields in the class have columns in the datastore table!
throw new NucleusUserException(LOCALISER.msg("059030", candidateClass.getName())).setFatal();
}
// Generate id column field information for later checking the id is present
DatastoreClass table = storeMgr.getDatastoreClass(candidateClass.getName(), clr);
PersistableMapping idMapping = (PersistableMapping)table.getIdMapping();
String[] idColNames = new String[idMapping.getNumberOfDatastoreMappings()];
boolean[] idColMissing = new boolean[idMapping.getNumberOfDatastoreMappings()];
for (int i=0;i<idMapping.getNumberOfDatastoreMappings();i++)
{
DatastoreMapping m = idMapping.getDatastoreMapping(i);
idColNames[i] = m.getDatastoreField().getIdentifier().toString();
idColMissing[i] = true;
}
// Generate discriminator/version information for later checking they are present
String discriminatorColName = table.getDiscriminatorMapping(false) != null ?