From ce5f0c60eecc71d03f7f9a0f0adc5fa8eaa899d9 Mon Sep 17 00:00:00 2001 From: Christian Beikov Date: Fri, 17 Mar 2023 12:10:41 +0100 Subject: [PATCH] Remove SelfInterpretingSqmPath and remove some warnings --- .../domain/internal/DiscriminatorSqmPath.java | 42 +++++-------------- .../query/sqm/SemanticQueryWalker.java | 8 ++-- .../query/sqm/internal/SqmTreePrinter.java | 10 ++--- .../sqm/spi/BaseSemanticQueryWalker.java | 9 ++-- .../sqm/sql/BaseSqmToSqlAstConverter.java | 16 ++++--- .../DiscriminatorPathInterpretation.java | 28 ++++++++++++- .../sql/internal/SelfInterpretingSqmPath.java | 26 ------------ 7 files changed, 57 insertions(+), 82 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SelfInterpretingSqmPath.java diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPath.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPath.java index 222bc39245..ff36f49a1b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DiscriminatorSqmPath.java @@ -8,26 +8,18 @@ package org.hibernate.metamodel.model.domain.internal; import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.mapping.EntityMappingType; -import org.hibernate.metamodel.mapping.EntityValuedModelPart; -import org.hibernate.metamodel.mapping.ModelPartContainer; -import org.hibernate.metamodel.mapping.PluralAttributeMapping; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.spi.NavigablePath; import org.hibernate.query.PathException; import org.hibernate.query.hql.spi.SqmCreationState; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmPathSource; -import org.hibernate.query.sqm.sql.internal.DiscriminatorPathInterpretation; -import org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath; -import org.hibernate.query.sqm.sql.internal.SqmPathInterpretation; import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.domain.AbstractSqmPath; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType; -import org.hibernate.sql.ast.spi.SqlAstCreationState; -import org.hibernate.sql.ast.tree.from.TableGroup; +import org.hibernate.spi.NavigablePath; /** * SqmPath specialization for an entity discriminator @@ -35,7 +27,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup; * @author Steve Ebersole */ @SuppressWarnings({ "rawtypes", "unchecked" }) -public class DiscriminatorSqmPath extends AbstractSqmPath implements SelfInterpretingSqmPath { +public class DiscriminatorSqmPath extends AbstractSqmPath { private final EntityDomainType entityDomainType; private final EntityMappingType entityDescriptor; @@ -51,6 +43,14 @@ public class DiscriminatorSqmPath extends AbstractSqmPath implements SelfInterpr this.entityDescriptor = entityDescriptor; } + public EntityDomainType getEntityDomainType() { + return entityDomainType; + } + + public EntityMappingType getEntityDescriptor() { + return entityDescriptor; + } + @Override public DiscriminatorSqmPath copy(SqmCopyContext context) { final DiscriminatorSqmPath existing = context.getCopy( this ); @@ -69,27 +69,7 @@ public class DiscriminatorSqmPath extends AbstractSqmPath implements SelfInterpr return walker.visitEntityTypeLiteralExpression( new SqmLiteralEntityType( entityDomainType, nodeBuilder() ) ); } - return walker.visitSelfInterpretingSqmPath( this ); - } - - @Override - public SqmPathInterpretation interpret( - SqlAstCreationState sqlAstCreationState, - SemanticQueryWalker sqmWalker, - boolean jpaQueryComplianceEnabled) { - assert entityDescriptor.hasSubclasses(); - - final TableGroup tableGroup = sqlAstCreationState.getFromClauseAccess().getTableGroup( getNavigablePath().getParent() ); - final ModelPartContainer modelPart = tableGroup.getModelPart(); - final EntityMappingType entityMapping; - if ( modelPart instanceof EntityValuedModelPart ) { - entityMapping = ( (EntityValuedModelPart) modelPart ).getEntityMappingType(); - } - else { - entityMapping = (EntityMappingType) ( (PluralAttributeMapping) modelPart ).getElementDescriptor().getPartMappingType(); - } - - return new DiscriminatorPathInterpretation( getNavigablePath(), entityMapping, tableGroup, sqlAstCreationState ); + return walker.visitDiscriminatorPath( this ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java index cc1e79cc2f..c3694709d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SemanticQueryWalker.java @@ -9,7 +9,7 @@ package org.hibernate.query.sqm; import java.util.List; import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; -import org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath; +import org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath; import org.hibernate.query.sqm.tree.cte.SqmCteContainer; import org.hibernate.query.sqm.tree.cte.SqmCteStatement; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; @@ -232,7 +232,7 @@ public interface SemanticQueryWalker { T visitFkExpression(SqmFkExpression fkExpression); - T visitSelfInterpretingSqmPath(SelfInterpretingSqmPath sqmPath); + T visitDiscriminatorPath(DiscriminatorSqmPath sqmPath); T visitIndexedPluralAccessPath(SqmIndexedCollectionAccessPath path); @@ -310,9 +310,9 @@ public interface SemanticQueryWalker { T visitEntityTypeLiteralExpression(SqmLiteralEntityType expression); - T visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression); + T visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression); - T visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression); + T visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression); T visitParameterizedEntityTypeExpression(SqmParameterizedEntityType expression); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java index d6eefcc882..f1d86f04ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/internal/SqmTreePrinter.java @@ -10,9 +10,9 @@ import java.util.List; import java.util.Locale; import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; +import org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath; import org.hibernate.query.QueryLogging; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath; import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.cte.SqmCteContainer; import org.hibernate.query.sqm.tree.cte.SqmCteStatement; @@ -689,8 +689,8 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitSelfInterpretingSqmPath(SelfInterpretingSqmPath sqmPath) { - logWithIndentation( "-> [self-interpreting-path] - `%s`", sqmPath.getNavigablePath() ); + public Object visitDiscriminatorPath(DiscriminatorSqmPath sqmPath) { + logWithIndentation( "-> [discriminator-path] - `%s`", sqmPath.getNavigablePath() ); return null; } @@ -1087,12 +1087,12 @@ public class SqmTreePrinter implements SemanticQueryWalker { } @Override - public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression) { + public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression) { return null; } @Override - public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { + public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java index 457820ab2f..cdc56e7447 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/spi/BaseSemanticQueryWalker.java @@ -9,9 +9,8 @@ package org.hibernate.query.sqm.spi; import java.util.List; import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; +import org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath; -import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.SqmVisitableNode; import org.hibernate.query.sqm.tree.cte.SqmCteContainer; import org.hibernate.query.sqm.tree.cte.SqmCteStatement; @@ -365,7 +364,7 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker path) { + public Object visitDiscriminatorPath(DiscriminatorSqmPath path) { return path; } @@ -607,12 +606,12 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker expression) { return expression; } @Override - public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { + public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { return expression; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 49c033fd81..c87d28915f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -89,6 +89,7 @@ import org.hibernate.metamodel.mapping.internal.OneToManyCollectionPart; import org.hibernate.metamodel.mapping.internal.SqlTypedMappingImpl; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.metamodel.mapping.ordering.OrderByFragment; +import org.hibernate.query.sqm.sql.internal.DiscriminatorPathInterpretation; import org.hibernate.sql.results.graph.collection.internal.EagerCollectionFetch; import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter; import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; @@ -150,7 +151,6 @@ import org.hibernate.query.sqm.sql.internal.EmbeddableValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.EntityValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.PluralValuedSimplePathInterpretation; -import org.hibernate.query.sqm.sql.internal.SelfInterpretingSqmPath; import org.hibernate.query.sqm.sql.internal.SqlAstProcessingStateImpl; import org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl; import org.hibernate.query.sqm.sql.internal.SqmMapEntryResult; @@ -4092,7 +4092,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base } @Override - public Expression visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath sqmPath) { + public Expression visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath sqmPath) { return withTreatRestriction( prepareReusablePath( sqmPath, @@ -4150,14 +4150,12 @@ public abstract class BaseSqmToSqlAstConverter extends Base } @Override - public Object visitSelfInterpretingSqmPath(SelfInterpretingSqmPath sqmPath) { + public Object visitDiscriminatorPath(DiscriminatorSqmPath sqmPath) { return prepareReusablePath( sqmPath, () -> { - if ( sqmPath instanceof DiscriminatorSqmPath ) { - registerTypeUsage( (DiscriminatorSqmPath) sqmPath ); - } - return sqmPath.interpret( this, this, jpaQueryComplianceEnabled ); + registerTypeUsage( sqmPath ); + return DiscriminatorPathInterpretation.from( sqmPath, this ); } ); } @@ -4845,7 +4843,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base // as that would register a type usage for the table group that we don't want here final DiscriminatorSqmPath discriminatorSqmPath = (DiscriminatorSqmPath) lhs.type(); registerTypeUsage( discriminatorSqmPath ); - final Expression typeExpression = discriminatorSqmPath.interpret( this, this, jpaQueryComplianceEnabled ); + final Expression typeExpression = DiscriminatorPathInterpretation.from( discriminatorSqmPath, this ); if ( subclassEntityNames.size() == 1 ) { return new ComparisonPredicate( typeExpression, @@ -6470,7 +6468,7 @@ public abstract class BaseSqmToSqlAstConverter extends Base @Override - public Expression visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { + public Expression visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { final BasicType domainType = expression.getDomainType(); return new QueryLiteral<>( domainType.convertToRelationalValue( expression.getEntityValue().getJavaType() ), diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatorPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatorPathInterpretation.java index 839c51d800..706ec29af0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatorPathInterpretation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DiscriminatorPathInterpretation.java @@ -8,7 +8,12 @@ package org.hibernate.query.sqm.sql.internal; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; import org.hibernate.metamodel.mapping.EntityMappingType; +import org.hibernate.metamodel.mapping.EntityValuedModelPart; import org.hibernate.metamodel.mapping.JdbcMapping; +import org.hibernate.metamodel.mapping.ModelPartContainer; +import org.hibernate.metamodel.mapping.PluralAttributeMapping; +import org.hibernate.metamodel.model.domain.internal.DiscriminatorSqmPath; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; import org.hibernate.spi.NavigablePath; import org.hibernate.query.results.ResultSetMappingSqlSelection; import org.hibernate.sql.ast.SqlAstWalker; @@ -26,7 +31,7 @@ import org.hibernate.type.spi.TypeConfiguration; * * @author Steve Ebersole */ -public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretation implements DomainResultProducer { +public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretation { private final Expression expression; public DiscriminatorPathInterpretation( @@ -40,6 +45,25 @@ public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretati expression = getDiscriminatorMapping().resolveSqlExpression( navigablePath, jdbcMappingToUse, tableGroup, sqlAstCreationState ); } + public static SqmPathInterpretation from( + DiscriminatorSqmPath path, + SqmToSqlAstConverter converter) { + assert path.getEntityDescriptor().hasSubclasses(); + + final NavigablePath navigablePath = path.getNavigablePath(); + final TableGroup tableGroup = converter.getFromClauseAccess().getTableGroup( navigablePath.getParent() ); + final ModelPartContainer modelPart = tableGroup.getModelPart(); + final EntityMappingType entityMapping; + if ( modelPart instanceof EntityValuedModelPart ) { + entityMapping = ( (EntityValuedModelPart) modelPart ).getEntityMappingType(); + } + else { + entityMapping = (EntityMappingType) ( (PluralAttributeMapping) modelPart ).getElementDescriptor().getPartMappingType(); + } + + return new DiscriminatorPathInterpretation<>( navigablePath, entityMapping, tableGroup, converter ); + } + public EntityDiscriminatorMapping getDiscriminatorMapping() { return (EntityDiscriminatorMapping) super.getExpressionType(); } @@ -59,7 +83,7 @@ public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretati } @Override - public DomainResult> createDomainResult(String resultVariable, DomainResultCreationState creationState) { + public DomainResult createDomainResult(String resultVariable, DomainResultCreationState creationState) { return getDiscriminatorMapping().createDomainResult( getNavigablePath(), getTableGroup(), resultVariable, creationState ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SelfInterpretingSqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SelfInterpretingSqmPath.java deleted file mode 100644 index 972904e6c0..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SelfInterpretingSqmPath.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.sql.internal; - -import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.sql.ast.spi.SqlAstCreationState; - -/** - * Optional contract for sqm-paths which need special interpretation handling - * - * @author Steve Ebersole - */ -public interface SelfInterpretingSqmPath extends SqmPath { - /** - * Perform the interpretation - */ - SqmPathInterpretation interpret( - SqlAstCreationState sqlAstCreationState, - SemanticQueryWalker sqmWalker, - boolean jpaQueryComplianceEnabled); -}