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);
}
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;
}
Aggregations