Search in sources :

Example 1 with EmbeddedHolder

use of org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder in project spring-roo by spring-projects.

the class JpaEntityFactoryMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String entityFactoryMetadata, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Get related entity
    final JavaType entity = (JavaType) governorPhysicalTypeMetadata.getMemberHoldingTypeDetails().getAnnotation(ROO_JPA_ENTITY_FACTORY).getAttribute("entity").getValue();
    if (entity == null) {
        return null;
    }
    final MemberDetails memberDetails = getMemberDetails(entity);
    if (memberDetails == null) {
        return null;
    }
    final MemberHoldingTypeDetails persistenceMemberHoldingTypeDetails = MemberFindingUtils.getMostConcreteMemberHoldingTypeDetailsWithTag(memberDetails, PERSISTENT_TYPE);
    if (persistenceMemberHoldingTypeDetails == null) {
        return null;
    }
    // We need to be informed if our dependent metadata changes
    getMetadataDependencyRegistry().registerDependency(persistenceMemberHoldingTypeDetails.getDeclaredByMetadataId(), entityFactoryMetadata);
    final JavaType identifierType = getPersistenceMemberLocator().getIdentifierType(entity);
    if (identifierType == null) {
        return null;
    }
    // Identify all the fields we care about on the entity
    final Map<FieldMetadata, JpaEntityFactoryMetadata> locatedFields = getLocatedFields(memberDetails, entityFactoryMetadata);
    // Get the list of embedded metadata holders - may be an empty list if
    // no embedded identifier exists
    final List<EmbeddedHolder> embeddedHolders = getEmbeddedHolders(memberDetails, entityFactoryMetadata);
    // Get the embedded identifier metadata holder - may be null if no
    // embedded identifier exists
    final EmbeddedIdHolder embeddedIdHolder = getEmbeddedIdHolder(memberDetails, entityFactoryMetadata);
    Set<ClassOrInterfaceTypeDetails> entityFactoryClasses = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY_FACTORY);
    return new JpaEntityFactoryMetadata(entityFactoryMetadata, aspectName, governorPhysicalTypeMetadata, entity, locatedFields, embeddedHolders, entityFactoryClasses, embeddedIdHolder);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) EmbeddedIdHolder(org.springframework.roo.addon.jpa.addon.dod.EmbeddedIdHolder) MemberHoldingTypeDetails(org.springframework.roo.classpath.details.MemberHoldingTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) EmbeddedHolder(org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder)

Example 2 with EmbeddedHolder

use of org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder in project spring-roo by spring-projects.

the class JpaEntityFactoryMetadataProviderImpl method getEmbeddedHolders.

private List<EmbeddedHolder> getEmbeddedHolders(final MemberDetails memberDetails, final String metadataIdentificationString) {
    final List<EmbeddedHolder> embeddedHolders = new ArrayList<EmbeddedHolder>();
    final List<FieldMetadata> embeddedFields = MemberFindingUtils.getFieldsWithTag(memberDetails, EMBEDDED_FIELD);
    if (embeddedFields.isEmpty()) {
        return embeddedHolders;
    }
    for (final FieldMetadata embeddedField : embeddedFields) {
        final MemberDetails embeddedMemberDetails = getMemberDetails(embeddedField.getFieldType());
        if (embeddedMemberDetails == null) {
            continue;
        }
        final List<FieldMetadata> fields = new ArrayList<FieldMetadata>();
        for (final FieldMetadata field : embeddedMemberDetails.getFields()) {
            if (!(Modifier.isStatic(field.getModifier()) || Modifier.isFinal(field.getModifier()) || Modifier.isTransient(field.getModifier()))) {
                getMetadataDependencyRegistry().registerDependency(field.getDeclaredByMetadataId(), metadataIdentificationString);
                fields.add(field);
            }
        }
        embeddedHolders.add(new EmbeddedHolder(embeddedField, fields));
    }
    return embeddedHolders;
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) EmbeddedHolder(org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder)

Aggregations

EmbeddedHolder (org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder)2 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)2 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)2 ArrayList (java.util.ArrayList)1 EmbeddedIdHolder (org.springframework.roo.addon.jpa.addon.dod.EmbeddedIdHolder)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 MemberHoldingTypeDetails (org.springframework.roo.classpath.details.MemberHoldingTypeDetails)1 JavaType (org.springframework.roo.model.JavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1