Search in sources :

Example 1 with CompleteFetchBuilderEntityValuedModelPart

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

the class FetchMementoHbmStandard method resolve.

@Override
public FetchBuilder resolve(Parent parent, Consumer<String> querySpaceConsumer, ResultSetMappingResolutionContext context) {
    final Map<String, FetchBuilder> fetchBuilderMap = new HashMap<>();
    fetchMementoMap.forEach((attrName, fetchMemento) -> fetchBuilderMap.put(attrName, fetchMemento.resolve(this, querySpaceConsumer, context)));
    final DynamicResultBuilderEntityStandard resultBuilder;
    if (fetchable instanceof PluralAttributeMapping) {
        resultBuilder = new DynamicResultBuilderEntityStandard((EntityMappingType) ((PluralAttributeMapping) fetchable).getElementDescriptor().getPartMappingType(), tableAlias, navigablePath);
        FetchBuilder element = fetchBuilderMap.get("element");
        if (element != null) {
            if (element instanceof DynamicFetchBuilder) {
                resultBuilder.addIdColumnAliases(((DynamicFetchBuilder) element).getColumnAliases().toArray(new String[0]));
            } else {
                resultBuilder.addIdColumnAliases(((CompleteFetchBuilderEntityValuedModelPart) element).getColumnAliases().toArray(new String[0]));
            }
        }
        FetchBuilder index = fetchBuilderMap.get("index");
        if (index != null) {
            resultBuilder.addFetchBuilder(CollectionPart.Nature.INDEX.getName(), index);
        }
        for (Map.Entry<String, FetchBuilder> entry : fetchBuilderMap.entrySet()) {
            if (entry.getKey().startsWith(ELEMENT_PREFIX)) {
                resultBuilder.addFetchBuilder(entry.getKey().substring(ELEMENT_PREFIX.length()), entry.getValue());
            }
        }
    } else {
        resultBuilder = new DynamicResultBuilderEntityStandard(((ToOneAttributeMapping) fetchable).getEntityMappingType(), tableAlias, navigablePath);
        fetchBuilderMap.forEach(resultBuilder::addFetchBuilder);
    }
    return new DynamicFetchBuilderLegacy(tableAlias, ownerTableAlias, fetchable.getFetchableName(), keyColumnNames, fetchBuilderMap, resultBuilder);
}
Also used : DynamicFetchBuilder(org.hibernate.query.results.dynamic.DynamicFetchBuilder) FetchBuilder(org.hibernate.query.results.FetchBuilder) CompleteFetchBuilderEntityValuedModelPart(org.hibernate.query.results.complete.CompleteFetchBuilderEntityValuedModelPart) HashMap(java.util.HashMap) PluralAttributeMapping(org.hibernate.metamodel.mapping.PluralAttributeMapping) DynamicFetchBuilder(org.hibernate.query.results.dynamic.DynamicFetchBuilder) ToOneAttributeMapping(org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping) DynamicFetchBuilderLegacy(org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy) DynamicResultBuilderEntityStandard(org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard) EntityMappingType(org.hibernate.metamodel.mapping.EntityMappingType) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

HashMap (java.util.HashMap)1 Map (java.util.Map)1 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)1 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)1 ToOneAttributeMapping (org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping)1 FetchBuilder (org.hibernate.query.results.FetchBuilder)1 CompleteFetchBuilderEntityValuedModelPart (org.hibernate.query.results.complete.CompleteFetchBuilderEntityValuedModelPart)1 DynamicFetchBuilder (org.hibernate.query.results.dynamic.DynamicFetchBuilder)1 DynamicFetchBuilderLegacy (org.hibernate.query.results.dynamic.DynamicFetchBuilderLegacy)1 DynamicResultBuilderEntityStandard (org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard)1