Search in sources :

Example 6 with SqmCreationProcessingState

use of org.hibernate.query.hql.spi.SqmCreationProcessingState in project hibernate-orm by hibernate.

the class SqmPathRegistryImpl method findFromByAlias.

@Override
public <X extends SqmFrom<?, ?>> X findFromByAlias(String alias, boolean searchParent) {
    final String localAlias = jpaCompliance.isJpaQueryComplianceEnabled() ? alias.toLowerCase(Locale.getDefault()) : alias;
    final SqmFrom<?, ?> registered = sqmFromByAlias.get(localAlias);
    if (registered != null) {
        // noinspection unchecked
        return (X) registered;
    }
    SqmCreationProcessingState parentProcessingState = associatedProcessingState.getParentProcessingState();
    if (searchParent && parentProcessingState != null) {
        X parentRegistered;
        do {
            parentRegistered = parentProcessingState.getPathRegistry().findFromByAlias(alias, false);
            parentProcessingState = parentProcessingState.getParentProcessingState();
        } while (parentProcessingState != null && parentRegistered == null);
        if (parentRegistered != null) {
            // If a parent query contains the alias, we need to create a correlation on the subquery
            final SqmSubQuery<?> selectQuery = (SqmSubQuery<?>) associatedProcessingState.getProcessingQuery();
            SqmFrom<?, ?> correlated;
            if (parentRegistered instanceof Root<?>) {
                correlated = selectQuery.correlate((Root<?>) parentRegistered);
            } else if (parentRegistered instanceof Join<?, ?>) {
                correlated = selectQuery.correlate((Join<?, ?>) parentRegistered);
            } else if (parentRegistered instanceof SqmCrossJoin<?>) {
                correlated = selectQuery.correlate((SqmCrossJoin<?>) parentRegistered);
            } else if (parentRegistered instanceof SqmEntityJoin<?>) {
                correlated = selectQuery.correlate((SqmEntityJoin<?>) parentRegistered);
            } else {
                throw new UnsupportedOperationException("Can't correlate from node: " + parentRegistered);
            }
            register(correlated);
            // noinspection unchecked
            return (X) correlated;
        }
    }
    return null;
}
Also used : SqmSubQuery(org.hibernate.query.sqm.tree.select.SqmSubQuery) SqmCrossJoin(org.hibernate.query.sqm.tree.from.SqmCrossJoin) Root(jakarta.persistence.criteria.Root) SqmCreationProcessingState(org.hibernate.query.hql.spi.SqmCreationProcessingState)

Aggregations

SqmCreationProcessingState (org.hibernate.query.hql.spi.SqmCreationProcessingState)6 SemanticException (org.hibernate.query.SemanticException)4 ParseTree (org.antlr.v4.runtime.tree.ParseTree)3 HqlParser (org.hibernate.grammars.hql.HqlParser)3 SqmPathRegistry (org.hibernate.query.hql.spi.SqmPathRegistry)2 StrictJpaComplianceViolation (org.hibernate.query.sqm.StrictJpaComplianceViolation)2 SqmPolymorphicRootDescriptor (org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor)2 SqmRoot (org.hibernate.query.sqm.tree.from.SqmRoot)2 SqmSelectQuery (org.hibernate.query.sqm.tree.select.SqmSelectQuery)2 SqmSubQuery (org.hibernate.query.sqm.tree.select.SqmSubQuery)2 Root (jakarta.persistence.criteria.Root)1 IDENTIFIER (org.hibernate.grammars.hql.HqlParser.IDENTIFIER)1 EntityDomainType (org.hibernate.metamodel.model.domain.EntityDomainType)1 DotIdentifierConsumer (org.hibernate.query.hql.spi.DotIdentifierConsumer)1 SetOperator (org.hibernate.query.sqm.SetOperator)1 DAY_OF_YEAR (org.hibernate.query.sqm.TemporalUnit.DAY_OF_YEAR)1 TIMEZONE_HOUR (org.hibernate.query.sqm.TemporalUnit.TIMEZONE_HOUR)1 WEEK_OF_YEAR (org.hibernate.query.sqm.TemporalUnit.WEEK_OF_YEAR)1 UnknownEntityException (org.hibernate.query.sqm.UnknownEntityException)1 SqmCreationProcessingStateImpl (org.hibernate.query.sqm.internal.SqmCreationProcessingStateImpl)1