77import jakarta .persistence .EntityGraph ;
88import jakarta .persistence .PessimisticLockScope ;
99import jakarta .persistence .Timeout ;
10+ import org .hibernate .BatchSize ;
1011import org .hibernate .CacheMode ;
12+ import org .hibernate .FindBy ;
1113import org .hibernate .LockMode ;
1214import org .hibernate .LockOptions ;
1315import org .hibernate .MultiIdentifierLoadAccess ;
16+ import org .hibernate .NaturalIdSynchronization ;
1417import org .hibernate .OrderingMode ;
18+ import org .hibernate .ReadOnlyMode ;
1519import org .hibernate .RemovalsMode ;
1620import org .hibernate .SessionCheckMode ;
1721import org .hibernate .UnknownProfileException ;
1822import org .hibernate .engine .spi .SessionImplementor ;
1923import org .hibernate .engine .spi .SharedSessionContractImplementor ;
2024import org .hibernate .graph .GraphSemantic ;
2125import org .hibernate .graph .spi .RootGraphImplementor ;
26+ import org .hibernate .internal .find .FindMultipleByKeyOperation ;
2227import org .hibernate .loader .ast .spi .MultiIdLoadOptions ;
28+ import org .hibernate .loader .internal .LoadAccessContext ;
2329import org .hibernate .persister .entity .EntityPersister ;
2430
2531import java .util .HashSet ;
2632import java .util .List ;
2733import java .util .Set ;
28- import java .util .function .Supplier ;
2934
3035import static java .util .Collections .emptyList ;
3136
32- /**
33- * @author Steve Ebersole
34- */
37+ /// Implementation of MultiIdentifierLoadAccess.
38+ ///
39+ /// @author Steve Ebersole
40+ ///
41+ /// @deprecated Use [FindMultipleByKeyOperation] instead.
42+ @ Deprecated
3543class MultiIdentifierLoadAccessImpl <T > implements MultiIdentifierLoadAccess <T >, MultiIdLoadOptions {
3644 private final SharedSessionContractImplementor session ;
3745 private final EntityPersister entityPersister ;
@@ -43,7 +51,7 @@ class MultiIdentifierLoadAccessImpl<T> implements MultiIdentifierLoadAccess<T>,
4351 private RootGraphImplementor <T > rootGraph ;
4452 private GraphSemantic graphSemantic ;
4553
46- private Integer batchSize ;
54+ private BatchSize batchSize ;
4755 private SessionCheckMode sessionCheckMode = SessionCheckMode .DISABLED ;
4856 private RemovalsMode removalsMode = RemovalsMode .REPLACE ;
4957 protected OrderingMode orderingMode = OrderingMode .ORDERED ;
@@ -107,12 +115,12 @@ public MultiIdentifierLoadAccess<T> with(EntityGraph<T> graph, GraphSemantic sem
107115
108116 @ Override
109117 public Integer getBatchSize () {
110- return batchSize ;
118+ return batchSize . batchSize () ;
111119 }
112120
113121 @ Override
114122 public MultiIdentifierLoadAccess <T > withBatchSize (int batchSize ) {
115- this .batchSize = batchSize < 1 ? null : batchSize ;
123+ this .batchSize = batchSize < 1 ? null : new BatchSize ( batchSize ) ;
116124 return this ;
117125 }
118126
@@ -164,53 +172,33 @@ public Boolean getReadOnly(SessionImplementor session) {
164172 @ Override
165173 @ SuppressWarnings ( "unchecked" )
166174 public <K > List <T > multiLoad (K ... ids ) {
167- return perform ( () -> (List <T >) entityPersister .multiLoad ( ids , session , this ) );
168- }
169-
170- public List <T > perform (Supplier <List <T >> executor ) {
171- final var sessionCacheMode = session .getCacheMode ();
172- boolean cacheModeChanged = false ;
173- if ( cacheMode != null ) {
174- // naive check for now...
175- // todo : account for "conceptually equal"
176- if ( cacheMode != sessionCacheMode ) {
177- session .setCacheMode ( cacheMode );
178- cacheModeChanged = true ;
179- }
180- }
175+ return buildOperation ().performFind ( List .of ( ids ), graphSemantic , rootGraph , (LoadAccessContext ) session );
176+ }
181177
182- try {
183- final var influencers = session .getLoadQueryInfluencers ();
184- final var fetchProfiles =
185- influencers .adjustFetchProfiles ( disabledFetchProfiles , enabledFetchProfiles );
186- final var effectiveEntityGraph =
187- rootGraph == null
188- ? null
189- : influencers .applyEntityGraph ( rootGraph , graphSemantic );
190- try {
191- return executor .get ();
192- }
193- finally {
194- if ( effectiveEntityGraph != null ) {
195- effectiveEntityGraph .clear ();
196- }
197- influencers .setEnabledFetchProfileNames ( fetchProfiles );
198- }
199- }
200- finally {
201- if ( cacheModeChanged ) {
202- // change it back
203- session .setCacheMode ( sessionCacheMode );
204- }
205- }
178+ private FindMultipleByKeyOperation <T > buildOperation () {
179+ return new FindMultipleByKeyOperation <T >(
180+ entityPersister ,
181+ FindBy .ID ,
182+ batchSize ,
183+ sessionCheckMode ,
184+ removalsMode ,
185+ orderingMode ,
186+ cacheMode ,
187+ lockOptions ,
188+ readOnly == Boolean .TRUE ? ReadOnlyMode .READ_ONLY : ReadOnlyMode .READ_WRITE ,
189+ enabledFetchProfiles ,
190+ disabledFetchProfiles ,
191+ // irrelevant for load-by-id
192+ NaturalIdSynchronization .DISABLED
193+ );
206194 }
207195
208196 @ Override
209197 @ SuppressWarnings ( "unchecked" )
210198 public <K > List <T > multiLoad (List <K > ids ) {
211199 return ids .isEmpty ()
212200 ? emptyList ()
213- : perform ( () -> (List <T >) entityPersister . multiLoad ( ids . toArray (), session , this ) );
201+ : buildOperation (). performFind ( (List <Object >) ids , graphSemantic , rootGraph , ( LoadAccessContext ) session );
214202 }
215203
216204 @ Override
0 commit comments