Search in sources :

Example 1 with JpaEntityFactoryMetadata

use of org.springframework.roo.addon.jpa.addon.entity.factories.JpaEntityFactoryMetadata in project spring-roo by spring-projects.

the class JpaDataOnDemandMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String dodMetadataId, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    if (layerService == null) {
        layerService = getLayerService();
    }
    Validate.notNull(layerService, "LayerService is required");
    // We need to parse the annotation, which we expect to be present
    final JpaDataOnDemandAnnotationValues annotationValues = new JpaDataOnDemandAnnotationValues(governorPhysicalTypeMetadata);
    final JavaType entity = annotationValues.getEntity();
    if (!annotationValues.isAnnotationFound() || entity == null) {
        return null;
    }
    // Remember that this entity JavaType matches up with this DOD's
    // metadata identification string
    // Start by clearing the previous association
    final JavaType oldEntity = dodMidToEntityMap.get(dodMetadataId);
    if (oldEntity != null) {
        entityToDodMidMap.remove(oldEntity);
    }
    entityToDodMidMap.put(annotationValues.getEntity(), dodMetadataId);
    dodMidToEntityMap.put(dodMetadataId, annotationValues.getEntity());
    final JavaType identifierType = getPersistenceMemberLocator().getIdentifierType(entity);
    if (identifierType == null) {
        return null;
    }
    final MemberDetails memberDetails = getMemberDetails(entity);
    if (memberDetails == null) {
        return null;
    }
    // Get associated factory class (factory for current associated entity)
    Set<ClassOrInterfaceTypeDetails> entityFactoryClasses = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_ENTITY_FACTORY);
    JpaEntityFactoryMetadata entityFactoryMetadata = null;
    for (ClassOrInterfaceTypeDetails cid : entityFactoryClasses) {
        if (((JavaType) cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY_FACTORY).getAttribute("entity").getValue()).equals(entity)) {
            String entityFactoryIdentifier = JpaEntityFactoryMetadata.createIdentifier(cid);
            // Register dependency between EntityFactoryMetadata and DataOnDemandMetadata
            registerDependency(entityFactoryIdentifier, dodMetadataId);
            // Obtain related entity EntityFactoryMetadata
            entityFactoryMetadata = getMetadataService().get(entityFactoryIdentifier);
            break;
        }
    }
    if (entityFactoryMetadata == null) {
        return null;
    }
    // Register JpaDataOndDemandConfiguration as downstream dependency
    Set<ClassOrInterfaceTypeDetails> dataOnDemandConfigurationClasses = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_JPA_DATA_ON_DEMAND_CONFIGURATION);
    if (dataOnDemandConfigurationClasses.isEmpty()) {
        return null;
    }
    ClassOrInterfaceTypeDetails jpaDataOnDemandConfigurationDetails = dataOnDemandConfigurationClasses.iterator().next();
    String dodConfigurationId = JpaDataOnDemandConfigurationMetadata.createIdentifier(jpaDataOnDemandConfigurationDetails);
    registerDependency(dodMetadataId, dodConfigurationId);
    return new JpaDataOnDemandMetadata(dodMetadataId, aspectName, governorPhysicalTypeMetadata, annotationValues, entityFactoryMetadata);
}
Also used : JpaEntityFactoryMetadata(org.springframework.roo.addon.jpa.addon.entity.factories.JpaEntityFactoryMetadata) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Aggregations

JpaEntityFactoryMetadata (org.springframework.roo.addon.jpa.addon.entity.factories.JpaEntityFactoryMetadata)1 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)1 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)1 JavaType (org.springframework.roo.model.JavaType)1 RooJavaType (org.springframework.roo.model.RooJavaType)1