Skip to content

Commit ffee08d

Browse files
committed
HHH-17121 Nullability improvements to LoadQueryInfluencers
1 parent 40a5c00 commit ffee08d

File tree

5 files changed

+12
-37
lines changed

5 files changed

+12
-37
lines changed

hibernate-core/src/main/java/org/hibernate/engine/spi/LoadQueryInfluencers.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.hibernate.graph.spi.RootGraphImplementor;
2424
import org.hibernate.internal.FilterImpl;
2525
import org.hibernate.internal.SessionCreationOptions;
26-
import org.hibernate.internal.util.NullnessUtil;
2726
import org.hibernate.loader.ast.spi.CascadingFetchProfile;
2827
import org.hibernate.persister.collection.CollectionPersister;
2928
import org.hibernate.persister.entity.EntityPersister;
@@ -44,17 +43,8 @@
4443
* @author Steve Ebersole
4544
*/
4645
public class LoadQueryInfluencers implements Serializable {
47-
/**
48-
* Static reference useful for cases where we are creating load SQL
49-
* outside the context of any influencers. One such example is
50-
* anything created by the session factory.
51-
*
52-
* @deprecated use {@link #LoadQueryInfluencers(SessionFactoryImplementor)}
53-
*/
54-
@Deprecated(forRemoval = true)
55-
public static final LoadQueryInfluencers NONE = new LoadQueryInfluencers();
5646

57-
private final @Nullable SessionFactoryImplementor sessionFactory;
47+
private final SessionFactoryImplementor sessionFactory;
5848

5949
private CascadingFetchProfile enabledCascadingFetchProfile;
6050

@@ -72,10 +62,6 @@ public class LoadQueryInfluencers implements Serializable {
7262

7363
private Boolean readOnly;
7464

75-
public LoadQueryInfluencers() {
76-
this.sessionFactory = null;
77-
}
78-
7965
public LoadQueryInfluencers(SessionFactoryImplementor sessionFactory) {
8066
this.sessionFactory = sessionFactory;
8167
batchSize = sessionFactory.getSessionFactoryOptions().getDefaultBatchFetchSize();
@@ -99,7 +85,7 @@ public EffectiveEntityGraph applyEntityGraph(@Nullable RootGraphImplementor<?> r
9985
return effectiveEntityGraph;
10086
}
10187

102-
public @Nullable SessionFactoryImplementor getSessionFactory() {
88+
public SessionFactoryImplementor getSessionFactory() {
10389
return sessionFactory;
10490
}
10591

@@ -135,7 +121,6 @@ public boolean hasEnabledCascadingFetchProfile() {
135121
* Set the effective {@linkplain #getEnabledCascadingFetchProfile() cascading fetch-profile}
136122
*/
137123
public void setEnabledCascadingFetchProfile(CascadingFetchProfile enabledCascadingFetchProfile) {
138-
checkMutability();
139124
this.enabledCascadingFetchProfile = enabledCascadingFetchProfile;
140125
}
141126

@@ -199,8 +184,7 @@ public Set<String> getEnabledFilterNames() {
199184
}
200185

201186
public Filter enableFilter(String filterName) {
202-
checkMutability();
203-
FilterImpl filter = new FilterImpl( NullnessUtil.castNonNull( sessionFactory ).getFilterDefinition( filterName ) );
187+
FilterImpl filter = new FilterImpl( sessionFactory.getFilterDefinition( filterName ) );
204188
if ( enabledFilters == null ) {
205189
this.enabledFilters = new HashMap<>();
206190
}
@@ -250,7 +234,7 @@ public Set<String> getEnabledFetchProfileNames() {
250234
}
251235

252236
private void checkFetchProfileName(String name) {
253-
if ( sessionFactory != null && !sessionFactory.containsFetchProfileDefinition( name ) ) {
237+
if ( !sessionFactory.containsFetchProfileDefinition( name ) ) {
254238
throw new UnknownProfileException( name );
255239
}
256240
}
@@ -261,7 +245,6 @@ public boolean isFetchProfileEnabled(String name) throws UnknownProfileException
261245
}
262246

263247
public void enableFetchProfile(String name) throws UnknownProfileException {
264-
checkMutability();
265248
checkFetchProfileName( name );
266249
if ( enabledFetchProfileNames == null ) {
267250
this.enabledFetchProfileNames = new HashSet<>();
@@ -368,14 +351,6 @@ private boolean isSubselectFetchEnabledInProfile(CollectionPersister persister)
368351
return false;
369352
}
370353

371-
private void checkMutability() {
372-
if ( sessionFactory == null ) {
373-
// that's the signal that this is the immutable, context-less
374-
// variety
375-
throw new IllegalStateException( "Cannot modify context-less LoadQueryInfluencers" );
376-
}
377-
}
378-
379354
public boolean hasSubselectLoadableCollections(EntityPersister persister) {
380355
return persister.hasSubselectLoadableCollections()
381356
|| subselectFetchEnabled && persister.hasCollections()

hibernate-core/src/test/java/org/hibernate/orm/test/entitygraph/ast/LoadPlanBuilderTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public void testSimpleBuild(SessionFactoryScope scope) {
5858

5959
final SingleIdLoadPlan<?> loadPlan = loader.resolveLoadPlan(
6060
LockOptions.READ,
61-
LoadQueryInfluencers.NONE,
61+
new LoadQueryInfluencers( sessionFactory ),
6262
sessionFactory
6363
);
6464

6565
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect()
6666
.getJdbcValuesMappingProducer()
67-
.resolve( null, LoadQueryInfluencers.NONE, sessionFactory )
67+
.resolve( null, new LoadQueryInfluencers( sessionFactory ), sessionFactory )
6868
.getDomainResults();
6969

7070
assertThat( domainResults ).hasSize( 1 );
@@ -91,7 +91,7 @@ public void testCascadeBasedBuild(SessionFactoryScope scope) {
9191

9292
final SingleIdEntityLoaderStandardImpl<?> loader = new SingleIdEntityLoaderStandardImpl<>( entityDescriptor, sessionFactory );
9393

94-
final LoadQueryInfluencers influencers = new LoadQueryInfluencers() {
94+
final LoadQueryInfluencers influencers = new LoadQueryInfluencers( sessionFactory ) {
9595
@Override
9696
public CascadingFetchProfile getEnabledCascadingFetchProfile() {
9797
return CascadingFetchProfile.MERGE;
@@ -105,7 +105,7 @@ public CascadingFetchProfile getEnabledCascadingFetchProfile() {
105105
);
106106
final List<DomainResult<?>> domainResults = loadPlan.getJdbcSelect()
107107
.getJdbcValuesMappingProducer()
108-
.resolve( null, LoadQueryInfluencers.NONE, sessionFactory )
108+
.resolve( null, new LoadQueryInfluencers( sessionFactory ), sessionFactory )
109109
.getDomainResults();
110110

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

136136
final CollectionLoaderSingleKey loader = new CollectionLoaderSingleKey(
137137
messages,
138-
LoadQueryInfluencers.NONE,
138+
new LoadQueryInfluencers( sessionFactory ),
139139
sessionFactory
140140
);
141141

hibernate-core/src/test/java/org/hibernate/orm/test/loading/MappedFetchTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void baseline(SessionFactoryScope scope) {
7373
rootEntityDescriptor.getIdentifierMapping(),
7474
null,
7575
1,
76-
LoadQueryInfluencers.NONE,
76+
new LoadQueryInfluencers( sessionFactory ),
7777
LockOptions.NONE,
7878
jdbcParameter -> {
7979
},

hibernate-core/src/test/java/org/hibernate/orm/test/query/hql/EntityJoinTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public void testNoImpliedJoinGeneratedForEqualityComparison(SessionFactoryScope
195195
QueryOptions.NONE,
196196
DomainParameterXref.empty(),
197197
QueryParameterBindings.NO_PARAM_BINDINGS,
198-
LoadQueryInfluencers.NONE,
198+
new LoadQueryInfluencers( factory ),
199199
factory,
200200
true
201201
)

hibernate-core/src/test/java/org/hibernate/orm/test/sql/results/AbstractResultTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected SelectStatement interpret(String hql, QueryParameterBindings parameter
3535
QueryOptions.NONE,
3636
DomainParameterXref.from( sqm ),
3737
parameterBindings,
38-
LoadQueryInfluencers.NONE,
38+
new LoadQueryInfluencers( sessionFactory ),
3939
sessionFactory,
4040
true
4141
)

0 commit comments

Comments
 (0)