Search in sources :

Example 1 with DelayedFetchBuilderBasicPart

use of org.hibernate.query.results.complete.DelayedFetchBuilderBasicPart in project hibernate-orm by hibernate.

the class ResultMementoEntityJpa method resolve.

@Override
public ResultBuilderEntityValued resolve(Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
    final EntityDiscriminatorMapping discriminatorMapping = entityDescriptor.getDiscriminatorMapping();
    final BasicValuedFetchBuilder discriminatorFetchBuilder;
    if (discriminatorMapping == null) {
        assert discriminatorMemento == null;
        discriminatorFetchBuilder = null;
    } else {
        if (discriminatorMemento != null) {
            discriminatorFetchBuilder = (BasicValuedFetchBuilder) discriminatorMemento.resolve(this, querySpaceConsumer, context);
        } else {
            discriminatorFetchBuilder = new ImplicitFetchBuilderBasic(navigablePath, discriminatorMapping);
        }
    }
    final HashMap<String, FetchBuilder> explicitFetchBuilderMap = new HashMap<>();
    // If there are no explicit fetches, we don't register DELAYED builders to get implicit fetching of all basic fetchables
    if (!explicitFetchMementoMap.isEmpty()) {
        explicitFetchMementoMap.forEach((relativePath, fetchMemento) -> explicitFetchBuilderMap.put(relativePath, fetchMemento.resolve(this, querySpaceConsumer, context)));
        final boolean isEnhancedForLazyLoading = entityDescriptor.getRepresentationStrategy().isBytecodeEnhanced();
        // Implicit basic fetches are DELAYED by default, so register fetch builders for the remaining basic fetchables
        entityDescriptor.visitAttributeMappings(attributeMapping -> {
            final Function<String, FetchBuilder> fetchBuilderCreator;
            if (attributeMapping instanceof BasicValuedModelPart) {
                fetchBuilderCreator = k -> new DelayedFetchBuilderBasicPart(navigablePath.append(k), (BasicValuedModelPart) attributeMapping, isEnhancedForLazyLoading);
                explicitFetchBuilderMap.computeIfAbsent(attributeMapping.getFetchableName(), fetchBuilderCreator);
            }
        });
    }
    return new CompleteResultBuilderEntityJpa(navigablePath, entityDescriptor, lockMode, discriminatorFetchBuilder, explicitFetchBuilderMap);
}
Also used : BasicValuedFetchBuilder(org.hibernate.query.results.BasicValuedFetchBuilder) ImplicitFetchBuilderBasic(org.hibernate.query.results.implicit.ImplicitFetchBuilderBasic) FetchBuilder(org.hibernate.query.results.FetchBuilder) BasicValuedFetchBuilder(org.hibernate.query.results.BasicValuedFetchBuilder) BasicValuedModelPart(org.hibernate.metamodel.mapping.BasicValuedModelPart) CompleteResultBuilderEntityJpa(org.hibernate.query.results.complete.CompleteResultBuilderEntityJpa) HashMap(java.util.HashMap) DelayedFetchBuilderBasicPart(org.hibernate.query.results.complete.DelayedFetchBuilderBasicPart) EntityDiscriminatorMapping(org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)

Aggregations

HashMap (java.util.HashMap)1 BasicValuedModelPart (org.hibernate.metamodel.mapping.BasicValuedModelPart)1 EntityDiscriminatorMapping (org.hibernate.metamodel.mapping.EntityDiscriminatorMapping)1 BasicValuedFetchBuilder (org.hibernate.query.results.BasicValuedFetchBuilder)1 FetchBuilder (org.hibernate.query.results.FetchBuilder)1 CompleteResultBuilderEntityJpa (org.hibernate.query.results.complete.CompleteResultBuilderEntityJpa)1 DelayedFetchBuilderBasicPart (org.hibernate.query.results.complete.DelayedFetchBuilderBasicPart)1 ImplicitFetchBuilderBasic (org.hibernate.query.results.implicit.ImplicitFetchBuilderBasic)1