Search in sources :

Example 1 with Element

use of javax.jdo.annotations.Element in project motech by motech.

the class EntityMetadataBuilderImpl method addManyToManyMetadata.

private void addManyToManyMetadata(FieldMetadata fmd, RelationshipHolder holder, EntityDto entity, FieldDto field, Class<?> definition) {
    // When using Lists join metadata must be present at two sides of M:N relation
    if (!holder.isOwningSide() || holder.isListManyToMany()) {
        java.lang.reflect.Field fieldDefinition = FieldUtils.getDeclaredField(definition, field.getBasic().getName(), true);
        Join join = fieldDefinition.getAnnotation(Join.class);
        Persistent persistent = fieldDefinition.getAnnotation(Persistent.class);
        Element element = fieldDefinition.getAnnotation(Element.class);
        JoinMetadata jmd = null;
        if (join == null) {
            jmd = fmd.newJoinMetadata();
        }
        setTableNameMetadata(fmd, persistent, entity, field, holder, EntityType.STANDARD);
        setElementMetadata(fmd, element, holder, entity);
        if (join == null || StringUtils.isEmpty(join.column())) {
            setJoinMetadata(jmd, fmd, ClassName.getSimpleName(entity.getClassName()).toUpperCase() + ID_SUFFIX);
            ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jmd);
            fkmd.setName(KeyNames.foreignKeyName(entity.getName(), entity.getId(), field.getBasic().getName(), EntityType.STANDARD));
        }
    }
}
Also used : ForeignKeyMetadata(javax.jdo.metadata.ForeignKeyMetadata) Element(javax.jdo.annotations.Element) Join(javax.jdo.annotations.Join) Persistent(javax.jdo.annotations.Persistent) JoinMetadata(javax.jdo.metadata.JoinMetadata)

Aggregations

Element (javax.jdo.annotations.Element)1 Join (javax.jdo.annotations.Join)1 Persistent (javax.jdo.annotations.Persistent)1 ForeignKeyMetadata (javax.jdo.metadata.ForeignKeyMetadata)1 JoinMetadata (javax.jdo.metadata.JoinMetadata)1