Search in sources :

Example 11 with SqlAstJoinType

use of org.hibernate.sql.ast.SqlAstJoinType in project hibernate-orm by hibernate.

the class PluralAttributeMappingImpl method createRootTableGroupJoin.

@Override
public TableGroup createRootTableGroupJoin(NavigablePath navigablePath, TableGroup lhs, String explicitSourceAlias, SqlAstJoinType requestedJoinType, boolean fetched, Consumer<Predicate> predicateConsumer, SqlAliasBaseGenerator aliasBaseGenerator, SqlExpressionResolver sqlExpressionResolver, FromClauseAccess fromClauseAccess, SqlAstCreationContext creationContext) {
    final SqlAstJoinType joinType;
    if (requestedJoinType == null) {
        joinType = SqlAstJoinType.INNER;
    } else {
        joinType = requestedJoinType;
    }
    final CollectionPersister collectionDescriptor = getCollectionDescriptor();
    final TableGroup tableGroup;
    if (collectionDescriptor.isOneToMany()) {
        tableGroup = createOneToManyTableGroup(lhs.canUseInnerJoins() && joinType == SqlAstJoinType.INNER, navigablePath, fetched, explicitSourceAlias, aliasBaseGenerator.createSqlAliasBase(getSqlAliasStem()), sqlExpressionResolver, fromClauseAccess, creationContext);
    } else {
        tableGroup = createCollectionTableGroup(lhs.canUseInnerJoins() && joinType == SqlAstJoinType.INNER, navigablePath, fetched, explicitSourceAlias, aliasBaseGenerator.createSqlAliasBase(getSqlAliasStem()), sqlExpressionResolver, fromClauseAccess, creationContext);
    }
    if (predicateConsumer != null) {
        predicateConsumer.accept(getKeyDescriptor().generateJoinPredicate(lhs, tableGroup, sqlExpressionResolver, creationContext));
    }
    return tableGroup;
}
Also used : CollectionPersister(org.hibernate.persister.collection.CollectionPersister) CollectionTableGroup(org.hibernate.sql.ast.tree.from.CollectionTableGroup) OneToManyTableGroup(org.hibernate.sql.ast.tree.from.OneToManyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType)

Example 12 with SqlAstJoinType

use of org.hibernate.sql.ast.SqlAstJoinType in project hibernate-orm by hibernate.

the class EntityCollectionPart method createTableGroupJoin.

@Override
public TableGroupJoin createTableGroupJoin(NavigablePath navigablePath, TableGroup collectionTableGroup, 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;
    }
    if (collectionDescriptor.isOneToMany() && nature == Nature.ELEMENT) {
        // If this is a one-to-many, the element part is already available, so we return a TableGroupJoin "hull"
        return new TableGroupJoin(navigablePath, joinType, ((OneToManyTableGroup) collectionTableGroup).getElementTableGroup(), null);
    }
    final LazyTableGroup lazyTableGroup = createRootTableGroupJoin(navigablePath, collectionTableGroup, explicitSourceAlias, requestedJoinType, fetched, null, aliasBaseGenerator, sqlExpressionResolver, fromClauseAccess, creationContext);
    final TableGroupJoin join = new TableGroupJoin(navigablePath, joinType, lazyTableGroup, null);
    lazyTableGroup.setTableGroupInitializerCallback(tableGroup -> join.applyPredicate(fkDescriptor.generateJoinPredicate(tableGroup.getPrimaryTableReference(), collectionTableGroup.resolveTableReference(fkDescriptor.getKeyTable()), sqlExpressionResolver, creationContext)));
    return join;
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) SqlAstJoinType(org.hibernate.sql.ast.SqlAstJoinType)

Aggregations

SqlAstJoinType (org.hibernate.sql.ast.SqlAstJoinType)12 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)10 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)9 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)5 StandardVirtualTableGroup (org.hibernate.sql.ast.tree.from.StandardVirtualTableGroup)5 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)4 NavigablePath (org.hibernate.query.spi.NavigablePath)3 SqlAliasBase (org.hibernate.sql.ast.spi.SqlAliasBase)3 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)3 TableReference (org.hibernate.sql.ast.tree.from.TableReference)3 EmbeddableValuedModelPart (org.hibernate.metamodel.mapping.EmbeddableValuedModelPart)2 AbstractEntityPersister (org.hibernate.persister.entity.AbstractEntityPersister)2 EntityPersister (org.hibernate.persister.entity.EntityPersister)2 TreatedNavigablePath (org.hibernate.query.spi.TreatedNavigablePath)2 EntityIdentifierNavigablePath (org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath)2 MappedByTableGroup (org.hibernate.sql.ast.tree.from.MappedByTableGroup)2 StandardTableGroup (org.hibernate.sql.ast.tree.from.StandardTableGroup)2 TableGroupProducer (org.hibernate.sql.ast.tree.from.TableGroupProducer)2 Predicate (org.hibernate.sql.ast.tree.predicate.Predicate)2 ArrayList (java.util.ArrayList)1