From 055ce0c54239b6b1e3fab6f6b0754a6743519c7f Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 19 Sep 2019 07:36:41 -0500 Subject: [PATCH] cleanup --- .../BasicValuedSingularAttributeMapping.java | 5 +- .../internal/EmbeddedAttributeMapping.java | 7 +- .../internal/AbstractPluralAttribute.java | 3 +- .../domain/internal/DomainModelHelper.java | 178 ------------------ .../domain/internal/ListAttributeImpl.java | 3 +- .../domain/internal/MapAttributeImpl.java | 3 +- .../internal/SingularAttributeImpl.java | 3 +- .../sqm/internal/SqmMappingModelHelper.java | 169 +++++++++++++++++ .../BasicValuedPathInterpretation.java | 5 +- .../EmbeddableValuedPathInterpretation.java | 5 +- .../query/sqm/tree/expression/SqmLiteral.java | 4 +- 11 files changed, 187 insertions(+), 198 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java index 49f899a1ba..43d5e71150 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedSingularAttributeMapping.java @@ -18,13 +18,12 @@ import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess; import org.hibernate.metamodel.model.convert.spi.BasicValueConverter; -import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.query.NavigablePath; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.sql.SqlAstCreationState; import org.hibernate.query.sqm.sql.SqlExpressionResolver; import org.hibernate.sql.ast.Clause; -import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.from.TableGroup; @@ -166,7 +165,7 @@ public class BasicValuedSingularAttributeMapping extends AbstractSingularAttribu final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().resolveTableGroup( fetchParent.getNavigablePath(), - pnp -> DomainModelHelper.resolveLhs( fetchParent.getNavigablePath(), sqlAstCreationState ) + pnp -> SqmMappingModelHelper.resolveLhs( fetchParent.getNavigablePath(), sqlAstCreationState ) ); final SqlSelection sqlSelection = resolveSqlSelection( tableGroup, creationState ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java index 948d2111fb..828271d58c 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/EmbeddedAttributeMapping.java @@ -23,17 +23,14 @@ import org.hibernate.metamodel.mapping.ManagedMappingType; import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.mapping.SingularAttributeMapping; import org.hibernate.metamodel.mapping.StateArrayContributorMetadataAccess; -import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; import org.hibernate.property.access.spi.PropertyAccess; import org.hibernate.query.NavigablePath; -import org.hibernate.query.sqm.SqmPathSource; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.sql.SqlAstCreationState; import org.hibernate.query.sqm.sql.SqlExpressionResolver; import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; -import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.JoinType; -import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.expression.SqlTuple; @@ -218,7 +215,7 @@ public class EmbeddedAttributeMapping lnp -> { // there is not yet a TableGroup associated with this path - create one... - final TableGroup lhsLhsTableGroup = DomainModelHelper.resolveLhs( lhsPath, creationState ); + final TableGroup lhsLhsTableGroup = SqmMappingModelHelper.resolveLhs( lhsPath, creationState ); final CompositeTableGroup compositeTableGroup = new CompositeTableGroup( lnp, diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java index 5a70b3eacb..47a3c1d430 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java @@ -16,6 +16,7 @@ import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -51,7 +52,7 @@ public abstract class AbstractPluralAttribute this.classification = builder.getCollectionClassification(); - this.elementPathSource = DomainModelHelper.resolveSqmPathSource( + this.elementPathSource = SqmMappingModelHelper.resolveSqmPathSource( getName(), builder.getValueType(), BindableType.PLURAL_ATTRIBUTE diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java index 6395f13e71..f536685dac 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainModelHelper.java @@ -31,12 +31,7 @@ import org.hibernate.query.sqm.sql.SqlAstCreationState; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; -import org.hibernate.query.sqm.tree.from.SqmFrom; -import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.tree.from.TableGroup; -import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.Fetch; -import org.hibernate.sql.results.spi.FetchParent; import org.hibernate.type.BasicType; /** @@ -84,177 +79,4 @@ public class DomainModelHelper { } - /** - * Resolve a JPA EntityType descriptor to it's corresponding EntityPersister - * in the Hibernate mapping type system - */ - public static EntityPersister resolveEntityPersister( - EntityDomainType entityType, - SessionFactoryImplementor sessionFactory) { - // Our EntityTypeImpl#getType impl returns the Hibernate entity-name - // which is exactly what we want - final String hibernateEntityName = entityType.getHibernateEntityName(); - return sessionFactory.getMetamodel().entityPersister( hibernateEntityName ); - } - - public static SqmPathSource resolveSqmPathSource( - String name, - DomainType valueDomainType, - Bindable.BindableType jpaBindableType) { - - if ( valueDomainType instanceof BasicDomainType ) { - return new BasicSqmPathSource<>( - name, - (BasicDomainType) valueDomainType, - jpaBindableType - ); - } - - if ( valueDomainType instanceof AnyMappingDomainType ) { - return new AnyMappingSqmPathSource<>( - name, - (AnyMappingDomainType) valueDomainType, - jpaBindableType - ); - } - - if ( valueDomainType instanceof EmbeddableDomainType ) { - return new EmbeddedSqmPathSource<>( - name, - (EmbeddableDomainType) valueDomainType, - jpaBindableType - ); - } - - if ( valueDomainType instanceof EntityDomainType ) { - return new EntitySqmPathSource<>( - name, - (EntityDomainType) valueDomainType, - jpaBindableType - ); - } - - throw new IllegalArgumentException( - "Unrecognized value type Java-type [" + valueDomainType.getTypeName() + "] for plural attribute value" - ); - } - - public static MappingModelExpressable resolveMappingModelExpressable( - SqmTypedNode sqmNode, - SqlAstCreationState creationState) { - if ( sqmNode instanceof SqmPath ) { - return resolveSqmPath( (SqmPath) sqmNode, creationState ); - } - - final SqmExpressable nodeType = sqmNode.getNodeType(); - if ( nodeType instanceof BasicType ) { - return ( (BasicType) nodeType ); - } - - throw new NotYetImplementedFor6Exception( DomainModelHelper.class ); - } - - private static ModelPart resolveSqmPath(SqmPath sqmPath, SqlAstCreationState creationState) { - final DomainMetamodel domainModel = creationState.getCreationContext().getDomainModel(); - - if ( sqmPath instanceof SqmTreatedPath ) { - final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath; - final EntityDomainType treatTargetType = treatedPath.getTreatTarget(); - return domainModel.findEntityDescriptor( treatTargetType.getHibernateEntityName() ); - } - - // see if the LHS is treated - if ( sqmPath.getLhs() instanceof SqmTreatedPath ) { - final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath.getLhs(); - final EntityDomainType treatTargetType = treatedPath.getTreatTarget(); - final EntityPersister container = domainModel.findEntityDescriptor( treatTargetType.getHibernateEntityName() ); - - return container.findSubPart( sqmPath.getNavigablePath().getLocalName(), container ); - } - - final TableGroup lhsTableGroup = resolveLhs( sqmPath, creationState ); - lhsTableGroup.getModelPart().prepareAsLhs( sqmPath.getNavigablePath(), creationState ); - return lhsTableGroup.getModelPart().findSubPart( sqmPath.getReferencedPathSource().getPathName(), null ); - } - - public static TableGroup resolveLhs(SqmPath sqmPath, SqlAstCreationState creationState) { - final SqmPath lhs = sqmPath.getLhs(); - - final TableGroup tableGroup = creationState.getFromClauseAccess().resolveTableGroup( - lhs.getNavigablePath(), - lhsNp -> { - assert !( lhs instanceof SqmFrom ); - assert lhs.getLhs() != null; - - final TableGroup lhsLhsTableGroup = resolveLhs( lhs, creationState ); - - final ModelPart lhsPart = lhsLhsTableGroup.getModelPart().findSubPart( - lhs.getReferencedPathSource().getPathName(), - null - ); - - return ( (Queryable) lhsPart ).prepareAsLhs( sqmPath.getNavigablePath(), creationState ); - } - ); - - SqmTreeTransformationLogger.LOGGER.debugf( - "Resolved TableGroup [%s] as the left-hand side for interpretations of SqmPath [%s]", - tableGroup, - sqmPath - ); - - return tableGroup; - } - - public static TableGroup resolveLhs(NavigablePath navigablePath, SqlAstCreationState creationState) { - assert navigablePath.getParent() != null; - - final TableGroup tableGroup = creationState.getFromClauseAccess().resolveTableGroup( - navigablePath.getParent(), - lhsNp -> { - // LHS does not yet have an associated TableGroup.. - - final TableGroup lhsLhsTableGroup = resolveLhs( lhsNp, creationState ); - - final ModelPart lhsPart = lhsLhsTableGroup.getModelPart().findSubPart( - lhsNp.getLocalName(), - null - ); - - return ( (Queryable) lhsPart ).prepareAsLhs( navigablePath, creationState ); - } - ); - - SqmTreeTransformationLogger.LOGGER.debugf( - "Resolved NavigablePath : [%s] -> [%s]", - navigablePath.getParent(), - tableGroup - ); - - return tableGroup; - } - - public static TableGroup resolve(FetchParent fetchParent, DomainResultCreationState creationState) { - final SqlAstCreationState sqlAstCreationState = creationState.getSqlAstCreationState(); - final FromClauseAccess fromClauseAccess = sqlAstCreationState.getFromClauseAccess(); - - return fromClauseAccess.resolveTableGroup( - fetchParent.getNavigablePath(), - pnp -> { - // `fetchParent` does not yet have an associated TableGroup.. - - assert fetchParent.getNavigablePath().getParent() != null; - - final TableGroup parentParentTableGroup = resolveLhs( - fetchParent.getNavigablePath().getParent(), - sqlAstCreationState - ); - - return parentParentTableGroup.getModelPart().prepareAsLhs( - fetchParent.getNavigablePath(), - sqlAstCreationState - ); - } - ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java index 3d6ae9154b..71060b7a37 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/ListAttributeImpl.java @@ -12,6 +12,7 @@ import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.model.domain.ListPersistentAttribute; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.SqmListJoin; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; @@ -27,7 +28,7 @@ class ListAttributeImpl extends AbstractPluralAttribute, E> imp super( builder, metadataContext ); //noinspection unchecked - this.indexPathSource = (SqmPathSource) DomainModelHelper.resolveSqmPathSource( + this.indexPathSource = (SqmPathSource) SqmMappingModelHelper.resolveSqmPathSource( getName(), builder.getListIndexOrMapKeyType(), BindableType.PLURAL_ATTRIBUTE diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java index 1c9a1eb8e0..29e4c0b38a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MapAttributeImpl.java @@ -14,6 +14,7 @@ import org.hibernate.metamodel.model.domain.MapPersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.SqmMapJoin; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; @@ -28,7 +29,7 @@ class MapAttributeImpl extends AbstractPluralAttribute, V> MapAttributeImpl(PluralAttributeBuilder, V, K> xceBuilder, MetadataContext metadataContext) { super( xceBuilder, metadataContext ); - this.keyPathSource = DomainModelHelper.resolveSqmPathSource( + this.keyPathSource = SqmMappingModelHelper.resolveSqmPathSource( getName(), xceBuilder.getListIndexOrMapKeyType(), BindableType.PLURAL_ATTRIBUTE diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java index b86e2724ca..e9e92ebd5f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java @@ -18,6 +18,7 @@ import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmSingularJoin; @@ -65,7 +66,7 @@ public class SingularAttributeImpl this.isOptional = isOptional; - this.sqmPathSource = DomainModelHelper.resolveSqmPathSource( + this.sqmPathSource = SqmMappingModelHelper.resolveSqmPathSource( name, attributeType, BindableType.SINGULAR_ATTRIBUTE diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java new file mode 100644 index 0000000000..cc65ae26a5 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmMappingModelHelper.java @@ -0,0 +1,169 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later + * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html + */ +package org.hibernate.query.sqm.internal; + +import javax.persistence.metamodel.Bindable; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.metamodel.mapping.ModelPart; +import org.hibernate.metamodel.mapping.Queryable; +import org.hibernate.metamodel.model.domain.AnyMappingDomainType; +import org.hibernate.metamodel.model.domain.BasicDomainType; +import org.hibernate.metamodel.model.domain.DomainType; +import org.hibernate.metamodel.model.domain.EmbeddableDomainType; +import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.metamodel.model.domain.internal.AnyMappingSqmPathSource; +import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource; +import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; +import org.hibernate.metamodel.model.domain.internal.EmbeddedSqmPathSource; +import org.hibernate.metamodel.model.domain.internal.EntitySqmPathSource; +import org.hibernate.metamodel.spi.DomainMetamodel; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.query.NavigablePath; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.SqmPathSource; +import org.hibernate.query.sqm.SqmTreeTransformationLogger; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.tree.SqmTypedNode; +import org.hibernate.query.sqm.tree.domain.SqmPath; +import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; +import org.hibernate.sql.ast.tree.from.TableGroup; +import org.hibernate.type.BasicType; + +/** + * Helper for dealing with Hibernate's "mapping model" while processing an SQM which is defined + * in terms of the JPA/SQM metamodel + * + * @author Steve Ebersole + */ +public class SqmMappingModelHelper { + private SqmMappingModelHelper() { + } + + /** + * Resolve a JPA EntityType descriptor to it's corresponding EntityPersister + * in the Hibernate mapping type system + */ + public static EntityPersister resolveEntityPersister( + EntityDomainType entityType, + SessionFactoryImplementor sessionFactory) { + // Our EntityTypeImpl#getType impl returns the Hibernate entity-name + // which is exactly what we want + final String hibernateEntityName = entityType.getHibernateEntityName(); + return sessionFactory.getMetamodel().entityPersister( hibernateEntityName ); + } + + public static SqmPathSource resolveSqmPathSource( + String name, + DomainType valueDomainType, + Bindable.BindableType jpaBindableType) { + + if ( valueDomainType instanceof BasicDomainType ) { + return new BasicSqmPathSource<>( + name, + (BasicDomainType) valueDomainType, + jpaBindableType + ); + } + + if ( valueDomainType instanceof AnyMappingDomainType ) { + return new AnyMappingSqmPathSource<>( + name, + (AnyMappingDomainType) valueDomainType, + jpaBindableType + ); + } + + if ( valueDomainType instanceof EmbeddableDomainType ) { + return new EmbeddedSqmPathSource<>( + name, + (EmbeddableDomainType) valueDomainType, + jpaBindableType + ); + } + + if ( valueDomainType instanceof EntityDomainType ) { + return new EntitySqmPathSource<>( + name, + (EntityDomainType) valueDomainType, + jpaBindableType + ); + } + + throw new IllegalArgumentException( + "Unrecognized value type Java-type [" + valueDomainType.getTypeName() + "] for plural attribute value" + ); + } + + public static MappingModelExpressable resolveMappingModelExpressable( + SqmTypedNode sqmNode, + SqlAstCreationState creationState) { + if ( sqmNode instanceof SqmPath ) { + return resolveSqmPath( (SqmPath) sqmNode, creationState ); + } + + final SqmExpressable nodeType = sqmNode.getNodeType(); + if ( nodeType instanceof BasicType ) { + return ( (BasicType) nodeType ); + } + + throw new NotYetImplementedFor6Exception( DomainModelHelper.class ); + } + + private static ModelPart resolveSqmPath(SqmPath sqmPath, SqlAstCreationState creationState) { + final DomainMetamodel domainModel = creationState.getCreationContext().getDomainModel(); + + if ( sqmPath instanceof SqmTreatedPath ) { + final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath; + final EntityDomainType treatTargetType = treatedPath.getTreatTarget(); + return domainModel.findEntityDescriptor( treatTargetType.getHibernateEntityName() ); + } + + // see if the LHS is treated + if ( sqmPath.getLhs() instanceof SqmTreatedPath ) { + final SqmTreatedPath treatedPath = (SqmTreatedPath) sqmPath.getLhs(); + final EntityDomainType treatTargetType = treatedPath.getTreatTarget(); + final EntityPersister container = domainModel.findEntityDescriptor( treatTargetType.getHibernateEntityName() ); + + return container.findSubPart( sqmPath.getNavigablePath().getLocalName(), container ); + } + + final TableGroup lhsTableGroup = resolveLhs( sqmPath.getNavigablePath(), creationState ); + lhsTableGroup.getModelPart().prepareAsLhs( sqmPath.getNavigablePath(), creationState ); + return lhsTableGroup.getModelPart().findSubPart( sqmPath.getReferencedPathSource().getPathName(), null ); + } + + public static TableGroup resolveLhs(NavigablePath navigablePath, SqlAstCreationState creationState) { + assert navigablePath.getParent() != null; + + final TableGroup tableGroup = creationState.getFromClauseAccess().resolveTableGroup( + navigablePath.getParent(), + lhsNp -> { + // LHS does not yet have an associated TableGroup.. + + final TableGroup lhsLhsTableGroup = resolveLhs( lhsNp, creationState ); + + final ModelPart lhsPart = lhsLhsTableGroup.getModelPart().findSubPart( + lhsNp.getLocalName(), + null + ); + + return ( (Queryable) lhsPart ).prepareAsLhs( navigablePath, creationState ); + } + ); + + SqmTreeTransformationLogger.LOGGER.debugf( + "Resolved NavigablePath : [%s] -> [%s]", + navigablePath.getParent(), + tableGroup + ); + + return tableGroup; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java index 9a40df43a2..8b74749d40 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/BasicValuedPathInterpretation.java @@ -10,14 +10,13 @@ import java.util.function.Consumer; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.metamodel.mapping.BasicValuedModelPart; -import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmPathSource; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.sql.SqlAstCreationState; import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath; -import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.spi.SqlAstCreationContext; import org.hibernate.sql.ast.tree.expression.Expression; @@ -37,7 +36,7 @@ public class BasicValuedPathInterpretation implements AssignableSqmPathInterp SqmBasicValuedSimplePath sqmPath, SqlAstCreationState sqlAstCreationState, SemanticQueryWalker sqmWalker) { - final TableGroup tableGroup = DomainModelHelper.resolveLhs( sqmPath, sqlAstCreationState ); + final TableGroup tableGroup = SqmMappingModelHelper.resolveLhs( sqmPath.getNavigablePath(), sqlAstCreationState ); tableGroup.getModelPart().prepareAsLhs( sqmPath.getNavigablePath(), sqlAstCreationState ); final BasicValuedModelPart mapping = (BasicValuedModelPart) tableGroup.getModelPart().findSubPart( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java index f3645e4745..19af98b848 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/EmbeddableValuedPathInterpretation.java @@ -10,14 +10,13 @@ import java.util.function.Consumer; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart; -import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; import org.hibernate.query.NavigablePath; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmPathSource; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.sql.SqlAstCreationState; import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath; -import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.spi.SqlAstCreationContext; import org.hibernate.sql.ast.tree.expression.Expression; @@ -38,7 +37,7 @@ public class EmbeddableValuedPathInterpretation implements AssignableSqmPathI SqmEmbeddedValuedSimplePath sqmPath, SqlAstCreationState sqlAstCreationState, SemanticQueryWalker sqmWalker) { - final TableGroup tableGroup = DomainModelHelper.resolveLhs( sqmPath, sqlAstCreationState ); + final TableGroup tableGroup = SqmMappingModelHelper.resolveLhs( sqmPath.getNavigablePath(), sqlAstCreationState ); tableGroup.getModelPart().prepareAsLhs( sqmPath.getNavigablePath(), sqlAstCreationState ); final EmbeddableValuedModelPart mapping = (EmbeddableValuedModelPart) tableGroup.getModelPart().findSubPart( diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java index cff664f47f..f26026c65b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java @@ -6,10 +6,10 @@ */ package org.hibernate.query.sqm.tree.expression; -import org.hibernate.metamodel.model.domain.internal.DomainModelHelper; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.internal.SqmMappingModelHelper; import org.hibernate.query.sqm.sql.SqlAstCreationState; import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.query.sqm.sql.internal.DomainResultProducer; @@ -53,7 +53,7 @@ public class SqmLiteral SqlAstCreationState sqlAstCreationState) { return new QueryLiteral( getLiteralValue(), - DomainModelHelper.resolveMappingModelExpressable( this, sqlAstCreationState ), + SqmMappingModelHelper.resolveMappingModelExpressable( this, sqlAstCreationState ), clause ); }