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);
}
}
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);
}
}
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));
}
}
}
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;
}
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);
}
Aggregations