Search in sources :

Example 1 with StringField

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

the class DtoFieldCreatorProvider 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, false);
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) 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 2 with StringField

use of org.springframework.roo.classpath.operations.jsr303.StringField 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 3 with StringField

use of org.springframework.roo.classpath.operations.jsr303.StringField 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

AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)3 StringField (org.springframework.roo.classpath.operations.jsr303.StringField)3 EnumDetails (org.springframework.roo.model.EnumDetails)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3 JavaType (org.springframework.roo.model.JavaType)3 JdkJavaType (org.springframework.roo.model.JdkJavaType)3 RooJavaType (org.springframework.roo.model.RooJavaType)3 JpaJavaType (org.springframework.roo.model.JpaJavaType)2 RooEnumDetails (org.springframework.roo.model.RooEnumDetails)1 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)1