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.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

View File

@ -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> {
T visitFkExpression(SqmFkExpression<?> fkExpression);
T visitSelfInterpretingSqmPath(SelfInterpretingSqmPath<?> sqmPath);
T visitDiscriminatorPath(DiscriminatorSqmPath sqmPath);
T visitIndexedPluralAccessPath(SqmIndexedCollectionAccessPath<?> path);
@ -310,9 +310,9 @@ public interface SemanticQueryWalker<T> {
T visitEntityTypeLiteralExpression(SqmLiteralEntityType<?> expression);
T visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression);
T visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath<?> expression);
T visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression);
T visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue<?> expression);
T visitParameterizedEntityTypeExpression(SqmParameterizedEntityType<?> expression);

View File

@ -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<Object> {
}
@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<Object> {
}
@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;
}

View File

@ -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<Obj
}
@Override
public Object visitSelfInterpretingSqmPath(SelfInterpretingSqmPath<?> path) {
public Object visitDiscriminatorPath(DiscriminatorSqmPath path) {
return path;
}
@ -607,12 +606,12 @@ public abstract class BaseSemanticQueryWalker implements SemanticQueryWalker<Obj
}
@Override
public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath expression) {
public Object visitAnyDiscriminatorTypeExpression(AnyDiscriminatorSqmPath<?> expression) {
return expression;
}
@Override
public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue expression) {
public Object visitAnyDiscriminatorTypeValueExpression(SqmAnyDiscriminatorValue<?> 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.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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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<T extends Statement> 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() ),

View File

@ -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<T> extends AbstractSqmPathInterpretation<T> {
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<Class<?>> createDomainResult(String resultVariable, DomainResultCreationState creationState) {
public DomainResult<T> createDomainResult(String resultVariable, DomainResultCreationState 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);
}