Skip to content

Commit

Permalink
HHH-17121 Nullability improvements to LoadQueryInfluencers
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Oct 23, 2023
1 parent 40a5c00 commit ffee08d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand All @@ -44,17 +43,8 @@
* @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;

Expand All @@ -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();
Expand All @@ -99,7 +85,7 @@ public EffectiveEntityGraph applyEntityGraph(@Nullable RootGraphImplementor<?> r
return effectiveEntityGraph;
}

public @Nullable SessionFactoryImplementor getSessionFactory() {
public SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}

Expand Down Expand Up @@ -135,7 +121,6 @@ public boolean hasEnabledCascadingFetchProfile() {
* Set the effective {@linkplain #getEnabledCascadingFetchProfile() cascading fetch-profile}
*/
public void setEnabledCascadingFetchProfile(CascadingFetchProfile enabledCascadingFetchProfile) {
checkMutability();
this.enabledCascadingFetchProfile = enabledCascadingFetchProfile;
}

Expand Down Expand Up @@ -199,8 +184,7 @@ public Set<String> getEnabledFilterNames() {
}

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<>();
}
Expand Down Expand Up @@ -250,7 +234,7 @@ public Set<String> getEnabledFetchProfileNames() {
}

private void checkFetchProfileName(String name) {
if ( sessionFactory != null && !sessionFactory.containsFetchProfileDefinition( name ) ) {
if ( !sessionFactory.containsFetchProfileDefinition( name ) ) {
throw new UnknownProfileException( name );
}
}
Expand All @@ -261,7 +245,6 @@ public boolean isFetchProfileEnabled(String name) throws UnknownProfileException
}

public void enableFetchProfile(String name) throws UnknownProfileException {
checkMutability();
checkFetchProfileName( name );
if ( enabledFetchProfileNames == null ) {
this.enabledFetchProfileNames = new HashSet<>();
Expand Down Expand Up @@ -368,14 +351,6 @@ private boolean isSubselectFetchEnabledInProfile(CollectionPersister persister)
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ public void testSimpleBuild(SessionFactoryScope scope) {

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 );
Expand All @@ -91,7 +91,7 @@ public void testCascadeBasedBuild(SessionFactoryScope scope) {

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;
Expand All @@ -105,7 +105,7 @@ public CascadingFetchProfile getEnabledCascadingFetchProfile() {
);
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect()
.getJdbcValuesMappingProducer()
.resolve( null, LoadQueryInfluencers.NONE, sessionFactory )
.resolve( null, new LoadQueryInfluencers( sessionFactory ), sessionFactory )
.getDomainResults();

assertThat( domainResults ).hasSize( 1 );
Expand Down Expand Up @@ -135,7 +135,7 @@ public void testCollectionInitializerCase(SessionFactoryScope scope) {

final CollectionLoaderSingleKey loader = new CollectionLoaderSingleKey(
messages,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void baseline(SessionFactoryScope scope) {
rootEntityDescriptor.getIdentifierMapping(),
null,
1,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
LockOptions.NONE,
jdbcParameter -> {
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public void testNoImpliedJoinGeneratedForEqualityComparison(SessionFactoryScope
QueryOptions.NONE,
DomainParameterXref.empty(),
QueryParameterBindings.NO_PARAM_BINDINGS,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( factory ),
factory,
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected SelectStatement interpret(String hql, QueryParameterBindings parameter
QueryOptions.NONE,
DomainParameterXref.from( sqm ),
parameterBindings,
LoadQueryInfluencers.NONE,
new LoadQueryInfluencers( sessionFactory ),
sessionFactory,
true
)
Expand Down

0 comments on commit ffee08d

Please sign in to comment.