@@ -42,9 +42,10 @@ public void onInitializeCollection(InitializeCollectionEvent event) throws Hiber
4242 * called by a collection that wants to initialize itself
4343 */
4444 public CompletionStage <Void > onReactiveInitializeCollection (InitializeCollectionEvent event ) throws HibernateException {
45- PersistentCollection collection = event .getCollection ();
46- SessionImplementor source = event .getSession ();
47- CollectionEntry ce = source .getPersistenceContextInternal ().getCollectionEntry ( collection );
45+ final PersistentCollection <?> collection = event .getCollection ();
46+ final SessionImplementor source = event .getSession ();
47+
48+ final CollectionEntry ce = source .getPersistenceContextInternal ().getCollectionEntry ( collection );
4849 if ( ce == null ) {
4950 throw LOG .collectionWasEvicted ();
5051 }
@@ -55,50 +56,55 @@ public CompletionStage<Void> onReactiveInitializeCollection(InitializeCollection
5556 }
5657
5758 final CollectionPersister loadedPersister = ce .getLoadedPersister ();
59+ final Object loadedKey = ce .getLoadedKey ();
5860 if ( LOG .isTraceEnabled () ) {
59- LOG .tracev ( "Initializing collection {0}" , collectionInfoString ( loadedPersister , collection , ce .getLoadedKey (), source ) );
61+ LOG .tracev (
62+ "Initializing collection {0}" ,
63+ collectionInfoString ( loadedPersister , collection , loadedKey , source )
64+ );
6065 LOG .trace ( "Checking second-level cache" );
6166 }
6267
63- final boolean foundInCache = initializeCollectionFromCache ( ce . getLoadedKey () , loadedPersister , collection , source );
68+ final boolean foundInCache = initializeCollectionFromCache ( loadedKey , loadedPersister , collection , source );
6469 if ( foundInCache ) {
6570 if ( LOG .isTraceEnabled () ) {
6671 LOG .trace ( "Collection initialized from cache" );
6772 }
6873 return voidFuture ();
6974 }
70-
71- if ( LOG .isTraceEnabled () ) {
72- LOG .trace ( "Collection not cached" );
75+ else {
76+ if ( LOG .isTraceEnabled () ) {
77+ LOG .trace ( "Collection not cached" );
78+ }
79+ return ( (ReactiveCollectionPersister ) loadedPersister )
80+ .reactiveInitialize ( loadedKey , source )
81+ .thenApply ( list -> {
82+ handlePotentiallyEmptyCollection ( collection , source , ce , loadedPersister );
83+ return list ;
84+ } )
85+ .thenAccept ( list -> {
86+ if ( LOG .isTraceEnabled () ) {
87+ LOG .trace ( "Collection initialized" );
88+ }
89+
90+ final StatisticsImplementor statistics = source .getFactory ().getStatistics ();
91+ if ( statistics .isStatisticsEnabled () ) {
92+ statistics .fetchCollection ( loadedPersister .getRole () );
93+ }
94+ } );
7395 }
74- return ( (ReactiveCollectionPersister ) loadedPersister )
75- .reactiveInitialize ( ce .getLoadedKey (), source )
76- .thenApply ( list -> {
77- handlePotentiallyEmptyCollection ( collection , source , ce , ce .getLoadedPersister () );
78- return list ;
79- } )
80- .thenAccept ( list -> {
81- if ( LOG .isTraceEnabled () ) {
82- LOG .trace ( "Collection initialized" );
83- }
84-
85- final StatisticsImplementor statistics = source .getFactory ().getStatistics ();
86- if ( statistics .isStatisticsEnabled () ) {
87- statistics .fetchCollection ( loadedPersister .getRole () );
88- }
89- } );
9096 }
9197
9298 private void handlePotentiallyEmptyCollection (
9399 PersistentCollection <?> collection ,
94100 SessionImplementor source ,
95101 CollectionEntry ce ,
96- CollectionPersister ceLoadedPersister ) {
102+ CollectionPersister loadedPersister ) {
97103 if ( !collection .wasInitialized () ) {
98- collection .initializeEmptyCollection ( ceLoadedPersister );
104+ collection .initializeEmptyCollection ( loadedPersister );
99105 ResultsHelper .finalizeCollectionLoading (
100106 source .getPersistenceContext (),
101- ceLoadedPersister ,
107+ loadedPersister ,
102108 collection ,
103109 ce .getLoadedKey (),
104110 true
@@ -120,10 +126,11 @@ private void handlePotentiallyEmptyCollection(
120126 private boolean initializeCollectionFromCache (
121127 Object id ,
122128 CollectionPersister persister ,
123- PersistentCollection collection ,
129+ PersistentCollection <?> collection ,
124130 SessionImplementor source ) {
125131
126- if ( source .getLoadQueryInfluencers ().hasEnabledFilters () && persister .isAffectedByEnabledFilters ( source ) ) {
132+ if ( source .getLoadQueryInfluencers ().hasEnabledFilters ()
133+ && persister .isAffectedByEnabledFilters ( source ) ) {
127134 LOG .trace ( "Disregarding cached version (if any) of collection due to enabled filters" );
128135 return false ;
129136 }
@@ -153,7 +160,8 @@ private boolean initializeCollectionFromCache(
153160 return false ;
154161 }
155162
156- CollectionCacheEntry cacheEntry = (CollectionCacheEntry ) persister .getCacheEntryStructure ().destructure ( ce , factory );
163+ final CollectionCacheEntry cacheEntry = (CollectionCacheEntry )
164+ persister .getCacheEntryStructure ().destructure ( ce , factory );
157165
158166 final PersistenceContext persistenceContext = source .getPersistenceContextInternal ();
159167 cacheEntry .assemble ( collection , persister , persistenceContext .getCollectionOwner ( id , persister ) );
0 commit comments