HHH-17126 Improve type narrowing in signatures of AbstractFetchParent

This commit is contained in:
Sanne Grinovero 2023-08-22 15:56:33 +02:00 committed by Sanne Grinovero
parent 4c549c46db
commit f58b7e4d29
9 changed files with 51 additions and 26 deletions

View File

@ -15,15 +15,13 @@ import org.hibernate.type.descriptor.java.JavaType;
* @author Steve Ebersole
*/
public abstract class AbstractFetchParent implements FetchParent {
private final FetchableContainer fetchContainer;
private final NavigablePath navigablePath;
private ImmutableFetchList fetches = ImmutableFetchList.EMPTY;
private boolean hasJoinFetches;
private boolean containsCollectionFetches;
public AbstractFetchParent(FetchableContainer fetchContainer, NavigablePath navigablePath) {
this.fetchContainer = fetchContainer;
public AbstractFetchParent(NavigablePath navigablePath) {
this.navigablePath = navigablePath;
}
@ -38,9 +36,7 @@ public abstract class AbstractFetchParent implements FetchParent {
this.containsCollectionFetches = newFetches.containsCollectionFetches();
}
public FetchableContainer getFetchContainer() {
return fetchContainer;
}
public abstract FetchableContainer getFetchContainer();
@Override
public NavigablePath getNavigablePath() {
@ -49,12 +45,12 @@ public abstract class AbstractFetchParent implements FetchParent {
@Override
public JavaType<?> getResultJavaType() {
return fetchContainer.getJavaType();
return getFetchContainer().getJavaType();
}
@Override
public FetchableContainer getReferencedMappingContainer() {
return fetchContainer;
return getFetchContainer();
}
@Override

View File

@ -46,6 +46,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements
private final TableGroup tableGroup;
private final boolean hasTableGroup;
private final SqlSelection aggregateSelection;
private final EmbeddableMappingType fetchContainer;
public AggregateEmbeddableFetchImpl(
NavigablePath navigablePath,
@ -54,7 +55,8 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements
FetchTiming fetchTiming,
boolean hasTableGroup,
DomainResultCreationState creationState) {
super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath );
super( navigablePath );
this.fetchContainer = embeddedPartDescriptor.getEmbeddableTypeDescriptor();
this.fetchParent = fetchParent;
this.fetchTiming = fetchTiming;
@ -84,7 +86,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements
final SqlExpressionResolver sqlExpressionResolver = sqlAstCreationState.getSqlExpressionResolver();
final TableReference tableReference = tableGroup.getPrimaryTableReference();
final SelectableMapping selectableMapping = embeddedPartDescriptor.getEmbeddableTypeDescriptor().getAggregateMapping();
final SelectableMapping selectableMapping = fetchContainer.getAggregateMapping();
final Expression expression = sqlExpressionResolver.resolveSqlExpression( tableReference, selectableMapping );
final TypeConfiguration typeConfiguration = sqlAstCreationState.getCreationContext()
.getSessionFactory()
@ -115,7 +117,7 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements
@Override
public EmbeddableMappingType getFetchContainer() {
return (EmbeddableMappingType) super.getFetchContainer();
return fetchContainer;
}
@Override

View File

@ -48,13 +48,15 @@ public class AggregateEmbeddableResultImpl<T> extends AbstractFetchParent implem
private final boolean containsAnyNonScalars;
private final NavigablePath initializerNavigablePath;
private final SqlSelection aggregateSelection;
private final EmbeddableMappingType fetchContainer;
public AggregateEmbeddableResultImpl(
NavigablePath navigablePath,
EmbeddableValuedModelPart embeddedPartDescriptor,
String resultVariable,
DomainResultCreationState creationState) {
super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath );
super( navigablePath );
this.fetchContainer = embeddedPartDescriptor.getEmbeddableTypeDescriptor();
this.resultVariable = resultVariable;
/*
An `{embeddable_result}` sub-path is created for the corresponding initializer to differentiate it from a fetch-initializer if this embedded is also fetched.
@ -127,7 +129,7 @@ public class AggregateEmbeddableResultImpl<T> extends AbstractFetchParent implem
@Override
public EmbeddableMappingType getFetchContainer() {
return (EmbeddableMappingType) super.getFetchContainer();
return this.fetchContainer;
}
@Override

View File

@ -36,6 +36,7 @@ import org.hibernate.type.spi.TypeConfiguration;
public class EmbeddableExpressionResultImpl<T> extends AbstractFetchParent implements EmbeddableResultGraphNode, DomainResult<T>, EmbeddableResult<T> {
private final String resultVariable;
private final boolean containsAnyNonScalars;
private final EmbeddableMappingType fetchContainer;
public EmbeddableExpressionResultImpl(
NavigablePath navigablePath,
@ -43,7 +44,8 @@ public class EmbeddableExpressionResultImpl<T> extends AbstractFetchParent imple
SqlTuple sqlExpression,
String resultVariable,
DomainResultCreationState creationState) {
super( modelPart.getEmbeddableTypeDescriptor(), navigablePath );
super( navigablePath );
this.fetchContainer = modelPart.getEmbeddableTypeDescriptor();
this.resultVariable = resultVariable;
final ImmutableFetchList.Builder fetches = new ImmutableFetchList.Builder( modelPart );
@ -100,7 +102,7 @@ public class EmbeddableExpressionResultImpl<T> extends AbstractFetchParent imple
@Override
public EmbeddableMappingType getFetchContainer() {
return (EmbeddableMappingType) super.getFetchContainer();
return this.fetchContainer;
}
@Override

View File

@ -37,6 +37,7 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
private final FetchTiming fetchTiming;
private final TableGroup tableGroup;
private final boolean hasTableGroup;
private final EmbeddableMappingType fetchContainer;
public EmbeddableFetchImpl(
NavigablePath navigablePath,
@ -45,7 +46,8 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
FetchTiming fetchTiming,
boolean hasTableGroup,
DomainResultCreationState creationState) {
super( embeddedPartDescriptor.getEmbeddableTypeDescriptor(), navigablePath );
super( navigablePath );
this.fetchContainer = embeddedPartDescriptor.getEmbeddableTypeDescriptor();
this.fetchParent = fetchParent;
this.fetchTiming = fetchTiming;
@ -79,7 +81,8 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
* For Hibernate Reactive
*/
protected EmbeddableFetchImpl(EmbeddableFetchImpl original) {
super( original.getFetchContainer(), original.getNavigablePath() );
super( original.getNavigablePath() );
this.fetchContainer = original.getFetchContainer();
fetchParent = original.fetchParent;
fetchTiming = original.fetchTiming;
tableGroup = original.tableGroup;
@ -103,7 +106,7 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
@Override
public EmbeddableMappingType getFetchContainer() {
return (EmbeddableMappingType) super.getFetchContainer();
return this.fetchContainer;
}
@Override

View File

@ -34,6 +34,7 @@ public class EmbeddableForeignKeyResultImpl<T>
private final String resultVariable;
private final FetchParent fetchParent;
private final EmbeddableMappingType fetchContainer;
public EmbeddableForeignKeyResultImpl(
NavigablePath navigablePath,
@ -41,7 +42,8 @@ public class EmbeddableForeignKeyResultImpl<T>
String resultVariable,
FetchParent fetchParent,
DomainResultCreationState creationState) {
super( embeddableValuedModelPart.getEmbeddableTypeDescriptor(), navigablePath );
super( navigablePath );
this.fetchContainer = embeddableValuedModelPart.getEmbeddableTypeDescriptor();
this.resultVariable = resultVariable;
this.fetchParent = fetchParent;
resetFetches( creationState.visitFetches( this ) );
@ -117,7 +119,7 @@ public class EmbeddableForeignKeyResultImpl<T>
@Override
public EmbeddableMappingType getFetchContainer() {
return (EmbeddableMappingType) super.getFetchContainer();
return fetchContainer;
}
@Override

View File

@ -33,13 +33,15 @@ public class EmbeddableResultImpl<T> extends AbstractFetchParent implements Embe
private final String resultVariable;
private final boolean containsAnyNonScalars;
private final NavigablePath initializerNavigablePath;
private final EmbeddableMappingType fetchContainer;
public EmbeddableResultImpl(
NavigablePath navigablePath,
EmbeddableValuedModelPart modelPart,
String resultVariable,
DomainResultCreationState creationState) {
super( modelPart.getEmbeddableTypeDescriptor(), navigablePath );
super( navigablePath );
this.fetchContainer = modelPart.getEmbeddableTypeDescriptor();
this.resultVariable = resultVariable;
/*
An `{embeddable_result}` sub-path is created for the corresponding initializer to differentiate it from a fetch-initializer if this embedded is also fetched.
@ -98,7 +100,7 @@ public class EmbeddableResultImpl<T> extends AbstractFetchParent implements Embe
@Override
public EmbeddableMappingType getFetchContainer() {
return (EmbeddableMappingType) super.getFetchContainer();
return this.fetchContainer;
}
@Override

View File

@ -17,6 +17,7 @@ import org.hibernate.sql.results.graph.DomainResult;
import org.hibernate.sql.results.graph.DomainResultCreationState;
import org.hibernate.sql.results.graph.Fetch;
import org.hibernate.sql.results.graph.FetchParent;
import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.basic.BasicFetch;
import org.hibernate.type.descriptor.java.JavaType;
@ -29,9 +30,11 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
private Fetch identifierFetch;
private BasicFetch<?> discriminatorFetch;
private DomainResult<Object> rowIdResult;
private final EntityValuedModelPart fetchContainer;
public AbstractEntityResultGraphNode(EntityValuedModelPart referencedModelPart, NavigablePath navigablePath) {
super( referencedModelPart, navigablePath );
super( navigablePath );
this.fetchContainer = referencedModelPart;
}
@Override
@ -72,7 +75,12 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
@Override
public EntityValuedModelPart getEntityValuedModelPart() {
return (EntityValuedModelPart) getFetchContainer();
return this.fetchContainer;
}
@Override
public FetchableContainer getFetchContainer() {
return this.fetchContainer;
}
@Override

View File

@ -13,6 +13,7 @@ import org.hibernate.sql.results.graph.AssemblerCreationState;
import org.hibernate.sql.results.graph.DomainResultAssembler;
import org.hibernate.sql.results.graph.FetchParent;
import org.hibernate.sql.results.graph.FetchParentAccess;
import org.hibernate.sql.results.graph.FetchableContainer;
import org.hibernate.sql.results.graph.entity.internal.EntityAssembler;
/**
@ -22,18 +23,25 @@ import org.hibernate.sql.results.graph.entity.internal.EntityAssembler;
*/
public abstract class AbstractNonLazyEntityFetch extends AbstractFetchParent implements EntityFetch {
private final FetchParent fetchParent;
private final EntityValuedFetchable fetchContainer;
public AbstractNonLazyEntityFetch(
FetchParent fetchParent,
EntityValuedFetchable fetchedPart,
NavigablePath navigablePath) {
super( fetchedPart, navigablePath );
super( navigablePath );
this.fetchContainer = fetchedPart;
this.fetchParent = fetchParent;
}
@Override
public EntityValuedFetchable getEntityValuedModelPart() {
return (EntityValuedFetchable) getFetchContainer();
return fetchContainer;
}
@Override
public FetchableContainer getFetchContainer() {
return fetchContainer;
}
@Override