HHH-14093 Make StatefulPersistenceContext#registerInsertedKey and StatefulPersistenceContext#wasInsertedDuringTransaction use HashSet instead of ArrayList

This commit is contained in:
katiforis 2020-07-09 09:19:11 +03:00 committed by Sanne Grinovero
parent 677a65a8cf
commit f1243a3285
1 changed files with 6 additions and 8 deletions

View File

@ -18,7 +18,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentMap;
@ -1831,7 +1830,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
// INSERTED KEYS HANDLING ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private HashMap<String,List<Serializable>> insertedKeysMap;
private HashMap<String, HashSet<Serializable>> insertedKeysMap;
@Override
public void registerInsertedKey(EntityPersister persister, Serializable id) {
@ -1841,11 +1840,10 @@ public class StatefulPersistenceContext implements PersistenceContext {
insertedKeysMap = new HashMap<>();
}
final String rootEntityName = persister.getRootEntityName();
List<Serializable> insertedEntityIds = insertedKeysMap.get( rootEntityName );
if ( insertedEntityIds == null ) {
insertedEntityIds = new ArrayList<>();
insertedKeysMap.put( rootEntityName, insertedEntityIds );
}
HashSet<Serializable> insertedEntityIds = insertedKeysMap.computeIfAbsent(
rootEntityName,
k -> new HashSet<>()
);
insertedEntityIds.add( id );
}
}
@ -1855,7 +1853,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
// again, we only really care if the entity is cached
if ( persister.canWriteToCache() ) {
if ( insertedKeysMap != null ) {
final List<Serializable> insertedEntityIds = insertedKeysMap.get( persister.getRootEntityName() );
final HashSet<Serializable> insertedEntityIds = insertedKeysMap.get( persister.getRootEntityName() );
if ( insertedEntityIds != null ) {
return insertedEntityIds.contains( id );
}