Search in sources :

Example 1 with EmbeddedField

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

the class EmbeddableFieldCreatorProvider method createEmbeddedField.

@Override
public void createEmbeddedField(JavaType typeName, JavaType fieldType, JavaSymbolName fieldName, boolean permitReservedWords, List<AnnotationMetadataBuilder> extraAnnotations) {
    // Check if the requested entity is a JPA @Entity
    final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService.getTypeDetails(typeName);
    Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", typeName);
    final String physicalTypeIdentifier = javaTypeDetails.getDeclaredByMetadataId();
    final PhysicalTypeMetadata targetTypeMetadata = (PhysicalTypeMetadata) metadataService.get(physicalTypeIdentifier);
    Validate.notNull(targetTypeMetadata, "The specified target '--class' does not exist or can not be found. Please create this type first.");
    final PhysicalTypeDetails targetPtd = targetTypeMetadata.getMemberHoldingTypeDetails();
    Validate.isInstanceOf(MemberHoldingTypeDetails.class, targetPtd);
    final ClassOrInterfaceTypeDetails targetTypeCid = (ClassOrInterfaceTypeDetails) targetPtd;
    final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(this.getClass().getName(), targetTypeCid);
    Validate.isTrue(memberDetails.getAnnotation(ENTITY) != null || memberDetails.getAnnotation(PERSISTENT) != null, "The field embedded command is only applicable to JPA @Entity or Spring Data @Persistent target types.");
    final EmbeddedField fieldDetails = new EmbeddedField(physicalTypeIdentifier, fieldType, fieldName);
    if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
        fieldDetails.addAnnotations(extraAnnotations);
    }
    insertField(fieldDetails, permitReservedWords, false);
}
Also used : EmbeddedField(org.springframework.roo.classpath.operations.jsr303.EmbeddedField) PhysicalTypeDetails(org.springframework.roo.classpath.PhysicalTypeDetails) PhysicalTypeMetadata(org.springframework.roo.classpath.PhysicalTypeMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Example 2 with EmbeddedField

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

the class JpaFieldCreatorProvider method createEmbeddedField.

@Override
public void createEmbeddedField(JavaType typeName, JavaType fieldType, JavaSymbolName fieldName, boolean permitReservedWords, List<AnnotationMetadataBuilder> extraAnnotations) {
    // Check if the requested entity is a JPA @Entity
    final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService.getTypeDetails(typeName);
    Validate.notNull(javaTypeDetails, "The type specified, '%s', doesn't exist", typeName);
    final String physicalTypeIdentifier = javaTypeDetails.getDeclaredByMetadataId();
    final PhysicalTypeMetadata targetTypeMetadata = (PhysicalTypeMetadata) metadataService.get(physicalTypeIdentifier);
    Validate.notNull(targetTypeMetadata, "The specified target '--class' does not exist or can not be found. Please create this type first.");
    final PhysicalTypeDetails targetPtd = targetTypeMetadata.getMemberHoldingTypeDetails();
    Validate.isInstanceOf(MemberHoldingTypeDetails.class, targetPtd);
    final ClassOrInterfaceTypeDetails targetTypeCid = (ClassOrInterfaceTypeDetails) targetPtd;
    final MemberDetails memberDetails = memberDetailsScanner.getMemberDetails(this.getClass().getName(), targetTypeCid);
    Validate.isTrue(memberDetails.getAnnotation(ENTITY) != null || memberDetails.getAnnotation(PERSISTENT) != null, "The field embedded command is only applicable to JPA @Entity or Spring Data @Persistent target types.");
    final EmbeddedField fieldDetails = new EmbeddedField(physicalTypeIdentifier, fieldType, fieldName);
    if (extraAnnotations != null && !extraAnnotations.isEmpty()) {
        fieldDetails.addAnnotations(extraAnnotations);
    }
    insertField(fieldDetails, permitReservedWords, false);
}
Also used : EmbeddedField(org.springframework.roo.classpath.operations.jsr303.EmbeddedField) PhysicalTypeDetails(org.springframework.roo.classpath.PhysicalTypeDetails) PhysicalTypeMetadata(org.springframework.roo.classpath.PhysicalTypeMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Aggregations

PhysicalTypeDetails (org.springframework.roo.classpath.PhysicalTypeDetails)2 PhysicalTypeMetadata (org.springframework.roo.classpath.PhysicalTypeMetadata)2 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)2 EmbeddedField (org.springframework.roo.classpath.operations.jsr303.EmbeddedField)2 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)2