Search in sources :

Example 36 with TableGroup

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

the class ImplicitModelPartResultBuilderEntity method buildResult.

@Override
public EntityResult buildResult(JdbcValuesMetadata jdbcResultsMetadata, int resultPosition, BiFunction<String, String, DynamicFetchBuilderLegacy> legacyFetchResolver, DomainResultCreationState domainResultCreationState) {
    final DomainResultCreationStateImpl creationStateImpl = ResultsHelper.impl(domainResultCreationState);
    creationStateImpl.disallowPositionalSelections();
    final TableGroup tableGroup = creationStateImpl.getFromClauseAccess().resolveTableGroup(navigablePath, np -> {
        if (navigablePath.getParent() != null) {
            return creationStateImpl.getFromClauseAccess().getTableGroup(navigablePath.getParent());
        }
        return modelPart.getEntityMappingType().createRootTableGroup(// since this is only used for result set mappings, the canUseInnerJoins value is irrelevant.
        true, navigablePath, null, null, creationStateImpl, creationStateImpl.getCreationContext());
    });
    return (EntityResult) modelPart.createDomainResult(navigablePath, tableGroup, null, domainResultCreationState);
}
Also used : DomainResultCreationStateImpl(org.hibernate.query.results.DomainResultCreationStateImpl) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) EntityResult(org.hibernate.sql.results.graph.entity.EntityResult)

Example 37 with TableGroup

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

the class AbstractSqlAstTranslator method processTableGroupJoin.

protected void processTableGroupJoin(TableGroupJoin tableGroupJoin, List<TableGroupJoin> tableGroupJoinCollector) {
    final TableGroup joinedGroup = tableGroupJoin.getJoinedGroup();
    final TableGroup realTableGroup;
    if (joinedGroup instanceof LazyTableGroup) {
        realTableGroup = ((LazyTableGroup) joinedGroup).getUnderlyingTableGroup();
    } else {
        realTableGroup = joinedGroup;
    }
    if (realTableGroup instanceof VirtualTableGroup) {
        processNestedTableGroupJoins(realTableGroup, tableGroupJoinCollector);
        if (tableGroupJoinCollector != null) {
            tableGroupJoinCollector.addAll(realTableGroup.getTableGroupJoins());
        } else {
            processTableGroupJoins(realTableGroup);
        }
    } else if (realTableGroup != null) {
        renderTableGroupJoin(tableGroupJoin, tableGroupJoinCollector);
    } else // A lazy table group, even if uninitialized, might contain table group joins
    if (joinedGroup instanceof LazyTableGroup) {
        processNestedTableGroupJoins(joinedGroup, tableGroupJoinCollector);
        if (tableGroupJoinCollector != null) {
            tableGroupJoinCollector.addAll(joinedGroup.getTableGroupJoins());
        } else {
            processTableGroupJoins(joinedGroup);
        }
    }
}
Also used : VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup)

Example 38 with TableGroup

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

the class AbstractSqlAstTranslator method hasNestedTableGroupsToRender.

protected boolean hasNestedTableGroupsToRender(List<TableGroupJoin> nestedTableGroupJoins) {
    for (TableGroupJoin nestedTableGroupJoin : nestedTableGroupJoins) {
        final TableGroup joinedGroup = nestedTableGroupJoin.getJoinedGroup();
        final TableGroup realTableGroup;
        if (joinedGroup instanceof LazyTableGroup) {
            realTableGroup = ((LazyTableGroup) joinedGroup).getUnderlyingTableGroup();
        } else {
            realTableGroup = joinedGroup;
        }
        if (realTableGroup instanceof VirtualTableGroup) {
            if (hasNestedTableGroupsToRender(realTableGroup.getNestedTableGroupJoins())) {
                return true;
            }
        } else if (realTableGroup != null) {
            return true;
        }
    }
    return false;
}
Also used : TableGroupJoin(org.hibernate.sql.ast.tree.from.TableGroupJoin) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup)

Example 39 with TableGroup

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

the class AbstractSqlAstTranslator method visitFromClause.

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// FROM clause
@Override
public void visitFromClause(FromClause fromClause) {
    if (fromClause == null || fromClause.getRoots().isEmpty()) {
        appendSql(getFromDualForSelectOnly());
    } else {
        appendSql(" from ");
        try {
            clauseStack.push(Clause.FROM);
            String separator = NO_SEPARATOR;
            for (TableGroup root : fromClause.getRoots()) {
                // Skip virtual table group roots which we use for simple correlations
                if (!(root instanceof VirtualTableGroup)) {
                    appendSql(separator);
                    renderRootTableGroup(root, null);
                    separator = COMA_SEPARATOR;
                }
            }
        } finally {
            clauseStack.pop();
        }
    }
}
Also used : VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup) LazyTableGroup(org.hibernate.sql.ast.tree.from.LazyTableGroup) TableGroup(org.hibernate.sql.ast.tree.from.TableGroup) QueryPartTableGroup(org.hibernate.sql.ast.tree.from.QueryPartTableGroup) VirtualTableGroup(org.hibernate.sql.ast.tree.from.VirtualTableGroup)

Example 40 with TableGroup

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

the class SimpleFromClauseAccessImpl method registerTableGroup.

@Override
public void registerTableGroup(NavigablePath navigablePath, TableGroup tableGroup) {
    SqlTreeCreationLogger.LOGGER.debugf("Registration of TableGroup [%s] with identifierForTableGroup [%s] for NavigablePath [%s] ", tableGroup, tableGroup.getNavigablePath().getIdentifierForTableGroup(), navigablePath.getIdentifierForTableGroup());
    final TableGroup previous = tableGroupMap.put(navigablePath, tableGroup);
    if (previous != null) {
        SqlTreeCreationLogger.LOGGER.debugf("Registration of TableGroup [%s] for NavigablePath [%s] overrode previous registration : %s", tableGroup, navigablePath, previous);
    }
}
Also used : TableGroup(org.hibernate.sql.ast.tree.from.TableGroup)

Aggregations

TableGroup (org.hibernate.sql.ast.tree.from.TableGroup)144 NavigablePath (org.hibernate.query.spi.NavigablePath)56 LazyTableGroup (org.hibernate.sql.ast.tree.from.LazyTableGroup)56 PluralTableGroup (org.hibernate.sql.ast.tree.from.PluralTableGroup)46 TableGroupJoin (org.hibernate.sql.ast.tree.from.TableGroupJoin)41 TableReference (org.hibernate.sql.ast.tree.from.TableReference)40 PluralAttributeMapping (org.hibernate.metamodel.mapping.PluralAttributeMapping)37 ColumnReference (org.hibernate.sql.ast.tree.expression.ColumnReference)35 CorrelatedTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedTableGroup)33 QueryPartTableGroup (org.hibernate.sql.ast.tree.from.QueryPartTableGroup)31 VirtualTableGroup (org.hibernate.sql.ast.tree.from.VirtualTableGroup)31 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)30 SqlExpressionResolver (org.hibernate.sql.ast.spi.SqlExpressionResolver)29 SqlSelection (org.hibernate.sql.ast.spi.SqlSelection)29 QuerySpec (org.hibernate.sql.ast.tree.select.QuerySpec)29 Fetch (org.hibernate.sql.results.graph.Fetch)29 Expression (org.hibernate.sql.ast.tree.expression.Expression)28 CorrelatedPluralTableGroup (org.hibernate.sql.ast.tree.from.CorrelatedPluralTableGroup)28 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)27 SelectStatement (org.hibernate.sql.ast.tree.select.SelectStatement)27