Search in sources :

Example 1 with DateField

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

the class JpaFieldCreatorProvider method createDateField.

@Override
public void createDateField(ClassOrInterfaceTypeDetails javaTypeDetails, JavaType fieldType, JavaSymbolName fieldName, boolean notNull, boolean nullRequired, boolean future, boolean past, DateFieldPersistenceType persistenceType, String column, String comment, DateTime dateFormat, DateTime timeFormat, String pattern, String value, boolean permitReservedWords, boolean transientModifier, List<AnnotationMetadataBuilder> extraAnnotations) {
    final String physicalTypeIdentifier = javaTypeDetails.getDeclaredByMetadataId();
    final DateField fieldDetails = new DateField(physicalTypeIdentifier, fieldType, fieldName);
    fieldDetails.setNotNull(notNull);
    fieldDetails.setNullRequired(nullRequired);
    fieldDetails.setFuture(future);
    fieldDetails.setPast(past);
    if (JdkJavaType.isDateField(fieldType)) {
        fieldDetails.setPersistenceType(persistenceType != null ? persistenceType : DateFieldPersistenceType.JPA_TIMESTAMP);
    }
    if (column != null) {
        fieldDetails.setColumn(column);
    }
    if (comment != null) {
        fieldDetails.setComment(comment);
    }
    if (dateFormat != null) {
        fieldDetails.setDateFormat(dateFormat);
    }
    if (timeFormat != null) {
        fieldDetails.setTimeFormat(timeFormat);
    }
    if (pattern != null) {
        fieldDetails.setPattern(pattern);
    }
    if (value != null) {
        fieldDetails.setValue(value);
    }
    if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
        fieldDetails.addAnnotations(extraAnnotations);
    }
    insertField(fieldDetails, permitReservedWords, transientModifier);
}
Also used : DateField(org.springframework.roo.classpath.operations.jsr303.DateField)

Example 2 with DateField

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

the class DtoFieldCreatorProvider method insertField.

public void insertField(final FieldDetails fieldDetails, final boolean permitReservedWords, final boolean transientModifier) {
    String module = null;
    if (!permitReservedWords) {
        ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getFieldName());
        if (fieldDetails.getColumn() != null) {
            ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getColumn());
        }
    }
    final List<AnnotationMetadataBuilder> annotations = fieldDetails.getInitedAnnotations();
    fieldDetails.decorateAnnotationsList(annotations);
    fieldDetails.setAnnotations(annotations);
    if (fieldDetails.getFieldType() != null) {
        module = fieldDetails.getFieldType().getModule();
    }
    fieldDetails.setModifiers(Modifier.PRIVATE);
    String initializer = null;
    if (fieldDetails instanceof CollectionField) {
        final CollectionField collectionField = (CollectionField) fieldDetails;
        module = collectionField.getGenericParameterTypeName().getModule();
        initializer = "new " + collectionField.getInitializer() + "()";
    } else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
        initializer = "new Date()";
    }
    // Format the passed-in comment (if given)
    formatFieldComment(fieldDetails);
    final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
    fieldBuilder.setFieldInitializer(initializer);
    typeManagementService.addField(fieldBuilder.build());
    if (module != null) {
        projectOperations.addModuleDependency(module);
    }
}
Also used : DateField(org.springframework.roo.classpath.operations.jsr303.DateField) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) CollectionField(org.springframework.roo.classpath.operations.jsr303.CollectionField) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 3 with DateField

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

the class EmbeddableFieldCreatorProvider method insertField.

public void insertField(final FieldDetails fieldDetails, final boolean permitReservedWords, final boolean transientModifier) {
    String module = null;
    if (!permitReservedWords) {
        ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getFieldName());
        if (fieldDetails.getColumn() != null) {
            ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getColumn());
        }
    }
    final List<AnnotationMetadataBuilder> annotations = fieldDetails.getInitedAnnotations();
    fieldDetails.decorateAnnotationsList(annotations);
    fieldDetails.setAnnotations(annotations);
    if (fieldDetails.getFieldType() != null) {
        module = fieldDetails.getFieldType().getModule();
    }
    String initializer = null;
    if (fieldDetails instanceof CollectionField) {
        final CollectionField collectionField = (CollectionField) fieldDetails;
        module = collectionField.getGenericParameterTypeName().getModule();
        initializer = "new " + collectionField.getInitializer() + "()";
    } else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
        initializer = "new Date()";
    }
    int modifier = Modifier.PRIVATE;
    if (transientModifier) {
        modifier += Modifier.TRANSIENT;
    }
    fieldDetails.setModifiers(modifier);
    // Format the passed-in comment (if given)
    formatFieldComment(fieldDetails);
    final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
    fieldBuilder.setFieldInitializer(initializer);
    typeManagementService.addField(fieldBuilder.build());
    if (module != null) {
        projectOperations.addModuleDependency(module);
    }
}
Also used : DateField(org.springframework.roo.classpath.operations.jsr303.DateField) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) CollectionField(org.springframework.roo.classpath.operations.jsr303.CollectionField) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Example 4 with DateField

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

