Search in sources :

Example 1 with JoinMetadata

use of javax.jdo.metadata.JoinMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method fixDuplicateColumnDefinitions.

private void fixDuplicateColumnDefinitions(MemberMetadata mmd) {
    JoinMetadata jmd = mmd.getJoinMetadata();
    ElementMetadata emd = mmd.getElementMetadata();
    if (jmd != null && ArrayUtils.isNotEmpty(jmd.getColumns()) && StringUtils.isNotEmpty(jmd.getColumn())) {
        jmd.setColumn(null);
    }
    if (emd != null && ArrayUtils.isNotEmpty(emd.getColumns()) && StringUtils.isNotEmpty(emd.getColumn())) {
        emd.setColumn(null);
    }
}
Also used : ElementMetadata(javax.jdo.metadata.ElementMetadata) JoinMetadata(javax.jdo.metadata.JoinMetadata)

Example 2 with JoinMetadata

use of javax.jdo.metadata.JoinMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method processHistoryTrashRelationship.

private void processHistoryTrashRelationship(ClassMetadata cmd, FieldMetadata fmd, RelationshipHolder holder) {
    if (holder.isOneToOne() || holder.isManyToOne()) {
        fmd.setColumn(holder.getFieldName() + ID_SUFFIX);
    } else {
        fmd.setTable(cmd.getTable() + '_' + holder.getFieldName());
        CollectionMetadata collMd = fmd.newCollectionMetadata();
        collMd.setElementType(Long.class.getName());
        JoinMetadata joinMd = fmd.newJoinMetadata();
        ColumnMetadata joinColumnMd = joinMd.newColumnMetadata();
        joinColumnMd.setName(cmd.getName() + ID_SUFFIX);
        ElementMetadata elementMd = fmd.newElementMetadata();
        elementMd.setColumn(holder.getFieldName() + ID_SUFFIX);
    }
}
Also used : CollectionMetadata(javax.jdo.metadata.CollectionMetadata) ColumnMetadata(javax.jdo.metadata.ColumnMetadata) ElementMetadata(javax.jdo.metadata.ElementMetadata) JoinMetadata(javax.jdo.metadata.JoinMetadata)

Example 3 with JoinMetadata

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

Example 4 with JoinMetadata

use of javax.jdo.metadata.JoinMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method setComboboxMetadata.

private FieldMetadata setComboboxMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field, Class<?> definition, EntityType entityType) {
    ComboboxHolder holder = new ComboboxHolder(entity, field);
    String fieldName = getNameForMetadata(field);
    FieldMetadata fmd = cmd.newFieldMetadata(fieldName);
    if (holder.isCollection()) {
        addDefaultFetchGroupMetadata(fmd, definition);
        fmd.setTable(ClassTableName.getTableName(cmd.getTable(), fieldName));
        JoinMetadata jm = fmd.newJoinMetadata();
        ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jm);
        fkmd.setName(KeyNames.cbForeignKeyName(entity.getName(), entity.getId(), fieldName, entityType));
        jm.setDeleteAction(ForeignKeyAction.CASCADE);
        jm.newColumnMetadata().setName(fieldName + "_OID");
    }
    return fmd;
}
Also used : FieldMetadata(javax.jdo.metadata.FieldMetadata) ForeignKeyMetadata(javax.jdo.metadata.ForeignKeyMetadata) ComboboxHolder(org.motechproject.mds.domain.ComboboxHolder) JoinMetadata(javax.jdo.metadata.JoinMetadata)

Example 5 with JoinMetadata

use of javax.jdo.metadata.JoinMetadata in project motech by motech.

the class EntityMetadataBuilderImpl method setJoinMetadata.

private void setJoinMetadata(JoinMetadata jmd, FieldMetadata fmd, String column) {
    JoinMetadata joinMetadata;
    if (jmd == null) {
        joinMetadata = fmd.newJoinMetadata();
        joinMetadata.setOuter(false);
    } else {
        joinMetadata = jmd;
    }
    joinMetadata.newColumnMetadata().setName(column);
}
Also used : JoinMetadata(javax.jdo.metadata.JoinMetadata)

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