HHH-17121 Nullability improvements to LoadQueryInfluencers

This commit is contained in:
Christian Beikov 2023-10-19 11:54:28 +02:00
parent 40a5c0059e
commit ffee08d853
5 changed files with 12 additions and 37 deletions

View File

@ -23,7 +23,6 @@ import org.hibernate.graph.GraphSemantic;
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.internal.FilterImpl;
import org.hibernate.internal.SessionCreationOptions;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.loader.ast.spi.CascadingFetchProfile;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
@ -44,17 +43,8 @@ import static org.hibernate.engine.FetchStyle.SUBSELECT;
* @author Steve Ebersole
*/
public class LoadQueryInfluencers implements Serializable {
/**
* Static reference useful for cases where we are creating load SQL
* outside the context of any influencers. One such example is
* anything created by the session factory.
*
* @deprecated use {@link #LoadQueryInfluencers(SessionFactoryImplementor)}
*/
@Deprecated(forRemoval = true)
public static final LoadQueryInfluencers NONE = new LoadQueryInfluencers();
private final @Nullable SessionFactoryImplementor sessionFactory;
private final SessionFactoryImplementor sessionFactory;
private CascadingFetchProfile enabledCascadingFetchProfile;
@ -72,10 +62,6 @@ public class LoadQueryInfluencers implements Serializable {
private Boolean readOnly;
public LoadQueryInfluencers() {
this.sessionFactory = null;
}
public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory) {
this.sessionFactory = sessionFactory;
batchSize = sessionFactory.getSessionFactoryOptions().getDefaultBatchFetchSize();
@ -99,7 +85,7 @@ public class LoadQueryInfluencers implements Serializable {
return effectiveEntityGraph;
}
public @Nullable SessionFactoryImplementor getSessionFactory() {
public SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}
@ -135,7 +121,6 @@ public class LoadQueryInfluencers implements Serializable {
* Set the effective {@linkplain #getEnabledCascadingFetchProfile() cascading fetch-profile}
*/
public void setEnabledCascadingFetchProfile(CascadingFetchProfile enabledCascadingFetchProfile) {
checkMutability();
this.enabledCascadingFetchProfile = enabledCascadingFetchProfile;
}
@ -199,8 +184,7 @@ public class LoadQueryInfluencers implements Serializable {
}
public Filter enableFilter(String filterName) {
checkMutability();
FilterImpl filter = new FilterImpl( NullnessUtil.castNonNull( sessionFactory ).getFilterDefinition( filterName ) );
FilterImpl filter = new FilterImpl( sessionFactory.getFilterDefinition( filterName ) );
if ( enabledFilters == null ) {
this.enabledFilters = new HashMap<>();
}
@ -250,7 +234,7 @@ public class LoadQueryInfluencers implements Serializable {
}
private void checkFetchProfileName(String name) {
if ( sessionFactory != null && !sessionFactory.containsFetchProfileDefinition( name ) ) {
if ( !sessionFactory.containsFetchProfileDefinition( name ) ) {
throw new UnknownProfileException( name );
}
}
@ -261,7 +245,6 @@ public class LoadQueryInfluencers implements Serializable {
}
public void enableFetchProfile(String name) throws UnknownProfileException {
checkMutability();
checkFetchProfileName( name );
if ( enabledFetchProfileNames == null ) {
this.enabledFetchProfileNames = new HashSet<>();
@ -368,14 +351,6 @@ public class LoadQueryInfluencers implements Serializable {
return false;
}
private void checkMutability() {
if ( sessionFactory == null ) {
// that's the signal that this is the immutable, context-less
// variety
throw new IllegalStateException( "Cannot modify context-less LoadQueryInfluencers" );
}
}
public boolean hasSubselectLoadableCollections(EntityPersister persister) {
return persister.hasSubselectLoadableCollections()
|| subselectFetchEnabled && persister.hasCollections()

View File

@ -58,13 +58,13 @@ public class LoadPlanBuilderTest {
final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(
LockOptions.READ,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory
);
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect()
.getJdbcValuesMappingProducer()
.resolve( null, LoadQueryInfluencers.NONE, sessionFactory )
.resolve( null, new LoadQueryInfluencers( sessionFactory ), sessionFactory )
.getDomainResults();
assertThat( domainResults ).hasSize( 1 );
@ -91,7 +91,7 @@ public class LoadPlanBuilderTest {
final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>( entityDescriptor, sessionFactory );
final LoadQueryInfluencers influencers = new LoadQueryInfluencers() {
final LoadQueryInfluencers influencers = new LoadQueryInfluencers( sessionFactory ) {
@Override
public CascadingFetchProfile getEnabledCascadingFetchProfile() {
return CascadingFetchProfile.MERGE;
@ -105,7 +105,7 @@ public class LoadPlanBuilderTest {
);
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect()
.getJdbcValuesMappingProducer()
.resolve( null, LoadQueryInfluencers.NONE, sessionFactory )
.resolve( null, new LoadQueryInfluencers( sessionFactory ), sessionFactory )
.getDomainResults();
assertThat( domainResults ).hasSize( 1 );
@ -135,7 +135,7 @@ public class LoadPlanBuilderTest {
final CollectionLoaderSingleKey loader = new CollectionLoaderSingleKey(
messages,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory
);

View File

@ -73,7 +73,7 @@ public class MappedFetchTests {
rootEntityDescriptor.getIdentifierMapping(),
null,
1,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
LockOptions.NONE,
jdbcParameter -> {
},

View File

@ -195,7 +195,7 @@ public class EntityJoinTest {
QueryOptions.NONE,
DomainParameterXref.empty(),
QueryParameterBindings.NO_PARAM_BINDINGS,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( factory ),
factory,
true
)

View File

@ -35,7 +35,7 @@ public class AbstractResultTests {
QueryOptions.NONE,
DomainParameterXref.from( sqm ),
parameterBindings,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory,
true
)