use of org.motechproject.mds.domain.RelationshipHolder in project motech by motech.
the class EntityMetadataBuilderImpl method fixRelationMetadata.
private void fixRelationMetadata(PackageMetadata pmd, EntityDto entity, FieldDto field) {
RelationshipHolder holder = new RelationshipHolder(field);
// this must be set here cause we can't get related class metadata before metadata enhancement
if (shouldSetCascadeDelete(holder, EntityType.STANDARD)) {
String relatedClass = ClassName.getSimpleName(holder.getRelatedClass());
MemberMetadata rfmd = getFieldMetadata(getClassMetadata(pmd, relatedClass), holder.getRelatedField());
ForeignKeyMetadata rfkmd = getOrCreateRelFkMetadata(rfmd, entity, field);
rfkmd.setDeleteAction(ForeignKeyAction.CASCADE);
}
}
use of org.motechproject.mds.domain.RelationshipHolder in project motech by motech.
the class LookupBuilder method body.
private String body() {
StringBuilder body = new StringBuilder();
body.append("java.util.List properties = new java.util.ArrayList();");
Map<String, String> jdoQueryVariables = new HashMap<>();
for (String lookupFieldName : lookup.getFieldsOrder()) {
boolean appendJdoVariableName = false;
FieldDto field = getLookupField(lookupFieldName);
// don't use lookupFieldName for fetching fields, as it can contain dots, etc.
LookupFieldDto lookupField = lookup.getLookupField(field.getBasic().getName());
FieldDto relationField = null;
if (lookupFieldName.contains(".")) {
EntityDto relatedEntity = schemaHolder.getEntityByClassName(new RelationshipHolder(field).getRelatedClass());
relationField = schemaHolder.getFieldByName(relatedEntity, LookupName.getRelatedFieldName(lookupFieldName));
}
TypeDto type = field.getType();
String typeClassName = resolveClassName(type, relationField);
body.append("properties.add(");
if (type.isCombobox()) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
typeClassName = holder.getUnderlyingType();
body.append(resolvePropertyForCombobox(holder, type));
} else if (relationField != null && relationField.getType().isCombobox()) {
RelationshipHolder relationshipHolder = new RelationshipHolder(field);
EntityDto relatedEntity = schemaHolder.getEntityByClassName(relationshipHolder.getRelatedClass());
ComboboxHolder holder = new ComboboxHolder(relatedEntity, relationField);
typeClassName = holder.getUnderlyingType();
body.append(resolvePropertyForCombobox(holder, type));
addJdoVariableName(jdoQueryVariables, lookupFieldName);
appendJdoVariableName = needsJdoVariable(type);
} else if (relationField != null && (type.getTypeClass().equals(TypeDto.MANY_TO_MANY_RELATIONSHIP.getTypeClass()) || type.getTypeClass().equals(TypeDto.ONE_TO_MANY_RELATIONSHIP.getTypeClass()))) {
// related class collection
body.append(PropertyBuilder.class.getName());
body.append(".createRelationProperty");
addJdoVariableName(jdoQueryVariables, lookupFieldName);
appendJdoVariableName = true;
} else {
body.append(PropertyBuilder.class.getName());
body.append(".create");
}
body.append(buildPropertyParameters(appendJdoVariableName, lookupFieldName, lookupField, typeClassName, jdoQueryVariables));
}
body.append(buildReturn());
return body.toString();
}
Aggregations