{
modifier = FieldPersistenceModifier.PERSISTENT.toString();
}
// Create the field
AbstractMemberMetaData fmd;
if (field.isProperty())
{
fmd = mgr.getMetaDataFactory().newPropertyObject(cmd, field.getName(), pk, modifier, dfg, nullValue,
embedded, null, null, mappedBy, null, null, null, null, null, null, null, null, null,
null, null, null, null);
}
else
{
fmd = mgr.getMetaDataFactory().newFieldObject(cmd, field.getName(), pk, modifier, dfg, nullValue,
embedded, null, null, mappedBy, null, null, null, null, null, null, null, null, null,
null, null, null);
}
if (version != null)
{
// Tag this field as the version field
VersionMetaData vermd = new VersionMetaData(VersionStrategy.VERSION_NUMBER.toString(), fmd.getName());
cmd.setVersionMetaData(vermd);
}
cmd.addMember(fmd);
if (cascades != null)
{
for (int i = 0; i < cascades.length; i++)
{
if (cascades[i] == CascadeType.ALL)
{
fmd.setCascadePersist(true);
fmd.setCascadeUpdate(true);
fmd.setCascadeDelete(true);
fmd.setCascadeRefresh(true);
}
else if (cascades[i] == CascadeType.PERSIST)
{
fmd.setCascadePersist(true);
}
else if (cascades[i] == CascadeType.MERGE)
{
fmd.setCascadeUpdate(true);
}
else if (cascades[i] == CascadeType.REMOVE)
{
fmd.setCascadeDelete(true);
}
else if (cascades[i] == CascadeType.REFRESH)
{
fmd.setCascadeRefresh(true);
}
}
}
// Value generation
if (valueStrategy != null && valueGenerator != null)
{
fmd.setValueGeneratorName(valueGenerator);
}
if (valueStrategy != null)
{
fmd.setValueStrategy(IdentityStrategy.getIdentityStrategy(valueStrategy));
}
// Type storage
if (storeInLob)
{
fmd.setStoreInLob();
}
// Container fields : If the field is a container then add its container element
ContainerMetaData contmd = null;
if (Collection.class.isAssignableFrom(field.getType()))
{
String elementType = null;
if (targetEntity != null && targetEntity != void.class)
{
elementType = targetEntity.getName();
}
if (elementType == null)
{
elementType = ClassUtils.getCollectionElementType(field.getType(),field.getGenericType());
}
// No annotation for collections so cant specify the element type, dependent, embedded, serialized
contmd = new CollectionMetaData(fmd, elementType, null, null, null);
}
else if (field.getType().isArray())
{
contmd = new ArrayMetaData(fmd, null, null, null, null);
}
else if (Map.class.isAssignableFrom(field.getType()))
{
String keyType = ClassUtils.getMapKeyType(field.getType(),field.getGenericType());
String valueType = null;
if (targetEntity != null && targetEntity != void.class)
{
valueType = targetEntity.getName();
}
if (valueType == null)
{
valueType = ClassUtils.getMapValueType(field.getType(),field.getGenericType());
}
// No annotation for maps so cant specify the key/value type, dependent, embedded, serialized
contmd = new MapMetaData(fmd, keyType, null, null, null, valueType, null, null, null);
}
if (contmd != null)
{
fmd.setContainer(contmd);
}
// JPOX extensions
if (extensions != null)
{
Iterator<ExtensionMetaData> iter = extensions.iterator();
while (iter.hasNext())
{
ExtensionMetaData extmd = iter.next();
fmd.addExtension(extmd.getVendorName(), extmd.getKey(), extmd.getValue());
}
}
return fmd;
}