use of org.hibernate.sql.ast.tree.from.CollectionTableGroup in project hibernate-orm by hibernate.
the class PluralAttributeMappingImpl method generateFetch.
@Override
public Fetch generateFetch(FetchParent fetchParent, NavigablePath fetchablePath, FetchTiming fetchTiming, boolean selected, String resultVariable, DomainResultCreationState creationState) {
final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState();
final boolean added = creationState.registerVisitedAssociationKey(fkDescriptor.getAssociationKey());
try {
if (fetchTiming == FetchTiming.IMMEDIATE) {
if (selected) {
final TableGroup collectionTableGroup = resolveCollectionTableGroup(fetchParent, fetchablePath, creationState, sqlAstCreationState);
return new EagerCollectionFetch(fetchablePath, this, collectionTableGroup, fetchParent, creationState);
} else {
return createSelectEagerCollectionFetch(fetchParent, fetchablePath, creationState, sqlAstCreationState);
}
}
if (getCollectionDescriptor().getCollectionType().hasHolder()) {
return createSelectEagerCollectionFetch(fetchParent, fetchablePath, creationState, sqlAstCreationState);
}
return createDelayedCollectionFetch(fetchParent, fetchablePath, creationState, sqlAstCreationState);
} finally {
// and on top of this, we are not handling circular fetches for plural attributes yet
if (added) {
creationState.removeVisitedAssociationKey(fkDescriptor.getAssociationKey());
}
}
}
use of org.hibernate.sql.ast.tree.from.CollectionTableGroup in project hibernate-orm by hibernate.
the class PluralAttributeMappingImpl method createCollectionTableGroup.
private TableGroup createCollectionTableGroup(boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, SqlAliasBase sqlAliasBase, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
assert !getCollectionDescriptor().isOneToMany();
final String collectionTableName = ((Joinable) collectionDescriptor).getTableName();
final TableReference collectionTableReference = new NamedTableReference(collectionTableName, sqlAliasBase.generateNewAlias(), true, creationContext.getSessionFactory());
final CollectionTableGroup tableGroup = new CollectionTableGroup(canUseInnerJoins, navigablePath, this, fetched, sourceAlias, collectionTableReference, true, sqlAliasBase, s -> false, null, creationContext.getSessionFactory());
if (elementDescriptor instanceof TableGroupJoinProducer) {
final TableGroupJoin tableGroupJoin = ((TableGroupJoinProducer) elementDescriptor).createTableGroupJoin(navigablePath.append(CollectionPart.Nature.ELEMENT.getName()), tableGroup, null, SqlAstJoinType.INNER, fetched, false, stem -> sqlAliasBase, sqlExpressionResolver, fromClauseAccess, creationContext);
tableGroup.registerElementTableGroup(tableGroupJoin);
}
if (indexDescriptor instanceof TableGroupJoinProducer) {
final TableGroupJoin tableGroupJoin = ((TableGroupJoinProducer) indexDescriptor).createTableGroupJoin(navigablePath.append(CollectionPart.Nature.INDEX.getName()), tableGroup, null, SqlAstJoinType.INNER, fetched, false, stem -> sqlAliasBase, sqlExpressionResolver, fromClauseAccess, creationContext);
tableGroup.registerIndexTableGroup(tableGroupJoin);
}
return tableGroup;
}
use of org.hibernate.sql.ast.tree.from.CollectionTableGroup 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);
}
Aggregations