Remove SelfInterpretingSqmPath and remove some warnings

This commit is contained in:
Christian Beikov 2023-03-17 12:10:41 +01:00
parent cf5eafdd13
commit 272df3ebe2
7 changed files with 57 additions and 82 deletions

View File

@ -8,26 +8,18 @@ package org.hibernate.metamodel.model.domain.internal;
import org.hibernate.metamodel.UnsupportedMappingException; import org.hibernate.metamodel.UnsupportedMappingException;
import org.hibernate.metamodel.mapping.EntityMappingType; 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.metamodel.model.domain.EntityDomainType;
import org.hibernate.spi.NavigablePath;
import org.hibernate.query.PathException; import org.hibernate.query.PathException;
import org.hibernate.query.hql.spi.SqmCreationState; import org.hibernate.query.hql.spi.SqmCreationState;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmPathSource; 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.SqmCopyContext;
import org.hibernate.query.sqm.tree.domain.AbstractSqmPath; import org.hibernate.query.sqm.tree.domain.AbstractSqmPath;
import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath;
import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType; import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType;
import org.hibernate.sql.ast.spi.SqlAstCreationState; import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.tree.from.TableGroup;
/** /**
* SqmPath specialization for an entity discriminator * SqmPath specialization for an entity discriminator
@ -35,7 +27,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({ "rawtypes", "unchecked" }) @SuppressWarnings({ "rawtypes", "unchecked" })
public class DiscriminatorSqmPath extends AbstractSqmPath implements SelfInterpretingSqmPath { public class DiscriminatorSqmPath extends AbstractSqmPath {
private final EntityDomainType entityDomainType; private final EntityDomainType entityDomainType;
private final EntityMappingType entityDescriptor; private final EntityMappingType entityDescriptor;
@ -51,6 +43,14 @@ public class DiscriminatorSqmPath extends AbstractSqmPath implements SelfInterpr
this.entityDescriptor = entityDescriptor; this.entityDescriptor = entityDescriptor;
} }
public EntityDomainType getEntityDomainType() {
return entityDomainType;
}
public EntityMappingType getEntityDescriptor() {
return entityDescriptor;
}
@Override @Override
public DiscriminatorSqmPath copy(SqmCopyContext context) { public DiscriminatorSqmPath copy(SqmCopyContext context) {
final DiscriminatorSqmPath existing = context.getCopy( this ); 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.visitEntityTypeLiteralExpression( new SqmLiteralEntityType( entityDomainType, nodeBuilder() ) );
} }
return walker.visitSelfInterpretingSqmPath( this ); return walker.visitDiscriminatorPath( 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 );
} }
@Override @Override

View File

@ -9,7 +9,7 @@ package org.hibernate.query.sqm;
import java.util.List; import java.util.List;
import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; 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.SqmCteContainer;
import org.hibernate.query.sqm.tree.cte.SqmCteStatement; import org.hibernate.query.sqm.tree.cte.SqmCteStatement;
import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement;
@ -232,7 +232,7 @@ public interface SemanticQueryWalker<T> {
T visitFkExpression(SqmFkExpression<?> fkExpression); T visitFkExpression(SqmFkExpression<?> fkExpression);
T visitSelfInterpretingSqmPath(SelfInterpretingSqmPath<?> sqmPath); T visitDiscriminatorPath(DiscriminatorSqmPath sqmPath);
T visitIndexedPluralAccessPath(SqmIndexedCollectionAccessPath<?> path); T visitIndexedPluralAccessPath(SqmIndexedCollectionAccessPath<?> path);
@ -310,9 +310,9 @@ public interface SemanticQueryWalker<T> {
T visitEntityTypeLiteralExpression(SqmLiteralEntityType<?> expression); T visitEntityTypeLiteralExpression(SqmLiteralEntityType<?> expression);
T visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression); T visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath<?> expression);
T visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression); T visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue<?> expression);
T visitParameterizedEntityTypeExpression(SqmParameterizedEntityType<?> expression); T visitParameterizedEntityTypeExpression(SqmParameterizedEntityType<?> expression);

View File

@ -10,9 +10,9 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; 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.QueryLogging;
import org.hibernate.query.sqm.SemanticQueryWalker; 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.SqmStatement;
import org.hibernate.query.sqm.tree.cte.SqmCteContainer; import org.hibernate.query.sqm.tree.cte.SqmCteContainer;
import org.hibernate.query.sqm.tree.cte.SqmCteStatement; import org.hibernate.query.sqm.tree.cte.SqmCteStatement;
@ -689,8 +689,8 @@ public class SqmTreePrinter implements SemanticQueryWalker<Object> {
} }
@Override @Override
public Object visitSelfInterpretingSqmPath(SelfInterpretingSqmPath<?> sqmPath) { public Object visitDiscriminatorPath(DiscriminatorSqmPath sqmPath) {
logWithIndentation( "-> [self-interpreting-path] - `%s`", sqmPath.getNavigablePath() ); logWithIndentation( "-> [discriminator-path] - `%s`", sqmPath.getNavigablePath() );
return null; return null;
} }
@ -1087,12 +1087,12 @@ public class SqmTreePrinter implements SemanticQueryWalker<Object> {
} }
@Override @Override
public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression) { public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath<?> expression) {
return null; return null;
} }
@Override @Override
public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue<?> expression) {
return null; return null;
} }

View File

@ -9,9 +9,8 @@ package org.hibernate.query.sqm.spi;
import java.util.List; import java.util.List;
import org.hibernate.metamodel.model.domain.internal.AnyDiscriminatorSqmPath; 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.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.SqmVisitableNode;
import org.hibernate.query.sqm.tree.cte.SqmCteContainer; import org.hibernate.query.sqm.tree.cte.SqmCteContainer;
import org.hibernate.query.sqm.tree.cte.SqmCteStatement; import org.hibernate.query.sqm.tree.cte.SqmCteStatement;
@ -365,7 +364,7 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker<Obj
} }
@Override @Override
public Object visitSelfInterpretingSqmPath(SelfInterpretingSqmPath<?> path) { public Object visitDiscriminatorPath(DiscriminatorSqmPath path) {
return path; return path;
} }
@ -607,12 +606,12 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker<Obj
} }
@Override @Override
public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression) { public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath<?> expression) {
return expression; return expression;
} }
@Override @Override
public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue<?> expression) {
return expression; return expression;
} }

View File

@ -89,6 +89,7 @@ import org.hibernate.metamodel.mapping.internal.OneToManyCollectionPart;
import org.hibernate.metamodel.mapping.internal.SqlTypedMappingImpl; import org.hibernate.metamodel.mapping.internal.SqlTypedMappingImpl;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping; import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.metamodel.mapping.ordering.OrderByFragment; 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.sql.results.graph.collection.internal.EagerCollectionFetch;
import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter; import org.hibernate.type.descriptor.converter.internal.OrdinalEnumValueConverter;
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; 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.EntityValuedPathInterpretation;
import org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation; import org.hibernate.query.sqm.sql.internal.NonAggregatedCompositeValuedPathInterpretation;
import org.hibernate.query.sqm.sql.internal.PluralValuedSimplePathInterpretation; 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.SqlAstProcessingStateImpl;
import org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl; import org.hibernate.query.sqm.sql.internal.SqlAstQueryPartProcessingStateImpl;
import org.hibernate.query.sqm.sql.internal.SqmMapEntryResult; import org.hibernate.query.sqm.sql.internal.SqmMapEntryResult;
@ -4092,7 +4092,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
} }
@Override @Override
public Expression visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath sqmPath) { public Expression visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath<?> sqmPath) {
return withTreatRestriction( return withTreatRestriction(
prepareReusablePath( prepareReusablePath(
sqmPath, sqmPath,
@ -4150,14 +4150,12 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
} }
@Override @Override
public Object visitSelfInterpretingSqmPath(SelfInterpretingSqmPath<?> sqmPath) { public Object visitDiscriminatorPath(DiscriminatorSqmPath sqmPath) {
return prepareReusablePath( return prepareReusablePath(
sqmPath, sqmPath,
() -> { () -> {
if ( sqmPath instanceof DiscriminatorSqmPath ) { registerTypeUsage( sqmPath );
registerTypeUsage( (DiscriminatorSqmPath) sqmPath ); return DiscriminatorPathInterpretation.from( sqmPath, this );
}
return sqmPath.interpret( this, this, jpaQueryComplianceEnabled );
} }
); );
} }
@ -4845,7 +4843,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
// as that would register a type usage for the table group that we don't want here // as that would register a type usage for the table group that we don't want here
final DiscriminatorSqmPath discriminatorSqmPath = (DiscriminatorSqmPath) lhs.type(); final DiscriminatorSqmPath discriminatorSqmPath = (DiscriminatorSqmPath) lhs.type();
registerTypeUsage( discriminatorSqmPath ); registerTypeUsage( discriminatorSqmPath );
final Expression typeExpression = discriminatorSqmPath.interpret( this, this, jpaQueryComplianceEnabled ); final Expression typeExpression = DiscriminatorPathInterpretation.from( discriminatorSqmPath, this );
if ( subclassEntityNames.size() == 1 ) { if ( subclassEntityNames.size() == 1 ) {
return new ComparisonPredicate( return new ComparisonPredicate(
typeExpression, typeExpression,
@ -6470,7 +6468,7 @@ public abstract class BaseSqmToSqlAstConverter<T extends Statement> extends Base
@Override @Override
public Expression visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) { public Expression visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue<?> expression) {
final BasicType<?> domainType = expression.getDomainType(); final BasicType<?> domainType = expression.getDomainType();
return new QueryLiteral<>( return new QueryLiteral<>(
domainType.convertToRelationalValue( expression.getEntityValue().getJavaType() ), domainType.convertToRelationalValue( expression.getEntityValue().getJavaType() ),

View File

@ -8,7 +8,12 @@ package org.hibernate.query.sqm.sql.internal;
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping; import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.metamodel.mapping.JdbcMapping; 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.spi.NavigablePath;
import org.hibernate.query.results.ResultSetMappingSqlSelection; import org.hibernate.query.results.ResultSetMappingSqlSelection;
import org.hibernate.sql.ast.SqlAstWalker; import org.hibernate.sql.ast.SqlAstWalker;
@ -26,7 +31,7 @@ import org.hibernate.type.spi.TypeConfiguration;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretation implements DomainResultProducer { public class DiscriminatorPathInterpretation<T> extends AbstractSqmPathInterpretation<T> {
private final Expression expression; private final Expression expression;
public DiscriminatorPathInterpretation( public DiscriminatorPathInterpretation(
@ -40,6 +45,25 @@ public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretati
expression = getDiscriminatorMapping().resolveSqlExpression( navigablePath, jdbcMappingToUse, tableGroup, sqlAstCreationState ); 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() { public EntityDiscriminatorMapping getDiscriminatorMapping() {
return (EntityDiscriminatorMapping) super.getExpressionType(); return (EntityDiscriminatorMapping) super.getExpressionType();
} }
@ -59,7 +83,7 @@ public class DiscriminatorPathInterpretation extends AbstractSqmPathInterpretati
} }
@Override @Override
public DomainResult<Class<?>> createDomainResult(String resultVariable, DomainResultCreationState creationState) { public DomainResult<T> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
return getDiscriminatorMapping().createDomainResult( getNavigablePath(), getTableGroup(), resultVariable, creationState ); return getDiscriminatorMapping().createDomainResult( getNavigablePath(), getTableGroup(), resultVariable, creationState );
} }

View File

@ -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<T> extends SqmPath<T> {
/**
* Perform the interpretation
*/
SqmPathInterpretation<T> interpret(
SqlAstCreationState sqlAstCreationState,
SemanticQueryWalker<?> sqmWalker,
boolean jpaQueryComplianceEnabled);
}