HHH-13587 Make StatefulPersistenceContext#arrayHolders lazily initialized as well
This commit is contained in:
parent
dbbc24c2e1
commit
05b888e0c0
|
@ -162,7 +162,6 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
entityEntryContext = new EntityEntryContext( this );
|
||||
collectionsByKey = new HashMap<>( INIT_COLL_SIZE );
|
||||
arrayHolders = new IdentityHashMap<>( INIT_COLL_SIZE );
|
||||
}
|
||||
|
||||
private ConcurrentMap<EntityKey, Object> getOrInitializeProxiesByKey() {
|
||||
|
@ -243,7 +242,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
IdentityMap.onEachKey( collectionEntries, k -> k.unsetSession( session ) );
|
||||
}
|
||||
|
||||
arrayHolders.clear();
|
||||
arrayHolders = null;
|
||||
entitiesByKey.clear();
|
||||
entitiesByUniqueKey.clear();
|
||||
entityEntryContext.clear();
|
||||
|
@ -981,18 +980,21 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
@Override
|
||||
public PersistentCollection getCollectionHolder(Object array) {
|
||||
return arrayHolders.get( array );
|
||||
return arrayHolders == null ? null : arrayHolders.get( array );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollectionHolder(PersistentCollection holder) {
|
||||
//TODO:refactor + make this method private
|
||||
if ( arrayHolders == null ) {
|
||||
arrayHolders = new IdentityHashMap<>( INIT_COLL_SIZE );
|
||||
}
|
||||
arrayHolders.put( holder.getValue(), holder );
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistentCollection removeCollectionHolder(Object array) {
|
||||
return arrayHolders.remove( array );
|
||||
return arrayHolders != null ? arrayHolders.remove( array ) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1583,6 +1585,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
}
|
||||
}
|
||||
|
||||
if ( arrayHolders == null ) {
|
||||
oos.writeInt( 0 );
|
||||
}
|
||||
else {
|
||||
oos.writeInt( arrayHolders.size() );
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.trace( "Starting serialization of [" + arrayHolders.size() + "] arrayHolders entries" );
|
||||
|
@ -1591,6 +1597,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
oos.writeObject( entry.getKey() );
|
||||
oos.writeObject( entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( nullifiableEntityKeys == null ) {
|
||||
oos.writeInt( 0 );
|
||||
|
@ -1707,10 +1714,12 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.trace( "Starting deserialization of [" + count + "] arrayHolders entries" );
|
||||
}
|
||||
if ( count != 0 ) {
|
||||
rtn.arrayHolders = new IdentityHashMap<>( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
|
||||
for ( int i = 0; i < count; i++ ) {
|
||||
rtn.arrayHolders.put( ois.readObject(), (PersistentCollection) ois.readObject() );
|
||||
}
|
||||
}
|
||||
|
||||
count = ois.readInt();
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
|
|
Loading…
Reference in New Issue