HHH-17193 Introduce `Fetch#asFetchParent()` to avoid instanceof checks
This commit is contained in:
parent
8b4ef7c66c
commit
cc99b8a67c
|
@ -536,6 +536,11 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
|
|||
getKeyValueFetch().createAssembler( parentAccess, creationState )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private static class AnyResultAssembler<T> implements DomainResultAssembler<T> {
|
||||
|
|
|
@ -37,6 +37,14 @@ public interface Fetch extends DomainResultGraphNode {
|
|||
*/
|
||||
FetchParent getFetchParent();
|
||||
|
||||
/**
|
||||
* Utility method to avoid {@code instanceof} checks. Returns this if it's
|
||||
* an instance of {@link FetchParent}, null otherwise.
|
||||
*/
|
||||
default FetchParent asFetchParent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The value mapping being fetched
|
||||
*/
|
||||
|
|
|
@ -72,7 +72,7 @@ public interface FetchList extends Iterable<Fetch> {
|
|||
if ( fetch instanceof EagerCollectionFetch ) {
|
||||
return true;
|
||||
}
|
||||
else if ( fetch instanceof FetchParent && ( (FetchParent) fetch ).containsCollectionFetches() ) {
|
||||
else if ( fetch.asFetchParent() != null && fetch.asFetchParent().containsCollectionFetches() ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,4 +220,9 @@ public class EagerCollectionFetch extends CollectionFetch implements FetchParent
|
|||
public JavaType<?> getResultJavaType() {
|
||||
return getFetchedMapping().getJavaType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -170,4 +170,9 @@ public class AggregateEmbeddableFetchImpl extends AbstractFetchParent implements
|
|||
|
||||
return new EmbeddableAssembler( initializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -168,4 +168,8 @@ public class EmbeddableFetchImpl extends AbstractFetchParent implements Embeddab
|
|||
return getFetchParent().appliesTo( graphImplementor, metamodel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,13 +43,13 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
|
|||
final TableGroup entityTableGroup = creationState.getSqlAstCreationState().getFromClauseAccess()
|
||||
.getTableGroup( navigablePath );
|
||||
final EntityResultGraphNode entityResultGraphNode = (EntityResultGraphNode) fetchParent;
|
||||
final Fetch fetch = creationState.visitIdentifierFetch( entityResultGraphNode );
|
||||
final Fetch idFetch = creationState.visitIdentifierFetch( entityResultGraphNode );
|
||||
if ( navigablePath.getParent() == null && !creationState.forceIdentifierSelection() &&
|
||||
( !( fetch instanceof FetchParent ) || !( (FetchParent) fetch ).containsCollectionFetches() ) ) {
|
||||
( idFetch.asFetchParent() == null || !idFetch.asFetchParent().containsCollectionFetches() ) ) {
|
||||
identifierFetch = null;
|
||||
}
|
||||
else {
|
||||
identifierFetch = fetch;
|
||||
identifierFetch = idFetch;
|
||||
}
|
||||
|
||||
discriminatorFetch = creationState.visitDiscriminatorFetch( entityResultGraphNode );
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.sql.results.graph.entity;
|
||||
|
||||
import org.hibernate.sql.results.graph.Fetch;
|
||||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
|
||||
/**
|
||||
* Specialization of Fetch for entity-valued fetches
|
||||
|
@ -19,4 +20,8 @@ public interface EntityFetch extends EntityResultGraphNode, Fetch {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
default FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue