Search in sources :

Example 1 with CompleteResultBuilderCollectionStandard

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

the class ResultSetMappingProcessor method createSuffixedResultBuilder.

private CompleteResultBuilderCollectionStandard createSuffixedResultBuilder(NativeQuery.CollectionReturn collectionReturn, String suffix, String entitySuffix) {
    final CollectionPersister collectionPersister = collectionReturn.getPluralAttribute().getCollectionDescriptor();
    final String[] elementColumnAliases;
    if (collectionPersister.getElementType().isEntityType()) {
        final Loadable elementPersister = (Loadable) ((QueryableCollection) collectionPersister).getElementPersister();
        final String[] propertyNames = elementPersister.getPropertyNames();
        final String[] identifierAliases = elementPersister.getIdentifierAliases(entitySuffix);
        final String discriminatorAlias = elementPersister.getDiscriminatorAlias(entitySuffix);
        final List<String> aliases = new ArrayList<>(propertyNames.length + identifierAliases.length + (discriminatorAlias == null ? 0 : 1));
        Collections.addAll(aliases, identifierAliases);
        if (discriminatorAlias != null) {
            aliases.add(discriminatorAlias);
        }
        for (int i = 0; i < propertyNames.length; i++) {
            Collections.addAll(aliases, elementPersister.getPropertyAliases(entitySuffix, i));
        }
        elementColumnAliases = ArrayHelper.toStringArray(aliases);
    } else {
        elementColumnAliases = collectionPersister.getElementColumnAliases(suffix);
    }
    return new CompleteResultBuilderCollectionStandard(collectionReturn.getTableAlias(), collectionReturn.getNavigablePath(), collectionReturn.getPluralAttribute(), collectionPersister.getKeyColumnAliases(suffix), collectionPersister.hasIndex() ? collectionPersister.getIndexColumnAliases(suffix) : null, elementColumnAliases);
}
Also used : SQLLoadable(org.hibernate.persister.entity.SQLLoadable) Loadable(org.hibernate.persister.entity.Loadable) CompleteResultBuilderCollectionStandard(org.hibernate.query.results.complete.CompleteResultBuilderCollectionStandard) CollectionPersister(org.hibernate.persister.collection.CollectionPersister) ArrayList(java.util.ArrayList)

Example 2 with CompleteResultBuilderCollectionStandard

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

the class ResultSetMappingProcessor method generateResultMapping.

public ResultSetMapping generateResultMapping(boolean queryHadAliases) {
    if (!queryHadAliases) {
        return this.resultSetMapping;
    }
    final ResultSetMappingImpl resultSetMapping = new ResultSetMappingImpl(null);
    final Set<String> visited = new HashSet<>();
    this.resultSetMapping.visitResultBuilders((i, resultBuilder) -> {
        if (resultBuilder instanceof NativeQuery.RootReturn) {
            final NativeQuery.RootReturn rootReturn = (NativeQuery.RootReturn) resultBuilder;
            final String suffix = alias2Suffix.get(rootReturn.getTableAlias());
            visited.add(rootReturn.getTableAlias());
            if (suffix == null) {
                resultSetMapping.addResultBuilder(resultBuilder);
            } else {
                final DynamicResultBuilderEntityStandard resultBuilderEntity = createSuffixedResultBuilder(rootReturn, suffix);
                resultSetMapping.addResultBuilder(resultBuilderEntity);
                alias2Return.put(rootReturn.getTableAlias(), resultBuilderEntity);
            }
        } else if (resultBuilder instanceof NativeQuery.CollectionReturn) {
            final NativeQuery.CollectionReturn collectionReturn = (NativeQuery.CollectionReturn) resultBuilder;
            final String suffix = alias2CollectionSuffix.get(collectionReturn.getTableAlias());
            if (suffix == null) {
                resultSetMapping.addResultBuilder(resultBuilder);
            } else {
                final CompleteResultBuilderCollectionStandard resultBuilderCollection = createSuffixedResultBuilder(collectionReturn, suffix, alias2Suffix.get(collectionReturn.getTableAlias()));
                resultSetMapping.addResultBuilder(resultBuilderCollection);
                alias2Return.put(collectionReturn.getTableAlias(), resultBuilderCollection);
            }
        } else {
            resultSetMapping.addResultBuilder(resultBuilder);
        }
    });
    this.resultSetMapping.visitLegacyFetchBuilders(fetchBuilder -> applyFetchBuilder(resultSetMapping, fetchBuilder, visited));
    return resultSetMapping;
}
Also used : CompleteResultBuilderCollectionStandard(org.hibernate.query.results.complete.CompleteResultBuilderCollectionStandard) ResultSetMappingImpl(org.hibernate.query.results.ResultSetMappingImpl) NativeQuery(org.hibernate.query.NativeQuery) DynamicResultBuilderEntityStandard(org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard) HashSet(java.util.HashSet)

Aggregations

CompleteResultBuilderCollectionStandard (org.hibernate.query.results.complete.CompleteResultBuilderCollectionStandard)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CollectionPersister (org.hibernate.persister.collection.CollectionPersister)1 Loadable (org.hibernate.persister.entity.Loadable)1 SQLLoadable (org.hibernate.persister.entity.SQLLoadable)1 NativeQuery (org.hibernate.query.NativeQuery)1 ResultSetMappingImpl (org.hibernate.query.results.ResultSetMappingImpl)1 DynamicResultBuilderEntityStandard (org.hibernate.query.results.dynamic.DynamicResultBuilderEntityStandard)1