Search in sources :

Example 1 with BasicValuedFetchBuilder

use of org.hibernate.query.results.BasicValuedFetchBuilder 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)

Example 2 with BasicValuedFetchBuilder

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

the class ResultMementoEntityStandard method resolve.

@Override
public ResultBuilderEntityValued resolve(Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
    final BasicValuedFetchBuilder discriminatorResultBuilder = discriminatorMemento != null ? (BasicValuedFetchBuilder) discriminatorMemento.resolve(this, querySpaceConsumer, context) : null;
    final HashMap<String, FetchBuilder> fetchBuilderMap = new HashMap<>();
    fetchMementoMap.forEach((attrName, fetchMemento) -> fetchBuilderMap.put(attrName, fetchMemento.resolve(this, querySpaceConsumer, context)));
    return new CompleteResultBuilderEntityStandard(tableAlias, navigablePath, entityDescriptor, lockMode, discriminatorResultBuilder, fetchBuilderMap);
}
Also used : BasicValuedFetchBuilder(org.hibernate.query.results.BasicValuedFetchBuilder) FetchBuilder(org.hibernate.query.results.FetchBuilder) BasicValuedFetchBuilder(org.hibernate.query.results.BasicValuedFetchBuilder) HashMap(java.util.HashMap) CompleteResultBuilderEntityStandard(org.hibernate.query.results.complete.CompleteResultBuilderEntityStandard)

Aggregations

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