use of org.springframework.roo.classpath.details.FieldDetails in project spring-roo by spring-projects.
the class EmbeddableFieldCreatorProvider method createOtherField.
@Override
public void createOtherField(ClassOrInterfaceTypeDetails cid, JavaType fieldType, JavaSymbolName fieldName, boolean notNull, boolean nullRequired, String comment, String column, boolean permitReservedWords, boolean transientModifier, List<AnnotationMetadataBuilder> extraAnnotations) {
final String physicalTypeIdentifier = cid.getDeclaredByMetadataId();
final FieldDetails fieldDetails = new FieldDetails(physicalTypeIdentifier, fieldType, fieldName);
fieldDetails.setNotNull(notNull);
fieldDetails.setNullRequired(nullRequired);
if (comment != null) {
fieldDetails.setComment(comment);
}
if (column != null) {
fieldDetails.setColumn(column);
}
if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
fieldDetails.addAnnotations(extraAnnotations);
}
insertField(fieldDetails, permitReservedWords, transientModifier);
}
use of org.springframework.roo.classpath.details.FieldDetails in project spring-roo by spring-projects.
the class JpaFieldCreatorProvider method createOtherField.
@Override
public void createOtherField(ClassOrInterfaceTypeDetails cid, JavaType fieldType, JavaSymbolName fieldName, boolean notNull, boolean nullRequired, String comment, String column, boolean permitReservedWords, boolean transientModifier, List<AnnotationMetadataBuilder> extraAnnotations) {
final String physicalTypeIdentifier = cid.getDeclaredByMetadataId();
final FieldDetails fieldDetails = new FieldDetails(physicalTypeIdentifier, fieldType, fieldName);
fieldDetails.setNotNull(notNull);
fieldDetails.setNullRequired(nullRequired);
if (comment != null) {
fieldDetails.setComment(comment);
}
if (column != null) {
fieldDetails.setColumn(column);
}
if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
fieldDetails.addAnnotations(extraAnnotations);
}
insertField(fieldDetails, permitReservedWords, transientModifier);
}
use of org.springframework.roo.classpath.details.FieldDetails in project spring-roo by spring-projects.
the class JpaAuditOperationsImpl method getCreatedByField.
/**
* Builds createdBy field for storing user who creates entity registers
*
* @return FieldMetadataBuilder
*/
private FieldMetadataBuilder getCreatedByField(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);
}
AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.CREATED_BY);
annotations.add(createdDateAnnotation);
// Create field
FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JavaType.STRING, new JavaSymbolName("createdBy"));
fieldDetails.setModifiers(Modifier.PRIVATE);
fieldDetails.setAnnotations(annotations);
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
return fieldBuilder;
}
use of org.springframework.roo.classpath.details.FieldDetails in project spring-roo by spring-projects.
the class JpaAuditOperationsImpl method getModifiedByField.
/**
* Builds modifiedBy field for storing user who last modifies entity registers
*
* @return FieldMetadataBuilder
*/
private FieldMetadataBuilder getModifiedByField(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);
}
AnnotationMetadataBuilder createdDateAnnotation = new AnnotationMetadataBuilder(SpringJavaType.LAST_MODIFIED_BY);
annotations.add(createdDateAnnotation);
// Create field
FieldDetails fieldDetails = new FieldDetails(PhysicalTypeIdentifier.createIdentifier(entityDetails), JavaType.STRING, new JavaSymbolName("modifiedBy"));
fieldDetails.setModifiers(Modifier.PRIVATE);
fieldDetails.setAnnotations(annotations);
FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
return fieldBuilder;
}
use of org.springframework.roo.classpath.details.FieldDetails in project spring-roo by spring-projects.
the class JpaOperationsImpl method getVersionField.
/**
* This method generates the version field using the provided values
*
* @param entity
* @param versionField
* @param versionType
* @param versionColumn
* @return
*/
private FieldMetadata getVersionField(final JavaType entity, String versionField, final JavaType versionType, final String versionColumn) {
if (StringUtils.isEmpty(versionField)) {
versionField = "version";
}
final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
annotations.add(new AnnotationMetadataBuilder(VERSION));
if (StringUtils.isNotEmpty(versionColumn)) {
final AnnotationMetadataBuilder columnBuilder = new AnnotationMetadataBuilder(COLUMN);
columnBuilder.addStringAttribute("name", versionColumn);
annotations.add(columnBuilder);
}
FieldDetails versionFieldDetails = new FieldDetails(getTypeLocationService().getPhysicalTypeIdentifier(entity), versionType, new JavaSymbolName(versionField));
versionFieldDetails.setModifiers(Modifier.PRIVATE);
versionFieldDetails.addAnnotations(annotations);
return new FieldMetadataBuilder(versionFieldDetails).build();
}
Aggregations