Search in sources :

Example 11 with EnumDetails

use of org.springframework.roo.model.EnumDetails in project spring-roo by spring-projects.

the class EnumField method decorateAnnotationsList.

@Override
public void decorateAnnotationsList(final List<AnnotationMetadataBuilder> annotations) {
    super.decorateAnnotationsList(annotations);
    final List<AnnotationAttributeValue<?>> attributes = new ArrayList<AnnotationAttributeValue<?>>();
    if (enumType != null) {
        JavaSymbolName value = new JavaSymbolName("ORDINAL");
        if (enumType == EnumType.STRING) {
            value = new JavaSymbolName("STRING");
        }
        attributes.add(new EnumAttributeValue(new JavaSymbolName("value"), new EnumDetails(ENUM_TYPE, value)));
    }
    annotations.add(new AnnotationMetadataBuilder(ENUMERATED, attributes));
}
Also used : AnnotationAttributeValue(org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) EnumAttributeValue(org.springframework.roo.classpath.details.annotations.EnumAttributeValue) EnumDetails(org.springframework.roo.model.EnumDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 12 with EnumDetails

use of org.springframework.roo.model.EnumDetails in project spring-roo by spring-projects.

the class JpaAuditOperationsImpl method getCreatedDateField.

/**
 * Builds createdDate field for storing entity's created date
 *
 * @return FieldMetadataBuilder
 */
private FieldMetadataBuilder getCreatedDateField(ClassOrInterfaceTypeDetails entityDetails, String columnName) {
    // Create field annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    // Only add @Column if required by annotation @RooJpaAudit
    if (StringUtils.isNotBlank(columnName)) {
        AnnotationMetadataBuilder columnAnnotation = new AnnotationMetadataBuilder(JpaJavaType.COLUMN);
        columnAnnotation.addStringAttribute("name", columnName);
        annotations.add(columnAnnotation);
    }
    // Add @CreatedDate
    AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.CREATED_DATE);
    annotations.add(createdDateAnnotation);
    // Add @Temporal
    AnnotationMetadataBuilder temporalAnnotation = new AnnotationMetadataBuilder(JpaJavaType.TEMPORAL);
    temporalAnnotation.addEnumAttribute("value", new EnumDetails(JpaJavaType.TEMPORAL_TYPE, new JavaSymbolName("TIMESTAMP")));
    annotations.add(temporalAnnotation);
    // Add @DateTimeFormat
    AnnotationMetadataBuilder dateTimeFormatAnnotation = new AnnotationMetadataBuilder(SpringJavaType.DATE_TIME_FORMAT);
    dateTimeFormatAnnotation.addStringAttribute("style", "M-");
    annotations.add(dateTimeFormatAnnotation);
    // Create field
    FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JdkJavaType.CALENDAR, new JavaSymbolName("createdDate"));
    fieldDetails.setModifiers(Modifier.PRIVATE);
    fieldDetails.setAnnotations(annotations);
    FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
    return fieldBuilder;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) EnumDetails(org.springframework.roo.model.EnumDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 13 with EnumDetails

use of org.springframework.roo.model.EnumDetails in project spring-roo by spring-projects.

the class JpaAuditOperationsImpl method getModifiedDateField.

/**
 * Builds modifiedDate field for storing entity's last modified date
 *
 * @return FieldMetadataBuilder
 */
private FieldMetadataBuilder getModifiedDateField(ClassOrInterfaceTypeDetails entityDetails, String columnName) {
    // Create field annotations
    List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    // Only add @Column if required by annotation @RooJpaAudit
    if (StringUtils.isNotBlank(columnName)) {
        AnnotationMetadataBuilder columnAnnotation = new AnnotationMetadataBuilder(JpaJavaType.COLUMN);
        columnAnnotation.addStringAttribute("name", columnName);
        annotations.add(columnAnnotation);
    }
    // Add @LastModifiedDate
    AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.LAST_MODIFIED_DATE);
    annotations.add(createdDateAnnotation);
    // Add @Temporal
    AnnotationMetadataBuilder temporalAnnotation = new AnnotationMetadataBuilder(JpaJavaType.TEMPORAL);
    temporalAnnotation.addEnumAttribute("value", new EnumDetails(JpaJavaType.TEMPORAL_TYPE, new JavaSymbolName("TIMESTAMP")));
    annotations.add(temporalAnnotation);
    // Add @DateTimeFormat
    AnnotationMetadataBuilder dateTimeFormatAnnotation = new AnnotationMetadataBuilder(SpringJavaType.DATE_TIME_FORMAT);
    dateTimeFormatAnnotation.addStringAttribute("style", "M-");
    annotations.add(dateTimeFormatAnnotation);
    // Create field
    FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JdkJavaType.CALENDAR, new JavaSymbolName("modifiedDate"));
    fieldDetails.setModifiers(Modifier.PRIVATE);
    fieldDetails.setAnnotations(annotations);
    FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
    return fieldBuilder;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) EnumDetails(org.springframework.roo.model.EnumDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 14 with EnumDetails

use of org.springframework.roo.model.EnumDetails in project spring-roo by spring-projects.

the class EmbeddableFieldCreatorProvider method createStringField.

@Override
public void createStringField(ClassOrInterfaceTypeDetails cid, JavaSymbolName fieldName, boolean notNull, boolean nullRequired, String decimalMin, String decimalMax, Integer sizeMin, Integer sizeMax, String regexp, String column, String comment, boolean unique, String value, boolean lob, boolean permitReservedWords, boolean transientModifier, List<AnnotationMetadataBuilder> extraAnnotations) {
    final String physicalTypeIdentifier = cid.getDeclaredByMetadataId();
    final StringField fieldDetails = new StringField(physicalTypeIdentifier, fieldName);
    fieldDetails.setNotNull(notNull);
    fieldDetails.setNullRequired(nullRequired);
    if (decimalMin != null) {
        fieldDetails.setDecimalMin(decimalMin);
    }
    if (decimalMax != null) {
        fieldDetails.setDecimalMax(decimalMax);
    }
    if (sizeMin != null) {
        fieldDetails.setSizeMin(sizeMin);
    }
    if (sizeMax != null) {
        fieldDetails.setSizeMax(sizeMax);
    }
    if (regexp != null) {
        fieldDetails.setRegexp(regexp.replace("\\", "\\\\"));
    }
    if (column != null) {
        fieldDetails.setColumn(column);
    }
    if (comment != null) {
        fieldDetails.setComment(comment);
    }
    if (unique) {
        fieldDetails.setUnique(true);
    }
    if (value != null) {
        fieldDetails.setValue(value);
    }
    if (lob) {
        fieldDetails.getInitedAnnotations().add(new AnnotationMetadataBuilder("javax.persistence.Lob"));
        // ROO-3722: Add LAZY load in @Lob fields using @Basic
        AnnotationMetadataBuilder basicAnnotation = new AnnotationMetadataBuilder("javax.persistence.Basic");
        basicAnnotation.addEnumAttribute("fetch", new EnumDetails(new JavaType("javax.persistence.FetchType"), new JavaSymbolName("LAZY")));
        fieldDetails.getInitedAnnotations().add(basicAnnotation);
    }
    if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
        fieldDetails.addAnnotations(extraAnnotations);
    }
    insertField(fieldDetails, permitReservedWords, transientModifier);
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) StringField(org.springframework.roo.classpath.operations.jsr303.StringField) EnumDetails(org.springframework.roo.model.EnumDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 15 with EnumDetails

use of org.springframework.roo.model.EnumDetails in project spring-roo by spring-projects.

the class JpaFieldCreatorProvider method createStringField.

@Override
public void createStringField(ClassOrInterfaceTypeDetails cid, JavaSymbolName fieldName, boolean notNull, boolean nullRequired, String decimalMin, String decimalMax, Integer sizeMin, Integer sizeMax, String regexp, String column, String comment, boolean unique, String value, boolean lob, boolean permitReservedWords, boolean transientModifier, List<AnnotationMetadataBuilder> extraAnnotations) {
    final String physicalTypeIdentifier = cid.getDeclaredByMetadataId();
    final StringField fieldDetails = new StringField(physicalTypeIdentifier, fieldName);
    fieldDetails.setNotNull(notNull);
    fieldDetails.setNullRequired(nullRequired);
    if (decimalMin != null) {
        fieldDetails.setDecimalMin(decimalMin);
    }
    if (decimalMax != null) {
        fieldDetails.setDecimalMax(decimalMax);
    }
    if (sizeMin != null) {
        fieldDetails.setSizeMin(sizeMin);
    }
    if (sizeMax != null) {
        fieldDetails.setSizeMax(sizeMax);
    }
    if (regexp != null) {
        fieldDetails.setRegexp(regexp.replace("\\", "\\\\"));
    }
    if (column != null) {
        fieldDetails.setColumn(column);
    }
    if (comment != null) {
        fieldDetails.setComment(comment);
    }
    if (unique) {
        fieldDetails.setUnique(true);
    }
    if (value != null) {
        fieldDetails.setValue(value);
    }
    if (lob) {
        fieldDetails.getInitedAnnotations().add(new AnnotationMetadataBuilder("javax.persistence.Lob"));
        // ROO-3722: Add LAZY load in @Lob fields using @Basic
        AnnotationMetadataBuilder basicAnnotation = new AnnotationMetadataBuilder("javax.persistence.Basic");
        basicAnnotation.addEnumAttribute("fetch", new EnumDetails(new JavaType("javax.persistence.FetchType"), new JavaSymbolName("LAZY")));
        fieldDetails.getInitedAnnotations().add(basicAnnotation);
    }
    if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
        fieldDetails.addAnnotations(extraAnnotations);
    }
    insertField(fieldDetails, permitReservedWords, transientModifier);
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) StringField(org.springframework.roo.classpath.operations.jsr303.StringField) EnumDetails(org.springframework.roo.model.EnumDetails) RooEnumDetails(org.springframework.roo.model.RooEnumDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

EnumDetails (org.springframework.roo.model.EnumDetails)26 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)25 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)17 ArrayList (java.util.ArrayList)16 JavaType (org.springframework.roo.model.JavaType)12 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)11 EnumAttributeValue (org.springframework.roo.classpath.details.annotations.EnumAttributeValue)11 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)9 NestedAnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.NestedAnnotationAttributeValue)7 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)6 RooJavaType (org.springframework.roo.model.RooJavaType)6 ArrayAttributeValue (org.springframework.roo.classpath.details.annotations.ArrayAttributeValue)5 JdkJavaType (org.springframework.roo.model.JdkJavaType)5 List (java.util.List)4 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)4 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)3 FieldDetails (org.springframework.roo.classpath.details.FieldDetails)3 BooleanAttributeValue (org.springframework.roo.classpath.details.annotations.BooleanAttributeValue)3 ClassAttributeValue (org.springframework.roo.classpath.details.annotations.ClassAttributeValue)3 StringField (org.springframework.roo.classpath.operations.jsr303.StringField)3