Search in sources :

Example 6 with LazyTableGroup

use of org.hibernate.sql.ast.tree.from.LazyTableGroup 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)

Example 7 with LazyTableGroup

use of org.hibernate.sql.ast.tree.from.LazyTableGroup in project hibernate-orm by hibernate.

the class SqlTreePrinter method logTableGroupDetails.

private void logTableGroupDetails(TableGroup tableGroup) {
    if (tableGroup instanceof LazyTableGroup) {
        TableGroup underlyingTableGroup = ((LazyTableGroup) tableGroup).getUnderlyingTableGroup();
        if (underlyingTableGroup != null) {
            logTableGroupDetails(underlyingTableGroup);
        }
        return;
    }
    if (tableGroup.getPrimaryTableReference() instanceof NamedTableReference) {
        logWithIndentation("primaryTableReference : %s as %s", tableGroup.getPrimaryTableReference().getTableId(), tableGroup.getPrimaryTableReference().getIdentificationVariable());
    } else {
        if (tableGroup.getPrimaryTableReference() instanceof ValuesTableReference) {
            logWithIndentation("primaryTableReference : values (..) as %s", tableGroup.getPrimaryTableReference().getIdentificationVariable());
        } else if (tableGroup.getPrimaryTableReference() instanceof FunctionTableReference) {
            logWithIndentation("primaryTableReference : %s(...) as %s", ((FunctionTableReference) tableGroup.getPrimaryTableReference()).getFunctionExpression().getFunctionName(), tableGroup.getPrimaryTableReference().getIdentificationVariable());
        } else {
            logNode("PrimaryTableReference as " + tableGroup.getPrimaryTableReference().getIdentificationVariable(), () -> {
                QueryPart queryPart = ((QueryPartTableReference) tableGroup.getPrimaryTableReference()).getQueryPart();
                visitQueryPart(queryPart);
            });
        }
    }
    final List<TableReferenceJoin> tableReferenceJoins = tableGroup.getTableReferenceJoins();
    if (!tableReferenceJoins.isEmpty()) {
        logNode("TableReferenceJoins", () -> {
            for (TableReferenceJoin join : tableReferenceJoins) {
                logWithIndentation("%s join %s as %s", join.getJoinType().getText(), join.getJoinedTableReference().getTableExpression(), join.getJoinedTableReference().getIdentificationVariable());
            }
        });
    }
    final List<TableGroupJoin> nestedTableGroupJoins = tableGroup.getNestedTableGroupJoins();
    if (!nestedTableGroupJoins.isEmpty()) {
        logNode("NestedTableGroupJoins", () -> tableGroup.visitNestedTableGroupJoins(this::visitTableGroupJoin));
    }
    final List<TableGroupJoin> tableGroupJoins = tableGroup.getTableGroupJoins();
    if (!tableGroupJoins.isEmpty()) {
        logNode("TableGroupJoins", () -> tableGroup.visitTableGroupJoins(this::visitTableGroupJoin));
    }
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) NamedTableReference(org.hibernate.sql.ast.tree.from.NamedTableReference) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) FunctionTableReference(org.hibernate.sql.ast.tree.from.FunctionTableReference) QueryPart(org.hibernate.sql.ast.tree.select.QueryPart) ValuesTableReference(org.hibernate.sql.ast.tree.from.ValuesTableReference) TableReferenceJoin(org.hibernate.sql.ast.tree.from.TableReferenceJoin)

Aggregations

LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)7 TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)5 SqlAstJoinType (org.hibernate.sql.ast.SqlAstJoinType)4 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)4 NavigablePath (org.hibernate.query.spi.NavigablePath)3 SqlAliasBase (org.hibernate.sql.ast.spi.SqlAliasBase)3 TableReference (org.hibernate.sql.ast.tree.from.TableReference)3 EmbeddableValuedModelPart (org.hibernate.metamodel.mapping.EmbeddableValuedModelPart)2 TreatedNavigablePath (org.hibernate.query.spi.TreatedNavigablePath)2 EntityIdentifierNavigablePath (org.hibernate.query.sqm.spi.EntityIdentifierNavigablePath)2 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)2 MappedByTableGroup (org.hibernate.sql.ast.tree.from.MappedByTableGroup)2 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)2 QueryPartTableGroup (org.hibernate.sql.ast.tree.from.QueryPartTableGroup)2 StandardTableGroup (org.hibernate.sql.ast.tree.from.StandardTableGroup)2 TableGroupProducer (org.hibernate.sql.ast.tree.from.TableGroupProducer)2 VirtualTableGroup (org.hibernate.sql.ast.tree.from.VirtualTableGroup)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1