use of org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult in project hibernate-orm by hibernate.
the class LoadPlanBuilderTest method testCollectionInitializerCase.
@Test
public void testCollectionInitializerCase(SessionFactoryScope scope) {
final SessionFactoryImplementor sessionFactory = scope.getSessionFactory();
final EntityPersister posterEntityDescriptor = sessionFactory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Poster.class);
final PluralAttributeMapping messages = (PluralAttributeMapping) posterEntityDescriptor.findAttributeMapping("messages");
final CollectionLoaderSingleKey loader = new CollectionLoaderSingleKey(messages, LoadQueryInfluencers.NONE, sessionFactory);
assertThat(loader.getSqlAst().getDomainResultDescriptors()).hasSize(1);
assertThat(loader.getSqlAst().getDomainResultDescriptors().get(0)).isInstanceOf(CollectionDomainResult.class);
final CollectionDomainResult domainResult = (CollectionDomainResult) loader.getSqlAst().getDomainResultDescriptors().get(0);
DomainResultGraphPrinter.logDomainResultGraph(loader.getSqlAst().getDomainResultDescriptors());
assertThat(domainResult.getFetches()).isEmpty();
}
use of org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult in project hibernate-orm by hibernate.
the class PluralAttributeMappingImpl method createDomainResult.
@Override
public <T> DomainResult<T> createDomainResult(NavigablePath navigablePath, TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) {
final TableGroup collectionTableGroup = creationState.getSqlAstCreationState().getFromClauseAccess().getTableGroup(navigablePath);
assert collectionTableGroup != null;
// This is only used for collection initialization where we know the owner is available, so we mark it as visited
// which will cause bidirectional to-one associations to be treated as such and avoid a join
creationState.registerVisitedAssociationKey(fkDescriptor.getAssociationKey());
// noinspection unchecked
return new CollectionDomainResult(navigablePath, this, resultVariable, tableGroup, creationState);
}
use of org.hibernate.sql.results.graph.collection.internal.CollectionDomainResult in project hibernate-orm by hibernate.
the class LoaderSelectBuilder method generateSelect.
private SelectStatement generateSelect(SubselectFetch subselect) {
assert loadable instanceof PluralAttributeMapping;
final PluralAttributeMapping attributeMapping = (PluralAttributeMapping) loadable;
final QuerySpec rootQuerySpec = new QuerySpec(true);
final NavigablePath rootNavigablePath = new NavigablePath(loadable.getRootPathName());
// We need to initialize the acronymMap based on subselect.getLoadingSqlAst() to avoid alias collisions
final Map<String, TableReference> tableReferences = AliasCollector.getTableReferences(subselect.getLoadingSqlAst());
final LoaderSqlAstCreationState sqlAstCreationState = new LoaderSqlAstCreationState(rootQuerySpec, new SqlAliasBaseManager(tableReferences.keySet()), new SimpleFromClauseAccessImpl(), lockOptions, this::visitFetches, numberOfKeysToLoad > 1, creationContext);
final TableGroup rootTableGroup = loadable.createRootTableGroup(true, rootNavigablePath, null, () -> rootQuerySpec::applyPredicate, sqlAstCreationState, creationContext);
rootQuerySpec.getFromClause().addRoot(rootTableGroup);
sqlAstCreationState.getFromClauseAccess().registerTableGroup(rootNavigablePath, rootTableGroup);
registerPluralTableGroupParts(sqlAstCreationState.getFromClauseAccess(), rootTableGroup);
// generate and apply the restriction
applySubSelectRestriction(rootQuerySpec, rootNavigablePath, rootTableGroup, subselect, sqlAstCreationState);
// NOTE : no need to check - we are explicitly processing a plural-attribute
applyFiltering(rootQuerySpec, rootTableGroup, attributeMapping, sqlAstCreationState);
applyOrdering(rootTableGroup, attributeMapping);
return new SelectStatement(rootQuerySpec, List.of(new CollectionDomainResult(rootNavigablePath, attributeMapping, null, rootTableGroup, sqlAstCreationState)));
}
Aggregations