colmds[0] = colmd;
}
}
// Generate the column identifier
IdentifierFactory idFactory = storeMgr.getIdentifierFactory();
DatastoreIdentifier identifier = null;
if (colmd.getName() == null)
{
// No name specified, so generate the identifier from the field name
if (roleForField == FieldRole.ROLE_COLLECTION_ELEMENT)
{
// Join table collection element
identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null,
true, FieldRole.ROLE_COLLECTION_ELEMENT);
}
else if (roleForField == FieldRole.ROLE_ARRAY_ELEMENT)
{
// Join table array element
identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null,
true, FieldRole.ROLE_ARRAY_ELEMENT);
}
else if (roleForField == FieldRole.ROLE_MAP_KEY)
{
// Join table map key
identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null,
true, FieldRole.ROLE_MAP_KEY);
}
else if (roleForField == FieldRole.ROLE_MAP_VALUE)
{
// Join table map value
identifier = idFactory.newJoinTableFieldIdentifier(fmd, null, null,
true, FieldRole.ROLE_MAP_VALUE);
}
else
{
identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName());
int i=0;
while (datastoreContainer.hasDatastoreField(identifier))
{
identifier = idFactory.newIdentifier(IdentifierType.COLUMN, fmd.getName() + "_" + i);
i++;
}
}
colmd.setName(identifier.getIdentifierName());
}
else
{
// User has specified a name, so try to keep this unmodified
identifier = idFactory.newDatastoreFieldIdentifier(colmds[datastoreFieldIndex].getName(),
storeMgr.getNucleusContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
FieldRole.ROLE_CUSTOM);
}
// Create the column