Search in sources :

Example 1 with Cascade

use of org.springframework.roo.classpath.operations.Cascade in project spring-roo by spring-projects.

the class ReferenceField method decorateAnnotationsList.

@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
    super.decorateAnnotationsList(annotations);
    final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
    // Add cascade if option exists
    if (cascadeType != null) {
        List<EnumAttributeValue> cascadeValues = new ArrayList<EnumAttributeValue>();
        for (Cascade type : cascadeType) {
            cascadeValues.add(new EnumAttributeValue(new JavaSymbolName("cascade"), new EnumDetails(CASCADE_TYPE, new JavaSymbolName(type.name()))));
        }
        attributes.add(new ArrayAttributeValue<EnumAttributeValue>(new JavaSymbolName("cascade"), cascadeValues));
    }
    // Add orphanRemoval if option exists
    if (getOrphanRemoval() != null) {
        attributes.add(new BooleanAttributeValue(new JavaSymbolName("orphanRemoval"), getOrphanRemoval().booleanValue()));
    }
    if (fetch != null) {
        JavaSymbolName value = new JavaSymbolName("EAGER");
        if (fetch == Fetch.LAZY) {
            value = new JavaSymbolName("LAZY");
        }
        attributes.add(new EnumAttributeValue(new JavaSymbolName("fetch"), new EnumDetails(FETCH_TYPE, value)));
    }
    if (mappedBy != null) {
        attributes.add(new StringAttributeValue(new JavaSymbolName("mappedBy"), mappedBy.getSymbolName()));
    }
    switch(cardinality) {
        case ONE_TO_MANY:
            annotations.add(new AnnotationMetadataBuilder(ONE_TO_MANY, attributes));
            break;
        case MANY_TO_MANY:
            annotations.add(new AnnotationMetadataBuilder(MANY_TO_MANY, attributes));
            break;
        case ONE_TO_ONE:
            annotations.add(new AnnotationMetadataBuilder(ONE_TO_ONE, attributes));
            break;
        default:
            annotations.add(new AnnotationMetadataBuilder(MANY_TO_ONE, attributes));
            break;
    }
    // Add additional annotations (if any)
    if (additionaAnnotations != null) {
        annotations.addAll(additionaAnnotations);
    }
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) NestedAnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) BooleanAttributeValue(org.springframework.roo.classpath.details.annotations.BooleanAttributeValue) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) StringAttributeValue(org.springframework.roo.classpath.details.annotations.StringAttributeValue) Cascade(org.springframework.roo.classpath.operations.Cascade) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

ArrayList (java.util.ArrayList)1 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)1 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)1 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)1 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)1 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)1 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)1 Cascade (org.springframework.roo.classpath.operations.Cascade)1 EnumDetails (org.springframework.roo.model.EnumDetails)1 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)1