Skip to content

Commit d33a309

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

File tree

2 files changed

+44
-27
lines changed

2 files changed

+44
-27
lines changed

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

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,7 @@
44
*/
55
package org.hibernate.engine.internal;
66

7-
import java.io.IOException;
8-
import java.io.InvalidObjectException;
9-
import java.io.ObjectInputStream;
10-
import java.io.ObjectOutputStream;
11-
import java.io.Serializable;
12-
import java.lang.invoke.MethodHandles;
13-
import java.util.ArrayList;
14-
import java.util.Collection;
15-
import java.util.Collections;
16-
import java.util.HashMap;
17-
import java.util.HashSet;
18-
import java.util.IdentityHashMap;
19-
import java.util.Iterator;
20-
import java.util.Map;
21-
import java.util.Map.Entry;
22-
import java.util.NoSuchElementException;
23-
import java.util.function.BiConsumer;
24-
import java.util.function.Consumer;
25-
import java.util.function.Supplier;
26-
7+
import org.checkerframework.checker.nullness.qual.Nullable;
278
import org.hibernate.AssertionFailure;
289
import org.hibernate.Hibernate;
2910
import org.hibernate.HibernateException;
@@ -67,10 +48,27 @@
6748
import org.hibernate.sql.results.jdbc.spi.JdbcValuesSourceProcessingState;
6849
import org.hibernate.sql.results.spi.LoadContexts;
6950
import org.hibernate.type.CollectionType;
70-
7151
import org.jboss.logging.Logger;
7252

73-
import org.checkerframework.checker.nullness.qual.Nullable;
53+
import java.io.IOException;
54+
import java.io.InvalidObjectException;
55+
import java.io.ObjectInputStream;
56+
import java.io.ObjectOutputStream;
57+
import java.io.Serializable;
58+
import java.lang.invoke.MethodHandles;
59+
import java.util.ArrayList;
60+
import java.util.Collection;
61+
import java.util.Collections;
62+
import java.util.HashMap;
63+
import java.util.HashSet;
64+
import java.util.IdentityHashMap;
65+
import java.util.Iterator;
66+
import java.util.Map;
67+
import java.util.Map.Entry;
68+
import java.util.NoSuchElementException;
69+
import java.util.function.BiConsumer;
70+
import java.util.function.Consumer;
71+
import java.util.function.Supplier;
7472

7573
import static org.hibernate.engine.internal.ManagedTypeHelper.asHibernateProxy;
7674
import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity;
@@ -330,10 +328,7 @@ public Object[] getDatabaseSnapshot(Object id, EntityPersister persister) throws
330328
}
331329
else {
332330
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 );
331+
getOrInitializeEntitySnapshotsByKey().put( key, snapshot == null ? NO_ROW : snapshot );
337332
return snapshot;
338333
}
339334
}
@@ -1187,7 +1182,8 @@ public void initializeNonLazyCollections() throws HibernateException {
11871182
initializeNonLazyCollections( PersistentCollection::forceInitialization );
11881183
}
11891184

1190-
protected void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction ) {
1185+
@Override
1186+
public void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction) {
11911187
if ( loadCounter == 0 ) {
11921188
LOG.trace( "Initializing non-lazy collections" );
11931189

@@ -1314,6 +1310,19 @@ public Map<EntityKey,Object> getEntitiesByKey() {
13141310
return result;
13151311
}
13161312

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

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

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

447+
void initializeNonLazyCollections(Consumer<PersistentCollection<?>> initializeAction);
448+
447449
/**
448450
* Get the {@code PersistentCollection} object for an array
449451
*/
@@ -533,6 +535,12 @@ EntityHolder claimEntityHolderIfPossible(
533535
@Internal
534536
Map<EntityKey,Object> getEntitiesByKey();
535537

538+
@Internal
539+
Map<EntityKey,Object> getEntitySnapshotsByKey();
540+
541+
@Internal
542+
Map<EntityKey,Object> getOrInitializeEntitySnapshotsByKey();
543+
536544
/**
537545
* Doubly internal
538546
*/

0 commit comments

Comments
 (0)