|
26 | 26 |
|
27 | 27 | import org.checkerframework.checker.nullness.qual.Nullable; |
28 | 28 |
|
| 29 | +import static org.hibernate.internal.util.NullnessUtil.castNonNull; |
| 30 | + |
29 | 31 | /** |
30 | 32 | * Base support for CollectionInitializer implementations that represent |
31 | 33 | * an immediate initialization of some sort (join, select, batch, sub-select) |
@@ -141,7 +143,39 @@ public void resolveState(Data data) { |
141 | 143 | public void resolveFromPreviousRow(Data data) { |
142 | 144 | super.resolveFromPreviousRow( data ); |
143 | 145 | if ( data.getState() == State.RESOLVED ) { |
144 | | -resolveKeySubInitializers( data ); |
| 146 | +// The state is resolved, so we know a collection instance exists |
| 147 | +final PersistentCollection<?> collection = castNonNull( data.getCollectionInstance() ); |
| 148 | +if ( collection.wasInitialized() ) { |
| 149 | +// The collection was an already initialized instance, so we can set this to initialized |
| 150 | +// and just resolve sub-initializers |
| 151 | +resolveFromPreviouslyInitializedInstance( data ); |
| 152 | +} |
| 153 | +else { |
| 154 | +resolveKeySubInitializers( data ); |
| 155 | +} |
| 156 | +} |
| 157 | +} |
| 158 | + |
| 159 | +protected void resolveFromPreviouslyInitializedInstance(Data data) { |
| 160 | +data.setState( State.INITIALIZED ); |
| 161 | +if ( data.shallowCached ) { |
| 162 | +initializeShallowCached( data ); |
| 163 | +} |
| 164 | +else { |
| 165 | +resolveInstanceSubInitializers( data ); |
| 166 | +} |
| 167 | +final var rowProcessingState = data.getRowProcessingState(); |
| 168 | +if ( rowProcessingState.needsResolveState() ) { |
| 169 | +// Resolve the state of the identifier if result caching is enabled and this is not a query cache hit |
| 170 | +if ( collectionKeyResultAssembler != null ) { |
| 171 | +collectionKeyResultAssembler.resolveState( rowProcessingState ); |
| 172 | +} |
| 173 | +if ( !getInitializingCollectionDescriptor().useShallowQueryCacheLayout() ) { |
| 174 | +if ( collectionValueKeyResultAssembler != null ) { |
| 175 | +collectionValueKeyResultAssembler.resolveState( rowProcessingState ); |
| 176 | +} |
| 177 | +resolveCollectionContentState( rowProcessingState ); |
| 178 | +} |
145 | 179 | } |
146 | 180 | } |
147 | 181 |
|
@@ -337,25 +371,7 @@ public void resolveInstance(Object instance, Data data) { |
337 | 371 | } |
338 | 372 | data.collectionValueKey = null; |
339 | 373 | if ( collection.wasInitialized() ) { |
340 | | -data.setState( State.INITIALIZED ); |
341 | | -if ( data.shallowCached ) { |
342 | | -initializeShallowCached( data ); |
343 | | -} |
344 | | -else { |
345 | | -resolveInstanceSubInitializers( data ); |
346 | | -} |
347 | | -if ( rowProcessingState.needsResolveState() ) { |
348 | | -// Resolve the state of the identifier if result caching is enabled and this is not a query cache hit |
349 | | -if ( collectionKeyResultAssembler != null ) { |
350 | | -collectionKeyResultAssembler.resolveState( rowProcessingState ); |
351 | | -} |
352 | | -if ( !getInitializingCollectionDescriptor().useShallowQueryCacheLayout() ) { |
353 | | -if ( collectionValueKeyResultAssembler != null ) { |
354 | | -collectionValueKeyResultAssembler.resolveState( rowProcessingState ); |
355 | | -} |
356 | | -resolveCollectionContentState( rowProcessingState ); |
357 | | -} |
358 | | -} |
| 374 | +resolveFromPreviouslyInitializedInstance( data ); |
359 | 375 | } |
360 | 376 | else { |
361 | 377 | if ( data.shallowCached ) { |
|
0 commit comments