Search in sources :

Example 1 with MapMetadata

use of javax.jdo.metadata.MapMetadata 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

FieldMetadata (javax.jdo.metadata.FieldMetadata)1 ForeignKeyMetadata (javax.jdo.metadata.ForeignKeyMetadata)1 JoinMetadata (javax.jdo.metadata.JoinMetadata)1 MapMetadata (javax.jdo.metadata.MapMetadata)1 MetadataDto (org.motechproject.mds.dto.MetadataDto)1