mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-21 10:34:51 +00:00
HHH-17193 Introduce Fetch#asFetchParent()
to avoid instanceof checks
This commit is contained in:
parent
bc0afec791
commit
7dd824a87e
@ -536,6 +536,11 @@ public DomainResultAssembler<?> createAssembler(
|
||||
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 @@ default boolean containsCollectionFetches() {
|
||||
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 boolean containsCollectionFetches() {
|
||||
public JavaType<?> getResultJavaType() {
|
||||
return getFetchedMapping().getJavaType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -170,4 +170,9 @@ public DomainResultAssembler createAssembler(
|
||||
|
||||
return new EmbeddableAssembler( initializer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -168,4 +168,8 @@ public boolean appliesTo(GraphImplementor<?> graphImplementor, JpaMetamodel meta
|
||||
return getFetchParent().appliesTo( graphImplementor, metamodel );
|
||||
}
|
||||
|
||||
@Override
|
||||
public FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
@ -43,13 +43,13 @@ public void afterInitialize(FetchParent fetchParent, DomainResultCreationState c
|
||||
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 @@ default boolean containsAnyNonScalarResults() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
default FetchParent asFetchParent() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user