else if (roleForField == JavaTypeMapping.MAPPING_MAP_VALUE)
{
columnContainer= fmd.getValueMetaData();
}
Column col;
ColumnMetaData[] colmds;
if (columnContainer != null && columnContainer.getColumnMetaData().length > datastoreFieldIndex)
{
colmd = columnContainer.getColumnMetaData()[datastoreFieldIndex];
colmds = columnContainer.getColumnMetaData();
}
else
{
// If column specified add one (use any column name specified on field element)
colmd = new ColumnMetaData(fmd, fmd.getColumn());
if (columnContainer != null)
{
columnContainer.addColumn(colmd);
colmds = columnContainer.getColumnMetaData();
}
else
{
colmds = new ColumnMetaData[1];
colmds[0] = colmd;
}
}
// Generate the column identifier
IdentifierFactory idFactory = datastoreContainer.getStoreManager().getIdentifierFactory();
DatastoreIdentifier identifier = null;
if (colmd.getName() == null)
{
// No name specified, so generate the identifier from the field name
if (roleForField == JavaTypeMapping.MAPPING_FIELD)
{
identifier = idFactory.newIdentifier(IdentifierFactory.COLUMN, fmd.getName());
int i=0;
while (datastoreContainer.hasDatastoreField(identifier))
{
identifier = idFactory.newIdentifier(IdentifierFactory.COLUMN, fmd.getName() + "_" + i);
i++;
}
}
else if (roleForField == JavaTypeMapping.MAPPING_COLLECTION_ELEMENT)
{
// Join table collection element
identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_COLLECTION_ELEMENT);
}
else if (roleForField == JavaTypeMapping.MAPPING_ARRAY_ELEMENT)
{
// Join table array element
identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_ARRAY_ELEMENT);
}
else if (roleForField == JavaTypeMapping.MAPPING_MAP_KEY)
{
// Join table map key
identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_MAP_KEY);
}
else if (roleForField == JavaTypeMapping.MAPPING_MAP_VALUE)
{
// Join table map value
identifier = ((RDBMSIdentifierFactory)idFactory).newJoinTableFieldIdentifier(fmd, null, null, true, FieldRole.ROLE_MAP_VALUE);
}
colmd.setName(identifier.getIdentifier());
}
else
{
// User has specified a name, so try to keep this unmodified
identifier = idFactory.newDatastoreFieldIdentifier(colmds[datastoreFieldIndex].getName(),
datastoreContainer.getStoreManager().getOMFContext().getTypeManager().isDefaultEmbeddedType(fmd.getType()),
FieldRole.ROLE_CUSTOM);
}
// Create the column
col = (Column) datastoreContainer.addDatastoreField(javaType, identifier, mapping, colmd);
if (fmd.isPrimaryKey())
{
col.setAsPrimaryKey();
}
if (datastoreContainer.getStoreManager().isStrategyDatastoreAttributed(fmd.getValueStrategy(), false))
{
if (datastoreContainer instanceof DatastoreClass)
{
if ((fmd.isPrimaryKey() && ((DatastoreClass)datastoreContainer).isBaseDatastoreClass()) || !fmd.isPrimaryKey())
{
// Increment any PK field if we are in base class, and increment any other field
col.setAutoIncrement(true);
}
}
}
if (fmd.getValueForExtension("select-function") != null)
{
col.setWrapperFunction(fmd.getValueForExtension("select-function"),Column.WRAPPER_FUNCTION_SELECT);
}
if (fmd.getValueForExtension("insert-function") != null)
{
col.setWrapperFunction(fmd.getValueForExtension("insert-function"),Column.WRAPPER_FUNCTION_INSERT);
}
if (fmd.getValueForExtension("update-function") != null)
{
col.setWrapperFunction(fmd.getValueForExtension("update-function"),Column.WRAPPER_FUNCTION_UPDATE);
}
setDatastoreFieldNullability(fmd, colmd, col);
if (fmd.getNullValue() == NullValue.DEFAULT)
{
// Users default should be applied if a null is to be inserted
col.setDefaultable();
if (colmd.getDefaultValue() != null)
{
col.setDefaultValue(colmd.getDefaultValue());
}
}
return col;
}