@@ -42,9 +42,10 @@ public void onInitializeCollection(InitializeCollectionEvent event) throws Hiber
42
42
* called by a collection that wants to initialize itself
43
43
*/
44
44
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 );
48
49
if ( ce == null ) {
49
50
throw LOG .collectionWasEvicted ();
50
51
}
@@ -55,50 +56,55 @@ public CompletionStage<Void> onReactiveInitializeCollection(InitializeCollection
55
56
}
56
57
57
58
final CollectionPersister loadedPersister = ce .getLoadedPersister ();
59
+ final Object loadedKey = ce .getLoadedKey ();
58
60
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
+ );
60
65
LOG .trace ( "Checking second-level cache" );
61
66
}
62
67
63
- final boolean foundInCache = initializeCollectionFromCache ( ce . getLoadedKey () , loadedPersister , collection , source );
68
+ final boolean foundInCache = initializeCollectionFromCache ( loadedKey , loadedPersister , collection , source );
64
69
if ( foundInCache ) {
65
70
if ( LOG .isTraceEnabled () ) {
66
71
LOG .trace ( "Collection initialized from cache" );
67
72
}
68
73
return voidFuture ();
69
74
}
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
+ } );
73
95
}
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
- } );
90
96
}
91
97
92
98
private void handlePotentiallyEmptyCollection (
93
99
PersistentCollection <?> collection ,
94
100
SessionImplementor source ,
95
101
CollectionEntry ce ,
96
- CollectionPersister ceLoadedPersister ) {
102
+ CollectionPersister loadedPersister ) {
97
103
if ( !collection .wasInitialized () ) {
98
- collection .initializeEmptyCollection ( ceLoadedPersister );
104
+ collection .initializeEmptyCollection ( loadedPersister );
99
105
ResultsHelper .finalizeCollectionLoading (
100
106
source .getPersistenceContext (),
101
- ceLoadedPersister ,
107
+ loadedPersister ,
102
108
collection ,
103
109
ce .getLoadedKey (),
104
110
true
@@ -120,10 +126,11 @@ private void handlePotentiallyEmptyCollection(
120
126
private boolean initializeCollectionFromCache (
121
127
Object id ,
122
128
CollectionPersister persister ,
123
- PersistentCollection collection ,
129
+ PersistentCollection <?> collection ,
124
130
SessionImplementor source ) {
125
131
126
- if ( source .getLoadQueryInfluencers ().hasEnabledFilters () && persister .isAffectedByEnabledFilters ( source ) ) {
132
+ if ( source .getLoadQueryInfluencers ().hasEnabledFilters ()
133
+ && persister .isAffectedByEnabledFilters ( source ) ) {
127
134
LOG .trace ( "Disregarding cached version (if any) of collection due to enabled filters" );
128
135
return false ;
129
136
}
@@ -153,7 +160,8 @@ private boolean initializeCollectionFromCache(
153
160
return false ;
154
161
}
155
162
156
- CollectionCacheEntry cacheEntry = (CollectionCacheEntry ) persister .getCacheEntryStructure ().destructure ( ce , factory );
163
+ final CollectionCacheEntry cacheEntry = (CollectionCacheEntry )
164
+ persister .getCacheEntryStructure ().destructure ( ce , factory );
157
165
158
166
final PersistenceContext persistenceContext = source .getPersistenceContextInternal ();
159
167
cacheEntry .assemble ( collection , persister , persistenceContext .getCollectionOwner ( id , persister ) );
0 commit comments