revert back v5 implementation of fetch entity graph
This commit is contained in:
parent
11c5a1019f
commit
a91383a226
|
@ -30,8 +30,6 @@ import org.hibernate.event.spi.PostLoadEvent;
|
|||
import org.hibernate.event.spi.PostLoadEventListener;
|
||||
import org.hibernate.event.spi.PreLoadEvent;
|
||||
import org.hibernate.event.spi.PreLoadEventListener;
|
||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||
import org.hibernate.graph.spi.GraphImplementor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
|
@ -183,9 +181,6 @@ public final class TwoPhaseLoad {
|
|||
String entityName = persister.getEntityName();
|
||||
String[] propertyNames = persister.getPropertyNames();
|
||||
final Type[] types = persister.getPropertyTypes();
|
||||
|
||||
final GraphImplementor<?> fetchGraphContext = session.getFetchGraphLoadContext();
|
||||
|
||||
for ( int i = 0; i < hydratedState.length; i++ ) {
|
||||
final Object value = hydratedState[i];
|
||||
if ( debugEnabled ) {
|
||||
|
@ -232,10 +227,6 @@ public final class TwoPhaseLoad {
|
|||
LOG.debugf( "Skipping <unknown> attribute : `%s`", propertyNames[i] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( session.getFetchGraphLoadContext() != fetchGraphContext ) {
|
||||
session.setFetchGraphLoadContext( fetchGraphContext );
|
||||
}
|
||||
}
|
||||
|
||||
//Must occur after resolving identifiers!
|
||||
|
@ -373,51 +364,27 @@ public final class TwoPhaseLoad {
|
|||
}
|
||||
|
||||
/**
|
||||
* Check if eager of the association is overridden (i.e. skipping metamodel strategy), including (order sensitive):
|
||||
* <ol>
|
||||
* <li>fetch graph</li>
|
||||
* <li>fetch profile</li>
|
||||
* </ol>
|
||||
* Check if eager of the association is overriden by anything.
|
||||
*
|
||||
* @param session session
|
||||
* @param entityName entity name
|
||||
* @param associationName association name
|
||||
* @param associationType association type
|
||||
* @param isDebugEnabled if debug log level enabled
|
||||
*
|
||||
* @return null if there is no overriding, true if it is overridden to eager and false if it is overridden to lazy
|
||||
*/
|
||||
private static Boolean getOverridingEager(
|
||||
final SharedSessionContractImplementor session,
|
||||
final String entityName,
|
||||
final String associationName,
|
||||
final Type associationType,
|
||||
final Type type,
|
||||
final boolean isDebugEnabled) {
|
||||
// Performance: check type.isCollectionType() first, as type.isAssociationType() is megamorphic
|
||||
if ( associationType.isCollectionType() || associationType.isAssociationType() ) {
|
||||
if ( type.isCollectionType() || type.isAssociationType() ) {
|
||||
final Boolean overridingEager = isEagerFetchProfile( session, entityName, associationName );
|
||||
|
||||
// check 'fetch graph' first; skip 'fetch profile' if 'fetch graph' takes effect
|
||||
Boolean overridingEager = isEagerFetchGraph( session, associationName, associationType );
|
||||
|
||||
if ( overridingEager != null ) {
|
||||
//This method is very hot, and private so let's piggy back on the fact that the caller already knows the debugging state.
|
||||
if ( isDebugEnabled ) {
|
||||
LOG.debugf(
|
||||
"Overriding eager fetching using fetch graph. EntityName: %s, associationName: %s, eager fetching: %s",
|
||||
entityName,
|
||||
associationName,
|
||||
overridingEager
|
||||
);
|
||||
}
|
||||
|
||||
return overridingEager;
|
||||
}
|
||||
|
||||
// check 'fetch profile' next; skip 'metamodel' if 'fetch profile' takes effect
|
||||
overridingEager = isEagerFetchProfile( session, entityName, associationName );
|
||||
|
||||
if ( overridingEager != null ) {
|
||||
//This method is very hot, and private so let's piggy back on the fact that the caller already knows the debugging state.
|
||||
if ( isDebugEnabled ) {
|
||||
//This method is very hot, and private so let's piggy back on the fact that the caller already knows the debugging state.
|
||||
if ( isDebugEnabled ) {
|
||||
if ( overridingEager != null ) {
|
||||
LOG.debugf(
|
||||
"Overriding eager fetching using active fetch profile. EntityName: %s, associationName: %s, eager fetching: %s",
|
||||
entityName,
|
||||
|
@ -425,10 +392,10 @@ public final class TwoPhaseLoad {
|
|||
overridingEager
|
||||
);
|
||||
}
|
||||
return overridingEager;
|
||||
}
|
||||
|
||||
return overridingEager;
|
||||
}
|
||||
// let 'metamodel' decide eagerness
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -451,39 +418,6 @@ public final class TwoPhaseLoad {
|
|||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Boolean isEagerFetchGraph(SharedSessionContractImplementor session, String associationName, Type associationType) {
|
||||
final GraphImplementor<?> context = session.getFetchGraphLoadContext();
|
||||
|
||||
if ( context != null ) {
|
||||
// 'fetch graph' is in effect, so null should not be returned
|
||||
final AttributeNodeImplementor<Object> attributeNode = context.findAttributeNode( associationName );
|
||||
if ( attributeNode != null ) {
|
||||
if ( associationType.isCollectionType() ) {
|
||||
// to do: deal with Map's key and value
|
||||
session.setFetchGraphLoadContext( null );
|
||||
}
|
||||
else {
|
||||
// set 'fetchGraphContext' to sub-graph so graph is explored further (internal loading)
|
||||
final GraphImplementor<?> subContext = attributeNode.getSubGraphMap().get( associationType.getReturnedClass() );
|
||||
if ( subContext != null ) {
|
||||
session.setFetchGraphLoadContext( subContext );
|
||||
}
|
||||
else {
|
||||
session.setFetchGraphLoadContext( null );
|
||||
}
|
||||
}
|
||||
// explicit 'fetch graph' applies, so fetch eagerly
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
// implicit 'fetch graph' applies, so fetch lazily
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* PostLoad cannot occur during initializeEntity, as that call occurs *before*
|
||||
|
|
|
@ -458,31 +458,4 @@ public interface SharedSessionContractImplementor
|
|||
*/
|
||||
PersistenceContext getPersistenceContextInternal();
|
||||
|
||||
/**
|
||||
* Get the current fetch graph context (either {@link org.hibernate.graph.spi.RootGraphImplementor} or {@link org.hibernate.graph.spi.SubGraphImplementor}.
|
||||
* Suppose fetch graph is "a(b(c))", then during {@link org.hibernate.engine.internal.TwoPhaseLoad}:
|
||||
* <ul>
|
||||
* <li>when loading root</li>: {@link org.hibernate.graph.spi.RootGraphImplementor root} will be returned
|
||||
* <li>when internally loading 'a'</li>: {@link org.hibernate.graph.spi.SubGraphImplementor subgraph} of 'a' will be returned
|
||||
* <li>when internally loading 'b'</li>: {@link org.hibernate.graph.spi.SubGraphImplementor subgraph} of 'a(b)' will be returned
|
||||
* <li>when internally loading 'c'</li>: {@link org.hibernate.graph.spi.SubGraphImplementor subgraph} of 'a(b(c))' will be returned
|
||||
* </ul>
|
||||
*
|
||||
* @return current fetch graph context; can be null if fetch graph is not effective or the graph eager loading is done.
|
||||
* @see #setFetchGraphLoadContext(GraphImplementor)
|
||||
* @see org.hibernate.engine.internal.TwoPhaseLoad
|
||||
*/
|
||||
default GraphImplementor getFetchGraphLoadContext() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current fetch graph context (either {@link org.hibernate.graph.spi.RootGraphImplementor} or {@link org.hibernate.graph.spi.SubGraphImplementor}.
|
||||
*
|
||||
* @param fetchGraphLoadContext new fetch graph context; can be null (this field will be set to null after root entity loading is done).
|
||||
* @see #getFetchGraphLoadContext()
|
||||
*/
|
||||
default void setFetchGraphLoadContext(GraphImplementor fetchGraphLoadContext) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -185,8 +185,6 @@ public class SessionImpl
|
|||
private transient LoadEvent loadEvent; //cached LoadEvent instance
|
||||
|
||||
private transient TransactionObserver transactionObserver;
|
||||
|
||||
private transient GraphImplementor fetchGraphLoadContext;
|
||||
|
||||
public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
|
||||
super( factory, options );
|
||||
|
@ -2748,10 +2746,6 @@ public class SessionImpl
|
|||
lockOptions = buildLockOptions( lockModeType, properties );
|
||||
loadAccess.with( lockOptions );
|
||||
}
|
||||
|
||||
if ( getLoadQueryInfluencers().getEffectiveEntityGraph().getSemantic() == GraphSemantic.FETCH ) {
|
||||
setFetchGraphLoadContext( getLoadQueryInfluencers().getEffectiveEntityGraph().getGraph() );
|
||||
}
|
||||
|
||||
return loadAccess.load( primaryKey );
|
||||
}
|
||||
|
@ -2797,7 +2791,6 @@ public class SessionImpl
|
|||
finally {
|
||||
getLoadQueryInfluencers().getEffectiveEntityGraph().clear();
|
||||
getLoadQueryInfluencers().setReadOnly( null );
|
||||
setFetchGraphLoadContext( null );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3161,16 +3154,6 @@ public class SessionImpl
|
|||
checkOpen();
|
||||
return getEntityManagerFactory().findEntityGraphsByType( entityClass );
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphImplementor getFetchGraphLoadContext() {
|
||||
return this.fetchGraphLoadContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFetchGraphLoadContext(GraphImplementor fetchGraphLoadContext) {
|
||||
this.fetchGraphLoadContext = fetchGraphLoadContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by JDK serialization...
|
||||
|
|
|
@ -1372,9 +1372,6 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
sessionCacheMode = getSession().getCacheMode();
|
||||
getSession().setCacheMode( effectiveCacheMode );
|
||||
}
|
||||
if ( entityGraphQueryHint != null && entityGraphQueryHint.getSemantic() == GraphSemantic.FETCH ) {
|
||||
getSession().setFetchGraphLoadContext( entityGraphQueryHint.getGraph() );
|
||||
}
|
||||
}
|
||||
|
||||
protected void afterQuery() {
|
||||
|
@ -1386,7 +1383,6 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
|
|||
getSession().setCacheMode( sessionCacheMode );
|
||||
sessionCacheMode = null;
|
||||
}
|
||||
getSession().setFetchGraphLoadContext( null );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue