use of org.hibernate.sql.ast.tree.from.TableGroup 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.TableGroup in project hibernate-orm by hibernate.
the class PluralAttributeMappingImpl method createTableGroupJoin.
@Override
public TableGroupJoin createTableGroupJoin(NavigablePath navigablePath, TableGroup lhs, String explicitSourceAlias, SqlAstJoinType requestedJoinType, boolean fetched, boolean addsPredicate, SqlAliasBaseGenerator aliasBaseGenerator, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
final SqlAstJoinType joinType;
if (requestedJoinType == null) {
joinType = SqlAstJoinType.INNER;
} else {
joinType = requestedJoinType;
}
final java.util.List<Predicate> predicates = new ArrayList<>(2);
final TableGroup tableGroup = createRootTableGroupJoin(navigablePath, lhs, explicitSourceAlias, requestedJoinType, fetched, predicates::add, aliasBaseGenerator, sqlExpressionResolver, fromClauseAccess, creationContext);
final TableGroupJoin tableGroupJoin = new TableGroupJoin(navigablePath, joinType, tableGroup, null);
predicates.forEach(tableGroupJoin::applyPredicate);
return tableGroupJoin;
}
use of org.hibernate.sql.ast.tree.from.TableGroup in project hibernate-orm by hibernate.
the class PluralAttributeMappingImpl method createOneToManyTableGroup.
private TableGroup createOneToManyTableGroup(boolean canUseInnerJoins, NavigablePath navigablePath, boolean fetched, String sourceAlias, SqlAliasBase sqlAliasBase, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
final TableGroup elementTableGroup = ((EntityCollectionPart) elementDescriptor).createTableGroupInternal(canUseInnerJoins, navigablePath.append(CollectionPart.Nature.ELEMENT.getName()), fetched, sourceAlias, sqlAliasBase, sqlExpressionResolver, creationContext);
final OneToManyTableGroup tableGroup = new OneToManyTableGroup(this, elementTableGroup, creationContext.getSessionFactory());
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.TableGroup 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.ast.tree.from.TableGroup in project hibernate-orm by hibernate.
the class BasicAttributeMapping method resolveSqlSelection.
private SqlSelection resolveSqlSelection(NavigablePath navigablePath, TableGroup tableGroup, boolean allowFkOptimization, DomainResultCreationState creationState) {
final SqlExpressionResolver expressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
final TableReference tableReference = tableGroup.resolveTableReference(navigablePath, getContainingTableExpression(), allowFkOptimization);
return expressionResolver.resolveSqlSelection(expressionResolver.resolveSqlExpression(SqlExpressionResolver.createColumnReferenceKey(tableReference, mappedColumnExpression), sqlAstProcessingState -> new ColumnReference(tableReference, this, creationState.getSqlAstCreationState().getCreationContext().getSessionFactory())), valueConverter == null ? getMappedType().getMappedJavaType() : valueConverter.getRelationalJavaType(), creationState.getSqlAstCreationState().getCreationContext().getSessionFactory().getTypeConfiguration());
}
Aggregations