Search in sources :

Example 1 with EmbeddedIdHolder

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

the class JpaEntityFactoryMetadataProviderImpl method getEmbeddedIdHolder.

private EmbeddedIdHolder getEmbeddedIdHolder(final MemberDetails memberDetails, final String metadataIdentificationString) {
    final List<FieldMetadata> idFields = new ArrayList<FieldMetadata>();
    final List<FieldMetadata> fields = MemberFindingUtils.getFieldsWithTag(memberDetails, EMBEDDED_ID_FIELD);
    if (fields.isEmpty()) {
        return null;
    }
    final FieldMetadata embeddedIdField = fields.get(0);
    final MemberDetails identifierMemberDetails = getMemberDetails(embeddedIdField.getFieldType());
    if (identifierMemberDetails == null) {
        return null;
    }
    for (final FieldMetadata field : identifierMemberDetails.getFields()) {
        if (!(Modifier.isStatic(field.getModifier()) || Modifier.isFinal(field.getModifier()) || Modifier.isTransient(field.getModifier()))) {
            getMetadataDependencyRegistry().registerDependency(field.getDeclaredByMetadataId(), metadataIdentificationString);
            idFields.add(field);
        }
    }
    return new EmbeddedIdHolder(embeddedIdField, idFields);
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) EmbeddedIdHolder(org.springframework.roo.addon.jpa.addon.dod.EmbeddedIdHolder) ArrayList(java.util.ArrayList) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Example 2 with EmbeddedIdHolder

use of org.springframework.roo.addon.jpa.addon.dod.EmbeddedIdHolder 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)

Aggregations

EmbeddedIdHolder (org.springframework.roo.addon.jpa.addon.dod.EmbeddedIdHolder)2 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)2 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)2 ArrayList (java.util.ArrayList)1 EmbeddedHolder (org.springframework.roo.addon.jpa.addon.dod.EmbeddedHolder)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