mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-28 23:09:13 +00:00
HHH-13587 Make StatefulPersistenceContext#arrayHolders lazily initialized as well
This commit is contained in:
parent
dbbc24c2e1
commit
05b888e0c0
@ -162,7 +162,6 @@ public StatefulPersistenceContext(SharedSessionContractImplementor session) {
|
||||
|
||||
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 void clear() {
|
||||
IdentityMap.onEachKey( collectionEntries, k -> k.unsetSession( session ) );
|
||||
}
|
||||
|
||||
arrayHolders.clear();
|
||||
arrayHolders = null;
|
||||
entitiesByKey.clear();
|
||||
entitiesByUniqueKey.clear();
|
||||
entityEntryContext.clear();
|
||||
@ -981,18 +980,21 @@ public void initializeNonLazyCollections() throws HibernateException {
|
||||
|
||||
@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,13 +1585,18 @@ public void serialize(ObjectOutputStream oos) throws IOException {
|
||||
}
|
||||
}
|
||||
|
||||
oos.writeInt( arrayHolders.size() );
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.trace( "Starting serialization of [" + arrayHolders.size() + "] arrayHolders entries" );
|
||||
if ( arrayHolders == null ) {
|
||||
oos.writeInt( 0 );
|
||||
}
|
||||
for ( Map.Entry<Object,PersistentCollection> entry : arrayHolders.entrySet() ) {
|
||||
oos.writeObject( entry.getKey() );
|
||||
oos.writeObject( entry.getValue() );
|
||||
else {
|
||||
oos.writeInt( arrayHolders.size() );
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.trace( "Starting serialization of [" + arrayHolders.size() + "] arrayHolders entries" );
|
||||
}
|
||||
for ( Map.Entry<Object,PersistentCollection> entry : arrayHolders.entrySet() ) {
|
||||
oos.writeObject( entry.getKey() );
|
||||
oos.writeObject( entry.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
if ( nullifiableEntityKeys == null ) {
|
||||
@ -1707,9 +1714,11 @@ public static StatefulPersistenceContext deserialize(
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.trace( "Starting deserialization of [" + count + "] arrayHolders entries" );
|
||||
}
|
||||
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() );
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user