72
72
73
73
import org .checkerframework .checker .nullness .qual .Nullable ;
74
74
75
+ import static java .util .Collections .emptyMap ;
75
76
import static org .hibernate .engine .internal .ManagedTypeHelper .asHibernateProxy ;
76
77
import static org .hibernate .engine .internal .ManagedTypeHelper .asManagedEntity ;
77
78
import static org .hibernate .engine .internal .ManagedTypeHelper .asPersistentAttributeInterceptable ;
78
79
import static org .hibernate .engine .internal .ManagedTypeHelper .isPersistentAttributeInterceptable ;
80
+ import static org .hibernate .internal .util .collections .CollectionHelper .mapOfSize ;
79
81
import static org .hibernate .proxy .HibernateProxy .extractLazyInitializer ;
80
82
81
83
/**
@@ -183,7 +185,7 @@ the following fields are used in all circumstances, and are not worth (or not su
183
185
184
186
private Map <EntityKey , EntityHolderImpl > getOrInitializeEntitiesByKey () {
185
187
if ( entitiesByKey == null ) {
186
- entitiesByKey = CollectionHelper . mapOfSize ( INIT_COLL_SIZE );
188
+ entitiesByKey = mapOfSize ( INIT_COLL_SIZE );
187
189
}
188
190
return entitiesByKey ;
189
191
}
@@ -484,17 +486,10 @@ private void processLoadedEntityHolder(
484
486
postLoadEvent .setEntity ( holder .getEntity () )
485
487
.setId ( holder .getEntityKey ().getIdentifier () )
486
488
.setPersister ( holder .getDescriptor () );
487
- listenerGroup .fireEventOnEachListener (
488
- postLoadEvent ,
489
- PostLoadEventListener ::onPostLoad
490
- );
489
+ listenerGroup .fireEventOnEachListener ( postLoadEvent , PostLoadEventListener ::onPostLoad );
491
490
}
492
491
if ( callback != null ) {
493
- callback .invokeAfterLoadActions (
494
- holder .getEntity (),
495
- holder .getDescriptor (),
496
- getSession ()
497
- );
492
+ callback .invokeAfterLoadActions ( holder .getEntity (), holder .getDescriptor (), getSession () );
498
493
}
499
494
holder .resetEntityInitialier ();
500
495
}
@@ -599,7 +594,7 @@ public Object getEntity(EntityUniqueKey euk) {
599
594
@ Override
600
595
public void addEntity (EntityUniqueKey euk , Object entity ) {
601
596
if ( entitiesByUniqueKey == null ) {
602
- entitiesByUniqueKey = CollectionHelper . mapOfSize ( INIT_COLL_SIZE );
597
+ entitiesByUniqueKey = mapOfSize ( INIT_COLL_SIZE );
603
598
}
604
599
entitiesByUniqueKey .put ( euk , entity );
605
600
}
@@ -733,7 +728,8 @@ public EntityEntry addReferenceEntry(
733
728
734
729
@ Override
735
730
public boolean containsCollection (PersistentCollection <?> collection ) {
736
- return collectionEntries != null && collectionEntries .containsKey ( collection .$$_hibernate_getInstanceId (), collection );
731
+ return collectionEntries != null
732
+ && collectionEntries .containsKey ( collection .$$_hibernate_getInstanceId (), collection );
737
733
}
738
734
739
735
@ Override
@@ -818,9 +814,8 @@ public Object unproxy(Object maybeProxy) throws HibernateException {
818
814
final LazyInitializer lazyInitializer = extractLazyInitializer ( maybeProxy );
819
815
if ( lazyInitializer != null ) {
820
816
if ( lazyInitializer .isUninitialized () ) {
821
- throw new PersistentObjectException (
822
- "object was an uninitialized proxy for " + lazyInitializer .getEntityName ()
823
- );
817
+ throw new PersistentObjectException ( "object was an uninitialized proxy for "
818
+ + lazyInitializer .getEntityName () );
824
819
}
825
820
//unwrap the object and return
826
821
return lazyInitializer .getImplementation ();
@@ -839,10 +834,11 @@ public Object unproxyAndReassociate(final Object maybeProxy) throws HibernateExc
839
834
return lazyInitializer .getImplementation ();
840
835
}
841
836
else if ( isPersistentAttributeInterceptable ( maybeProxy ) ) {
842
- final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable ( maybeProxy );
843
- final PersistentAttributeInterceptor interceptor = interceptable .$$_hibernate_getInterceptor ();
844
- if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
845
- ( (EnhancementAsProxyLazinessInterceptor ) interceptor ).forceInitialize ( maybeProxy , null );
837
+ final PersistentAttributeInterceptor interceptor =
838
+ asPersistentAttributeInterceptable ( maybeProxy )
839
+ .$$_hibernate_getInterceptor ();
840
+ if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
841
+ lazinessInterceptor .forceInitialize ( maybeProxy , null );
846
842
}
847
843
return maybeProxy ;
848
844
}
@@ -893,7 +889,8 @@ public Object narrowProxy(Object proxy, EntityPersister persister, EntityKey key
893
889
894
890
895
891
// Otherwise, create the narrowed proxy
896
- final HibernateProxy narrowedProxy = asHibernateProxy ( persister .createProxy ( key .getIdentifier (), session ) );
892
+ final HibernateProxy narrowedProxy =
893
+ asHibernateProxy ( persister .createProxy ( key .getIdentifier (), session ) );
897
894
// set the read-only/modifiable mode in the new proxy to what it was in the original proxy
898
895
narrowedProxy .getHibernateLazyInitializer ().setReadOnly ( lazyInitializer .isReadOnly () );
899
896
return narrowedProxy ;
@@ -1309,9 +1306,9 @@ public Object removeProxy(EntityKey key) {
1309
1306
@ Override
1310
1307
public Map <EntityKey ,Object > getEntitiesByKey () {
1311
1308
if ( entitiesByKey == null ) {
1312
- return Collections . emptyMap ();
1309
+ return emptyMap ();
1313
1310
}
1314
- final HashMap <EntityKey , Object > result = CollectionHelper . mapOfSize ( entitiesByKey .size () );
1311
+ final HashMap <EntityKey , Object > result = mapOfSize ( entitiesByKey .size () );
1315
1312
for ( Entry <EntityKey , EntityHolderImpl > entry : entitiesByKey .entrySet () ) {
1316
1313
if ( entry .getValue ().entity != null ) {
1317
1314
result .put ( entry .getKey (), entry .getValue ().entity );
@@ -1330,7 +1327,7 @@ public Map<EntityKey, Object> getEntitySnapshotsByKey() {
1330
1327
@ Override
1331
1328
public Map <EntityKey , Object > getOrInitializeEntitySnapshotsByKey () {
1332
1329
if ( entitySnapshotsByKey == null ) {
1333
- entitySnapshotsByKey = CollectionHelper . mapOfSize ( INIT_COLL_SIZE );
1330
+ entitySnapshotsByKey = mapOfSize ( INIT_COLL_SIZE );
1334
1331
}
1335
1332
return entitySnapshotsByKey ;
1336
1333
}
@@ -1384,11 +1381,6 @@ public int getNumberOfManagedEntities() {
1384
1381
return entityEntryContext .getNumberOfManagedEntities ();
1385
1382
}
1386
1383
1387
- // @Override
1388
- // public Map getEntityEntries() {
1389
- // return null;
1390
- // }
1391
-
1392
1384
/**
1393
1385
* @deprecated We should not expose this directly: the other accessors that have been created as a replacement
1394
1386
* have better chances of skipping initializing this map, which is a good performance improvement.
@@ -1420,7 +1412,7 @@ public void forEachCollectionEntry(BiConsumer<PersistentCollection<?>, Collectio
1420
1412
1421
1413
@ Override
1422
1414
public Map <CollectionKey ,PersistentCollection <?>> getCollectionsByKey () {
1423
- return collectionsByKey == null ? Collections . emptyMap () : collectionsByKey ;
1415
+ return collectionsByKey == null ? emptyMap () : collectionsByKey ;
1424
1416
}
1425
1417
1426
1418
@ Override
@@ -1997,7 +1989,7 @@ public static StatefulPersistenceContext deserialize(
1997
1989
LOG .trace ( "Starting deserialization of [" + count + "] entitiesByUniqueKey entries" );
1998
1990
}
1999
1991
if ( count != 0 ) {
2000
- rtn .entitiesByUniqueKey = CollectionHelper . mapOfSize (Math .max (count , INIT_COLL_SIZE ));
1992
+ rtn .entitiesByUniqueKey = mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2001
1993
for ( int i = 0 ; i < count ; i ++ ) {
2002
1994
rtn .entitiesByUniqueKey .put ( EntityUniqueKey .deserialize ( ois , session ), ois .readObject () );
2003
1995
}
@@ -2007,7 +1999,7 @@ public static StatefulPersistenceContext deserialize(
2007
1999
if ( traceEnabled ) {
2008
2000
LOG .trace ( "Starting deserialization of [" + count + "] entitySnapshotsByKey entries" );
2009
2001
}
2010
- rtn .entitySnapshotsByKey = CollectionHelper . mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2002
+ rtn .entitySnapshotsByKey = mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2011
2003
for ( int i = 0 ; i < count ; i ++ ) {
2012
2004
rtn .entitySnapshotsByKey .put ( EntityKey .deserialize ( ois , sfi ), ois .readObject () );
2013
2005
}
@@ -2018,7 +2010,7 @@ public static StatefulPersistenceContext deserialize(
2018
2010
if ( traceEnabled ) {
2019
2011
LOG .trace ( "Starting deserialization of [" + count + "] entitiesByKey entries" );
2020
2012
}
2021
- rtn .entitiesByKey = CollectionHelper . mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2013
+ rtn .entitiesByKey = mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2022
2014
for ( int i = 0 ; i < count ; i ++ ) {
2023
2015
final EntityKey ek = EntityKey .deserialize ( ois , sfi );
2024
2016
final EntityPersister persister = sfi .getMappingMetamodel ().getEntityDescriptor ( (String ) ois .readObject () );
@@ -2048,7 +2040,7 @@ public static StatefulPersistenceContext deserialize(
2048
2040
if ( traceEnabled ) {
2049
2041
LOG .trace ( "Starting deserialization of [" + count + "] collectionsByKey entries" );
2050
2042
}
2051
- rtn .collectionsByKey = CollectionHelper . mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2043
+ rtn .collectionsByKey = mapOfSize (Math .max (count , INIT_COLL_SIZE ));
2052
2044
for ( int i = 0 ; i < count ; i ++ ) {
2053
2045
rtn .collectionsByKey .put (
2054
2046
CollectionKey .deserialize ( ois , session ),
@@ -2230,7 +2222,7 @@ public void clearCollectionsByKey() {
2230
2222
@ Override
2231
2223
public PersistentCollection <?> addCollectionByKey (CollectionKey collectionKey , PersistentCollection <?> persistentCollection ) {
2232
2224
if ( collectionsByKey == null ) {
2233
- collectionsByKey = CollectionHelper . mapOfSize ( INIT_COLL_SIZE );
2225
+ collectionsByKey = mapOfSize ( INIT_COLL_SIZE );
2234
2226
}
2235
2227
return collectionsByKey .put ( collectionKey , persistentCollection );
2236
2228
}
0 commit comments