Search in sources :

Example 1 with SqmCrossJoin

use of org.hibernate.query.sqm.tree.from.SqmCrossJoin 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

Root (jakarta.persistence.criteria.Root)1 SqmCreationProcessingState (org.hibernate.query.hql.spi.SqmCreationProcessingState)1 SqmCrossJoin (org.hibernate.query.sqm.tree.from.SqmCrossJoin)1 SqmSubQuery (org.hibernate.query.sqm.tree.select.SqmSubQuery)1