HHH-6862 Use generic Maps for more StatefulPersistenceContext fields

This commit is contained in:
Sanne Grinovero 2011-11-29 11:30:42 +00:00 committed by Strong Liu
parent f98e15e15f
commit 67d1c70335
2 changed files with 31 additions and 31 deletions

View File

@ -93,39 +93,39 @@ public class StatefulPersistenceContext implements PersistenceContext {
private SessionImplementor session;
// Loaded entity instances, by EntityKey
private Map entitiesByKey;
private Map<EntityKey, Object> entitiesByKey;
// Loaded entity instances, by EntityUniqueKey
private Map entitiesByUniqueKey;
private Map<EntityUniqueKey, Object> entitiesByUniqueKey;
// Identity map of EntityEntry instances, by the entity instance
private Map<Object,EntityEntry> entityEntries;
// Entity proxies, by EntityKey
private Map proxiesByKey;
private Map<EntityKey, Object> proxiesByKey;
// Snapshots of current database state for entities
// that have *not* been loaded
private Map entitySnapshotsByKey;
private Map<EntityKey, Object> entitySnapshotsByKey;
// Identity map of array holder ArrayHolder instances, by the array instance
private Map arrayHolders;
private Map<Object, PersistentCollection> arrayHolders;
// Identity map of CollectionEntry instances, by the collection wrapper
private Map collectionEntries;
private Map<PersistentCollection, CollectionEntry> collectionEntries;
// Collection wrappers, by the CollectionKey
private Map collectionsByKey; //key=CollectionKey, value=PersistentCollection
private Map<CollectionKey, PersistentCollection> collectionsByKey;
// Set of EntityKeys of deleted objects
private HashSet nullifiableEntityKeys;
private HashSet<EntityKey> nullifiableEntityKeys;
// properties that we have tried to load, and not found in the database
private HashSet nullAssociations;
private HashSet<AssociationKey> nullAssociations;
// A list of collection wrappers that were instantiating during result set
// processing, that we will need to initialize at the end of the query
private List nonlazyCollections;
private List<PersistentCollection> nonlazyCollections;
// A container for collections we load up when the owning entity is not
// yet loaded ... for now, this is purely transient!
@ -223,9 +223,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
final LazyInitializer li = ((HibernateProxy) o).getHibernateLazyInitializer();
li.unsetSession();
}
Map.Entry[] collectionEntryArray = IdentityMap.concurrentEntries( collectionEntries );
for ( Map.Entry aCollectionEntryArray : collectionEntryArray ) {
((PersistentCollection) aCollectionEntryArray.getKey()).unsetSession( getSession() );
Map.Entry<PersistentCollection, CollectionEntry>[] collectionEntryArray = IdentityMap.concurrentEntries( collectionEntries );
for ( Map.Entry<PersistentCollection, CollectionEntry> aCollectionEntryArray : collectionEntryArray ) {
aCollectionEntryArray.getKey().unsetSession( getSession() );
}
arrayHolders.clear();
entitiesByKey.clear();
@ -444,7 +444,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
* Get the collection entry for a persistent collection
*/
public CollectionEntry getCollectionEntry(PersistentCollection coll) {
return (CollectionEntry) collectionEntries.get(coll);
return collectionEntries.get(coll);
}
/**
@ -822,7 +822,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
private void addCollection(PersistentCollection coll, CollectionEntry entry, Serializable key) {
collectionEntries.put( coll, entry );
CollectionKey collectionKey = new CollectionKey( entry.getLoadedPersister(), key );
PersistentCollection old = ( PersistentCollection ) collectionsByKey.put( collectionKey, coll );
PersistentCollection old = collectionsByKey.put( collectionKey, coll );
if ( old != null ) {
if ( old == coll ) {
throw new AssertionFailure("bug adding collection twice");
@ -877,7 +877,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
* Get the collection instance associated with the <tt>CollectionKey</tt>
*/
public PersistentCollection getCollection(CollectionKey collectionKey) {
return (PersistentCollection) collectionsByKey.get(collectionKey);
return collectionsByKey.get( collectionKey );
}
/**
@ -902,7 +902,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
int size;
while ( ( size = nonlazyCollections.size() ) > 0 ) {
//note that each iteration of the loop may add new elements
( (PersistentCollection) nonlazyCollections.remove( size - 1 ) ).forceInitialization();
nonlazyCollections.remove( size - 1 ).forceInitialization();
}
}
finally {
@ -917,7 +917,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
* Get the <tt>PersistentCollection</tt> object for an array
*/
public PersistentCollection getCollectionHolder(Object array) {
return (PersistentCollection) arrayHolders.get(array);
return arrayHolders.get(array);
}
/**
@ -931,7 +931,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
}
public PersistentCollection removeCollectionHolder(Object array) {
return (PersistentCollection) arrayHolders.remove(array);
return arrayHolders.remove(array);
}
/**
@ -957,9 +957,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( coll == null ) {
//it might be an unwrapped collection reference!
//try to find a wrapper (slowish)
Iterator wrappers = IdentityMap.keyIterator(collectionEntries);
Iterator<PersistentCollection> wrappers = IdentityMap.keyIterator( collectionEntries );
while ( wrappers.hasNext() ) {
PersistentCollection pc = (PersistentCollection) wrappers.next();
PersistentCollection pc = wrappers.next();
if ( pc.isWrapper(collection) ) {
coll = pc;
break;
@ -1517,9 +1517,9 @@ public class StatefulPersistenceContext implements PersistenceContext {
oos.writeInt( nullifiableEntityKeys.size() );
if ( tracing ) LOG.trace("Starting serialization of [" + nullifiableEntityKeys.size() + "] nullifiableEntityKey entries");
itr = nullifiableEntityKeys.iterator();
while ( itr.hasNext() ) {
EntityKey entry = ( EntityKey ) itr.next();
Iterator<EntityKey> entityKeyIterator = nullifiableEntityKeys.iterator();
while ( entityKeyIterator.hasNext() ) {
EntityKey entry = entityKeyIterator.next();
entry.serialize( oos );
}
}
@ -1590,7 +1590,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( tracing ) LOG.trace("Starting deserialization of [" + count + "] collectionsByKey entries");
rtn.collectionsByKey = new HashMap( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
for ( int i = 0; i < count; i++ ) {
rtn.collectionsByKey.put( CollectionKey.deserialize( ois, session ), ois.readObject() );
rtn.collectionsByKey.put( CollectionKey.deserialize( ois, session ), (PersistentCollection) ois.readObject() );
}
count = ois.readInt();
@ -1607,7 +1607,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
if ( tracing ) LOG.trace("Starting deserialization of [" + count + "] arrayHolders entries");
rtn.arrayHolders = IdentityMap.instantiate( count < INIT_COLL_SIZE ? INIT_COLL_SIZE : count );
for ( int i = 0; i < count; i++ ) {
rtn.arrayHolders.put( ois.readObject(), ois.readObject() );
rtn.arrayHolders.put( ois.readObject(), (PersistentCollection) ois.readObject() );
}
count = ois.readInt();

View File

@ -86,16 +86,16 @@ public final class IdentityMap<K,V> implements Map<K,V> {
* @param map The map of entries
* @return Collection
*/
public static Map.Entry[] concurrentEntries(Map map) {
return ( (IdentityMap) map ).entryArray();
public static <K,V> Map.Entry<K,V>[] concurrentEntries(Map<K,V> map) {
return ( (IdentityMap<K,V>) map ).entryArray();
}
public static <K,V> List<Entry<K,V>> entries(Map<K,V> map) {
return ( (IdentityMap) map ).entryList();
return ( (IdentityMap<K,V>) map ).entryList();
}
public static Iterator keyIterator(Map map) {
return ( (IdentityMap) map ).keyIterator();
public static <K,V> Iterator<K> keyIterator(Map<K,V> map) {
return ( (IdentityMap<K,V>) map ).keyIterator();
}
public Iterator keyIterator() {