diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java index c554165dbb..1a56887bd3 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/StatefulPersistenceContext.java @@ -1162,7 +1162,7 @@ public class StatefulPersistenceContext implements PersistenceContext { //not found in case, proceed // iterate all the entities currently associated with the persistence context. - Iterator> entities = IdentityMap.entries(entityEntries).iterator(); + Iterator> entities = IdentityMap.entriesIterator( entityEntries ); while ( entities.hasNext() ) { final Map.Entry me = entities.next(); final EntityEntry entityEntry = me.getValue(); @@ -1286,7 +1286,7 @@ public class StatefulPersistenceContext implements PersistenceContext { } //Not found in cache, proceed - Iterator> entities = IdentityMap.entries(entityEntries).iterator(); + Iterator> entities = IdentityMap.entriesIterator( entityEntries ); while ( entities.hasNext() ) { Map.Entry me = entities.next(); EntityEntry ee = me.getValue(); diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java index e6a0669c80..8d607ac23f 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java @@ -25,7 +25,6 @@ package org.hibernate.event.internal; import java.io.Serializable; import java.util.Iterator; -import java.util.List; import java.util.Map; import org.jboss.logging.Logger; @@ -187,11 +186,10 @@ public abstract class AbstractFlushingEventListener implements Serializable { LOG.debug( "Dirty checking collections" ); - final List list = IdentityMap.entries( persistenceContext.getCollectionEntries() ); - final int size = list.size(); - for ( int i = 0; i < size; i++ ) { - Map.Entry e = ( Map.Entry ) list.get( i ); - ( (CollectionEntry) e.getValue() ).preFlush( (PersistentCollection) e.getKey() ); + Iterator> entriesIterator = IdentityMap.entriesIterator( persistenceContext.getCollectionEntries() ); + while ( entriesIterator.hasNext() ) { + Map.Entry e = entriesIterator.next(); + e.getValue().preFlush( e.getKey() ); } } @@ -248,13 +246,12 @@ public abstract class AbstractFlushingEventListener implements Serializable { LOG.trace( "Processing unreferenced collections" ); - List list = IdentityMap.entries( persistenceContext.getCollectionEntries() ); - int size = list.size(); - for ( int i = 0; i < size; i++ ) { - Map.Entry me = ( Map.Entry ) list.get( i ); - CollectionEntry ce = (CollectionEntry) me.getValue(); + Iterator> entriesIterator = IdentityMap.entriesIterator( persistenceContext.getCollectionEntries() ); + while ( entriesIterator.hasNext() ) { + Map.Entry me = entriesIterator.next(); + CollectionEntry ce = me.getValue(); if ( !ce.isReached() && !ce.isIgnore() ) { - Collections.processUnreachableCollection( (PersistentCollection) me.getKey(), session ); + Collections.processUnreachableCollection( me.getKey(), session ); } } @@ -262,13 +259,12 @@ public abstract class AbstractFlushingEventListener implements Serializable { LOG.trace( "Scheduling collection removes/(re)creates/updates" ); - list = IdentityMap.entries( persistenceContext.getCollectionEntries() ); - size = list.size(); + entriesIterator = IdentityMap.entriesIterator( persistenceContext.getCollectionEntries() ); ActionQueue actionQueue = session.getActionQueue(); - for ( int i = 0; i < size; i++ ) { - Map.Entry me = (Map.Entry) list.get(i); - PersistentCollection coll = (PersistentCollection) me.getKey(); - CollectionEntry ce = (CollectionEntry) me.getValue(); + while ( entriesIterator.hasNext() ) { + Map.Entry me = entriesIterator.next(); + PersistentCollection coll = me.getKey(); + CollectionEntry ce = me.getValue(); if ( ce.isDorecreate() ) { session.getInterceptor().onCollectionRecreate( coll, ce.getCurrentKey() ); diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java index 2468aa3e79..9c91a5536d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/collections/IdentityMap.java @@ -90,8 +90,8 @@ public final class IdentityMap implements Map { return ( (IdentityMap) map ).entryArray(); } - public static List> entries(Map map) { - return ( (IdentityMap) map ).entryList(); + public static Iterator> entriesIterator(Map map) { + return ( (IdentityMap) map ).entryList().iterator(); } public static Iterator keyIterator(Map map) {