the class EmbeddableFieldCreatorProvider method createDateField.

@Override
public void createDateField(ClassOrInterfaceTypeDetails javaTypeDetails, JavaType fieldType, JavaSymbolName fieldName, boolean notNull, boolean nullRequired, boolean future, boolean past, DateFieldPersistenceType persistenceType, String column, String comment, DateTime dateFormat, DateTime timeFormat, String pattern, String value, boolean permitReservedWords, boolean transientModifier, List<AnnotationMetadataBuilder> extraAnnotations) {
    final String physicalTypeIdentifier = javaTypeDetails.getDeclaredByMetadataId();
    final DateField fieldDetails = new DateField(physicalTypeIdentifier, fieldType, fieldName);
    fieldDetails.setNotNull(notNull);
    fieldDetails.setNullRequired(nullRequired);
    fieldDetails.setFuture(future);
    fieldDetails.setPast(past);
    if (JdkJavaType.isDateField(fieldType)) {
        fieldDetails.setPersistenceType(persistenceType != null ? persistenceType : DateFieldPersistenceType.JPA_TIMESTAMP);
    }
    if (column != null) {
        fieldDetails.setColumn(column);
    }
    if (comment != null) {
        fieldDetails.setComment(comment);
    }
    if (dateFormat != null) {
        fieldDetails.setDateFormat(dateFormat);
    }
    if (timeFormat != null) {
        fieldDetails.setTimeFormat(timeFormat);
    }
    if (pattern != null) {
        fieldDetails.setPattern(pattern);
    }
    if (value != null) {
        fieldDetails.setValue(value);
    }
    if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
        fieldDetails.addAnnotations(extraAnnotations);
    }
    insertField(fieldDetails, permitReservedWords, transientModifier);
}
Also used : DateField(org.springframework.roo.classpath.operations.jsr303.DateField)

Example 5 with DateField

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

the class JpaFieldCreatorProvider method generateFieldBuilder.

/**
 * Generates Field builder based on fieldDetails
 *
 * @param fieldDetails
 * @param permitReservedWords
 * @param transientModifier
 * @return
 */
private FieldMetadataBuilder generateFieldBuilder(final FieldDetails fieldDetails, final boolean permitReservedWords, final boolean transientModifier) {
    if (!permitReservedWords) {
        ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getFieldName());
        if (fieldDetails.getColumn() != null) {
            ReservedWords.verifyReservedWordsNotPresent(fieldDetails.getColumn());
        }
    }
    final List<AnnotationMetadataBuilder> annotations = fieldDetails.getInitedAnnotations();
    fieldDetails.decorateAnnotationsList(annotations);
    fieldDetails.setAnnotations(annotations);
    String initializer = null;
    if (fieldDetails instanceof CollectionField) {
        final CollectionField collectionField = (CollectionField) fieldDetails;
        initializer = "new " + collectionField.getInitializer() + "()";
    } else if (fieldDetails instanceof DateField && fieldDetails.getFieldName().getSymbolName().equals("created")) {
        initializer = "new Date()";
    }
    int modifier = Modifier.PRIVATE;
    if (transientModifier) {
        modifier += Modifier.TRANSIENT;
    }
    fieldDetails.setModifiers(modifier);
    // Format the passed-in comment (if given)
    formatFieldComment(fieldDetails);
    final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(fieldDetails);
    fieldBuilder.setFieldInitializer(initializer);
    return fieldBuilder;
}
Also used : DateField(org.springframework.roo.classpath.operations.jsr303.DateField) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder) CollectionField(org.springframework.roo.classpath.operations.jsr303.CollectionField) FieldMetadataBuilder(org.springframework.roo.classpath.details.FieldMetadataBuilder)

Aggregations

DateField (org.springframework.roo.classpath.operations.jsr303.DateField)7 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)4 CollectionField (org.springframework.roo.classpath.operations.jsr303.CollectionField)4 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)3 Entry (java.util.Map.Entry)1 FieldDetails (org.springframework.roo.classpath.details.FieldDetails)1 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)1 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)1 ListField (org.springframework.roo.classpath.operations.jsr303.ListField)1 SetField (org.springframework.roo.classpath.operations.jsr303.SetField)1 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)1 JavaType (org.springframework.roo.model.JavaType)1 JdkJavaType (org.springframework.roo.model.JdkJavaType)1 JpaJavaType (org.springframework.roo.model.JpaJavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1 Dependency (org.springframework.roo.project.Dependency)1