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