Search in sources :

Example 41 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class JpaOperationsImpl method getFieldChildPartOfCompositionRelation.

@Override
public Pair<FieldMetadata, RelationInfo> getFieldChildPartOfCompositionRelation(ClassOrInterfaceTypeDetails entityCdi) {
    JavaType domainType = entityCdi.getType();
    List<Pair<FieldMetadata, RelationInfo>> relations = getFieldChildPartOfRelation(entityCdi);
    if (relations.isEmpty()) {
        return null;
    }
    JpaEntityMetadata parent;
    JavaType parentType;
    RelationInfo info;
    List<Pair<FieldMetadata, RelationInfo>> compositionRelation = new ArrayList<Pair<FieldMetadata, RelationInfo>>();
    for (Pair<FieldMetadata, RelationInfo> field : relations) {
        if (field.getRight().type == JpaRelationType.COMPOSITION) {
            compositionRelation.add(field);
        }
    }
    Validate.isTrue(compositionRelation.size() <= 1, "Entity %s has more than one relations of composition as child part: ", domainType, StringUtils.join(getFieldNamesOfRelationList(compositionRelation), ","));
    if (compositionRelation.isEmpty()) {
        return null;
    }
    return compositionRelation.get(0);
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) RelationInfo(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo) ArrayList(java.util.ArrayList) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata) Pair(org.apache.commons.lang3.tuple.Pair)

Example 42 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class JpaOperationsImpl method updateEmbeddableToIdentifier.

@Override
public void updateEmbeddableToIdentifier(final JavaType identifierType, final String identifierField, final String identifierColumn) {
    Validate.notNull(identifierType, "Identifier type required");
    // Get details from existing JavaType
    ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(getTypeLocationService().getTypeDetails(identifierType));
    // Create @RooIdentifier with getters and setters
    AnnotationMetadataBuilder rooIdentifier = new AnnotationMetadataBuilder(ROO_IDENTIFIER);
    rooIdentifier.addBooleanAttribute("settersByDefault", true);
    final List<AnnotationMetadataBuilder> identifierAnnotations = Arrays.asList(new AnnotationMetadataBuilder(ROO_TO_STRING), new AnnotationMetadataBuilder(ROO_EQUALS), rooIdentifier);
    cidBuilder.setAnnotations(identifierAnnotations);
    // Set implement Serializable
    List<JavaType> implementTypes = new ArrayList<JavaType>();
    implementTypes.add(JdkJavaType.SERIALIZABLE);
    cidBuilder.setImplementsTypes(implementTypes);
    getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build());
}
Also used : JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetailsBuilder(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 43 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class EntityProjectionMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = EntityProjectionMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = EntityProjectionMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 44 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class EqualsMetadataProviderImpl method getGovernorPhysicalTypeIdentifier.

@Override
protected String getGovernorPhysicalTypeIdentifier(final String metadataIdentificationString) {
    final JavaType javaType = EqualsMetadata.getJavaType(metadataIdentificationString);
    final LogicalPath path = EqualsMetadata.getPath(metadataIdentificationString);
    return PhysicalTypeIdentifier.createIdentifier(javaType, path);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath)

Example 45 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class EqualsMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    final EqualsAnnotationValues annotationValues = new EqualsAnnotationValues(governorPhysicalTypeMetadata);
    if (!annotationValues.isAnnotationFound()) {
        return null;
    }
    final MemberDetails memberDetails = getMemberDetails(governorPhysicalTypeMetadata);
    if (memberDetails == null) {
        return null;
    }
    AnnotationMetadata javaBeanAnnotation = memberDetails.getAnnotation(ROO_JAVA_BEAN);
    if (javaBeanAnnotation != null) {
        // Return an empty metadata as @RooJavaBean do the work
        return new EqualsMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, new ArrayList<FieldMetadata>(), null, true);
    }
    final JavaType javaType = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getName();
    final List<FieldMetadata> equalityFields = locateFields(javaType, annotationValues.getExcludeFields(), memberDetails.getFields(), metadataIdentificationString);
    FieldMetadata identifierField = getIdentifier(governorPhysicalTypeMetadata);
    return new EqualsMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, equalityFields, identifierField, false);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata)

Aggregations

JavaType (org.springframework.roo.model.JavaType)411 RooJavaType (org.springframework.roo.model.RooJavaType)212 ArrayList (java.util.ArrayList)142 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)133 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)129 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)114 JdkJavaType (org.springframework.roo.model.JdkJavaType)110 SpringJavaType (org.springframework.roo.model.SpringJavaType)101 JpaJavaType (org.springframework.roo.model.JpaJavaType)83 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)78 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)76 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)72 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)70 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)65 LogicalPath (org.springframework.roo.project.LogicalPath)62 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)60 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)59 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)38 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)35 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)30