Search in sources :

Example 1 with MappedSuperclassDomainType

use of org.hibernate.metamodel.model.domain.MappedSuperclassDomainType in project hibernate-orm by hibernate.

the class MetadataContext method wrapUp.

@SuppressWarnings("unchecked")
public void wrapUp() {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Wrapping up metadata context...");
    }
    boolean staticMetamodelScanEnabled = this.jpaStaticMetaModelPopulationSetting != JpaStaticMetaModelPopulationSetting.DISABLED;
    // we need to process types from superclasses to subclasses
    for (Object mapping : orderedMappings) {
        if (PersistentClass.class.isAssignableFrom(mapping.getClass())) {
            final PersistentClass safeMapping = (PersistentClass) mapping;
            if (LOG.isTraceEnabled()) {
                LOG.trace("Starting entity [" + safeMapping.getEntityName() + ']');
            }
            try {
                final EntityDomainType<Object> jpaMapping = (EntityDomainType<Object>) entityTypesByPersistentClass.get(safeMapping);
                applyIdMetadata(safeMapping, jpaMapping);
                applyVersionAttribute(safeMapping, jpaMapping);
                for (Property property : safeMapping.getDeclaredProperties()) {
                    if (property.getValue() == safeMapping.getIdentifierMapper()) {
                        // #buildIdClassAttributes
                        continue;
                    }
                    if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
                        // skip the version property, it was already handled previously.
                        continue;
                    }
                    final PersistentAttribute<Object, ?> attribute = attributeFactory.buildAttribute(jpaMapping, property);
                    if (attribute != null) {
                        addAttribute(jpaMapping, attribute);
                        if (property.isNaturalIdentifier()) {
                            ((AttributeContainer<Object>) jpaMapping).getInFlightAccess().applyNaturalIdAttribute(attribute);
                        }
                    }
                }
                ((AttributeContainer<?>) jpaMapping).getInFlightAccess().finishUp();
                if (staticMetamodelScanEnabled) {
                    populateStaticMetamodel(jpaMapping);
                }
            } finally {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Completed entity [" + safeMapping.getEntityName() + ']');
                }
            }
        } else if (MappedSuperclass.class.isAssignableFrom(mapping.getClass())) {
            final MappedSuperclass safeMapping = (MappedSuperclass) mapping;
            if (LOG.isTraceEnabled()) {
                LOG.trace("Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
            }
            try {
                final MappedSuperclassDomainType<Object> jpaType = (MappedSuperclassDomainType<Object>) mappedSuperclassByMappedSuperclassMapping.get(safeMapping);
                applyIdMetadata(safeMapping, jpaType);
                applyVersionAttribute(safeMapping, jpaType);
                for (Property property : safeMapping.getDeclaredProperties()) {
                    if (safeMapping.isVersioned() && property == safeMapping.getVersion()) {
                        // skip the version property, it was already handled previously.
                        continue;
                    }
                    final PersistentAttribute<Object, ?> attribute = attributeFactory.buildAttribute(jpaType, property);
                    if (attribute != null) {
                        addAttribute(jpaType, attribute);
                        if (property.isNaturalIdentifier()) {
                            ((AttributeContainer<Object>) jpaType).getInFlightAccess().applyNaturalIdAttribute(attribute);
                        }
                    }
                }
                ((AttributeContainer<?>) jpaType).getInFlightAccess().finishUp();
                if (staticMetamodelScanEnabled) {
                    populateStaticMetamodel(jpaType);
                }
            } finally {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']');
                }
            }
        } else {
            throw new AssertionFailure("Unexpected mapping type: " + mapping.getClass());
        }
    }
    while (!embeddablesToProcess.isEmpty()) {
        final ArrayList<EmbeddableDomainType<?>> processingEmbeddables = new ArrayList<>(embeddablesToProcess.size());
        for (List<EmbeddableDomainType<?>> embeddableDomainTypes : embeddablesToProcess.values()) {
            processingEmbeddables.addAll(embeddableDomainTypes);
        }
        embeddablesToProcess.clear();
        for (EmbeddableDomainType<?> embeddable : processingEmbeddables) {
            final Component component = componentByEmbeddable.get(embeddable);
            for (Property property : component.getProperties()) {
                final PersistentAttribute<Object, ?> attribute = attributeFactory.buildAttribute((ManagedDomainType<Object>) embeddable, property);
                if (attribute != null) {
                    addAttribute(embeddable, attribute);
                }
            }
            ((AttributeContainer<?>) embeddable).getInFlightAccess().finishUp();
            embeddables.put(embeddable.getJavaType(), embeddable);
            if (staticMetamodelScanEnabled) {
                populateStaticMetamodel(embeddable);
            }
        }
    }
}
Also used : EmbeddableDomainType(org.hibernate.metamodel.model.domain.EmbeddableDomainType) AssertionFailure(org.hibernate.AssertionFailure) ArrayList(java.util.ArrayList) AttributeContainer(org.hibernate.metamodel.model.domain.internal.AttributeContainer) MappedSuperclassDomainType(org.hibernate.metamodel.model.domain.MappedSuperclassDomainType) PersistentAttribute(org.hibernate.metamodel.model.domain.PersistentAttribute) SingularPersistentAttribute(org.hibernate.metamodel.model.domain.SingularPersistentAttribute) MappedSuperclass(org.hibernate.mapping.MappedSuperclass) EntityDomainType(org.hibernate.metamodel.model.domain.EntityDomainType) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) PersistentClass(org.hibernate.mapping.PersistentClass)

Aggregations

ArrayList (java.util.ArrayList)1 AssertionFailure (org.hibernate.AssertionFailure)1 Component (org.hibernate.mapping.Component)1 MappedSuperclass (org.hibernate.mapping.MappedSuperclass)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 Property (org.hibernate.mapping.Property)1 EmbeddableDomainType (org.hibernate.metamodel.model.domain.EmbeddableDomainType)1 EntityDomainType (org.hibernate.metamodel.model.domain.EntityDomainType)1 MappedSuperclassDomainType (org.hibernate.metamodel.model.domain.MappedSuperclassDomainType)1 PersistentAttribute (org.hibernate.metamodel.model.domain.PersistentAttribute)1 SingularPersistentAttribute (org.hibernate.metamodel.model.domain.SingularPersistentAttribute)1 AttributeContainer (org.hibernate.metamodel.model.domain.internal.AttributeContainer)1