use of javax.jdo.metadata.JoinMetadata in project motech by motech.
the class EntityMetadataBuilderImpl method setMapMetadata.
private FieldMetadata setMapMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field, Class<?> definition, EntityType entityType) {
FieldMetadata fmd = cmd.newFieldMetadata(getNameForMetadata(field));
MetadataDto keyMetadata = field.getMetadata(MAP_KEY_TYPE);
MetadataDto valueMetadata = field.getMetadata(MAP_VALUE_TYPE);
boolean serialized = shouldSerializeMap(keyMetadata, valueMetadata);
// Depending on the types of key and value of the map we either serialize the map or create a separate table for it
fmd.setSerialized(serialized);
addDefaultFetchGroupMetadata(fmd, definition);
MapMetadata mmd = fmd.newMapMetadata();
if (serialized) {
mmd.setSerializedKey(true);
mmd.setSerializedValue(true);
} else {
mmd.setKeyType(keyMetadata.getValue());
mmd.setValueType(valueMetadata.getValue());
fmd.setTable(ClassTableName.getTableName(cmd.getTable(), getNameForMetadata(field)));
JoinMetadata jmd = fmd.newJoinMetadata();
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jmd);
fkmd.setDeleteAction(ForeignKeyAction.CASCADE);
fkmd.setName(KeyNames.mapForeignKeyName(entity.getName(), entity.getId(), field.getBasic().getName(), entityType));
}
return fmd;
}
Aggregations