Search in sources :

Example 6 with JoinMetadata

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;
}
Also used : FieldMetadata(javax.jdo.metadata.FieldMetadata) ForeignKeyMetadata(javax.jdo.metadata.ForeignKeyMetadata) JoinMetadata(javax.jdo.metadata.JoinMetadata) MetadataDto(org.motechproject.mds.dto.MetadataDto) MapMetadata(javax.jdo.metadata.MapMetadata)

Aggregations

JoinMetadata (javax.jdo.metadata.JoinMetadata)6 ForeignKeyMetadata (javax.jdo.metadata.ForeignKeyMetadata)3 ElementMetadata (javax.jdo.metadata.ElementMetadata)2 FieldMetadata (javax.jdo.metadata.FieldMetadata)2 Element (javax.jdo.annotations.Element)1 Join (javax.jdo.annotations.Join)1 Persistent (javax.jdo.annotations.Persistent)1 CollectionMetadata (javax.jdo.metadata.CollectionMetadata)1 ColumnMetadata (javax.jdo.metadata.ColumnMetadata)1 MapMetadata (javax.jdo.metadata.MapMetadata)1 ComboboxHolder (org.motechproject.mds.domain.ComboboxHolder)1 MetadataDto (org.motechproject.mds.dto.MetadataDto)1