From: Sergey K. <jus...@us...> - 2005-02-16 20:15:17
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30719/src/NHibernate/Impl Modified Files: SessionImpl.cs Log Message: Renamed PersistentCollection.ForceLoad to ForceInitialization, in accordance with H2.1 Added non-lazy collections handling which fixed a bug when non-lazy collections didn't initialize. Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.66 retrieving revision 1.67 diff -C2 -d -r1.66 -r1.67 *** SessionImpl.cs 11 Feb 2005 21:26:23 -0000 1.66 --- SessionImpl.cs 16 Feb 2005 20:14:20 -0000 1.67 *************** *** 186,189 **** --- 186,192 ---- [NonSerialized] + private int loadCounter = 0; + + [NonSerialized] private bool flushing; *************** *** 191,194 **** --- 194,200 ---- private IBatcher batcher; + [NonSerialized] + private IList nonlazyCollections = new ArrayList(20); + #region System.Runtime.Serialization.ISerializable Members *************** *** 2533,2537 **** AddEntry( result, Status.Loaded, values, id, version, LockMode.None, true, subclassPersister ); ! // TODO: InitializeNonLazyCollections(); // upgrate lock if necessary; --- 2539,2543 ---- AddEntry( result, Status.Loaded, values, id, version, LockMode.None, true, subclassPersister ); ! InitializeNonLazyCollections(); // upgrate lock if necessary; *************** *** 3489,3493 **** { log.Debug( "forcing collection initialization" ); ! coll.ForceLoad(); } } --- 3495,3499 ---- { log.Debug( "forcing collection initialization" ); ! coll.ForceInitialization(); } } *************** *** 3513,3516 **** --- 3519,3523 ---- private IDictionary loadingCollections = new Hashtable(); + private string loadingRole; *************** *** 3651,3654 **** --- 3658,3697 ---- } + public void BeforeLoad() + { + loadCounter++; + } + + public void AfterLoad() + { + loadCounter--; + } + + public void InitializeNonLazyCollections() + { + if( loadCounter==0 ) + { + log.Debug( "initializing non-lazy collections" ); + // Do this work only at the very highest level of the load + + // Don't let this method be called recursively + loadCounter++; + try + { + while (nonlazyCollections.Count > 0) + { + //note that each iteration of the loop may add new elements + PersistentCollection collection = (PersistentCollection)nonlazyCollections[ nonlazyCollections.Count - 1 ]; + nonlazyCollections.RemoveAt( nonlazyCollections.Count - 1 ); + collection.ForceInitialization(); + } + } + finally + { + loadCounter--; + } + } + } + private PersistentCollection GetCollection(CollectionKey key) { *************** *** 4545,4549 **** else if ( !persister.IsLazy ) { ! //nonlazyCollections.Add(collection); } return collection.GetValue(); --- 4588,4592 ---- else if ( !persister.IsLazy ) { ! nonlazyCollections.Add(collection); } return collection.GetValue(); |