Search in sources :

Example 1 with FieldDetails

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);
}
Also used : FieldDetails(org.springframework.roo.classpath.details.FieldDetails)

Example 2 with FieldDetails

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);
}
Also used : FieldDetails(org.springframework.roo.classpath.details.FieldDetails)

Example 3 with FieldDetails

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;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 4 with FieldDetails

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;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 5 with FieldDetails

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();
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ArrayList(java.util.ArrayList) FieldDetails(org.springframework.roo.classpath.details.FieldDetails) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Aggregations

FieldDetails (org.springframework.roo.classpath.details.FieldDetails)10 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)7 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)7 ArrayList (java.util.ArrayList)6 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)6 EnumDetails (org.springframework.roo.model.EnumDetails)3 JavaType (org.springframework.roo.model.JavaType)2 JdkJavaType (org.springframework.roo.model.JdkJavaType)2 RooJavaType (org.springframework.roo.model.RooJavaType)2 Entry (java.util.Map.Entry)1 IdentifierStrategy (org.springframework.roo.addon.jpa.addon.entity.IdentifierStrategy)1 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)1 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)1 CollectionField (org.springframework.roo.classpath.operations.jsr303.CollectionField)1 DateField (org.springframework.roo.classpath.operations.jsr303.DateField)1 ListField (org.springframework.roo.classpath.operations.jsr303.ListField)1 SetField (org.springframework.roo.classpath.operations.jsr303.SetField)1 JpaJavaType (org.springframework.roo.model.JpaJavaType)1 Dependency (org.springframework.roo.project.Dependency)1