Skip to content

Commit a8fc0ff

Browse files
committed
Changes for HR
1 parent 91cdac4 commit a8fc0ff

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,7 @@ public Object[] getDatabaseSnapshot(Object id, EntityPersister persister) throws
330330
}
331331
else {
332332
final Object[] snapshot = persister.getDatabaseSnapshot( id, session );
333-
if ( entitySnapshotsByKey == null ) {
334-
entitySnapshotsByKey = CollectionHelper.mapOfSize( INIT_COLL_SIZE );
335-
}
336-
entitySnapshotsByKey.put( key, snapshot == null ? NO_ROW : snapshot );
333+
getOrInitializeEntitySnapshotsByKey().put( key, snapshot == null ? NO_ROW : snapshot );
337334
return snapshot;
338335
}
339336
}
@@ -1187,7 +1184,8 @@ public void initializeNonLazyCollections() throws HibernateException {
11871184
initializeNonLazyCollections( PersistentCollection::forceInitialization );
11881185
}
11891186

1190-
protected void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction ) {
1187+
@Override
1188+
public void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction ) {
11911189
if ( loadCounter == 0 ) {
11921190
LOG.trace( "Initializing non-lazy collections" );
11931191

@@ -1314,6 +1312,19 @@ public Map<EntityKey,Object> getEntitiesByKey() {
13141312
return result;
13151313
}
13161314

1315+
@Override
1316+
public Map<EntityKey, Object> getEntitySnapshotsByKey() {
1317+
return entitySnapshotsByKey;
1318+
}
1319+
1320+
@Override
1321+
public Map<EntityKey, Object> getOrInitializeEntitySnapshotsByKey() {
1322+
if ( entitySnapshotsByKey == null ) {
1323+
entitySnapshotsByKey = CollectionHelper.mapOfSize( INIT_COLL_SIZE );
1324+
}
1325+
return entitySnapshotsByKey;
1326+
}
1327+
13171328
@Override
13181329
public Map<EntityKey, EntityHolder> getEntityHoldersByKey() {
13191330
//noinspection unchecked,rawtypes

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,18 @@ CollectionEntry addInitializedCollection(
444444
*/
445445
void initializeNonLazyCollections() throws HibernateException;
446446

447+
/**
448+
* Force initialization of all non-lazy collections encountered during
449+
* the current two-phase load (actually, this is a no-op, unless this
450+
* is the "outermost" load) allowing to customize how the initialization
451+
* should occur
452+
*
453+
* @see #initializeNonLazyCollections()
454+
* @param initializeAction the function that initialize the collection
455+
*/
456+
// Used by Hibernate Reactive
457+
void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction);
458+
447459
/**
448460
* Get the {@code PersistentCollection} object for an array
449461
*/
@@ -533,6 +545,12 @@ EntityHolder claimEntityHolderIfPossible(
533545
@Internal
534546
Map<EntityKey,Object> getEntitiesByKey();
535547

548+
@Internal
549+
Map<EntityKey,Object> getEntitySnapshotsByKey();
550+
551+
@Internal
552+
Map<EntityKey,Object> getOrInitializeEntitySnapshotsByKey();
553+
536554
/**
537555
* Doubly internal
538556
*/

0 commit comments

Comments
 (0)