From: Peter S. <sz...@us...> - 2004-08-06 15:35:06
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18582 Modified Files: SessionImpl.cs Log Message: Started implementing session serialization Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** SessionImpl.cs 13 Jul 2004 20:55:15 -0000 1.35 --- SessionImpl.cs 6 Aug 2004 15:34:57 -0000 1.36 *************** *** 3,6 **** --- 3,7 ---- using System.Text; using System.Collections; + using System.Runtime.Serialization; using System.Text.RegularExpressions; using NHibernate.Type; *************** *** 255,258 **** --- 256,263 ---- [NonSerialized] private IBatcher batcher; + + // For serialization + [NonSerialized] private SerializationInfo siInfo; + private IPreparer preparer; *************** *** 527,534 **** } ! //TODO: add serialization / deserialization stuff here ! // private void readObject ! // private void writeObject ! internal SessionImpl(IDbConnection connection, SessionFactoryImpl factory, bool autoClose, long timestamp, IInterceptor interceptor) { --- 532,601 ---- } ! SessionImpl(SerializationInfo info, StreamingContext context) ! { ! //The graph is not valid until OnDeserialization() has been called. ! siInfo = info; ! } ! ! public void GetObjectData(SerializationInfo info, StreamingContext context) ! { ! if ( IsConnected ) throw new InvalidOperationException("Cannot serialize a Session while connected"); ! if ( insertions.Count!=0 || deletions.Count!=0 ) ! throw new InvalidOperationException("Cannot serialize a Session which has work waiting to be flushed"); ! ! log.Info("serializing session"); ! ! info.AddValue("entries", entries); ! info.AddValue("collections", collections); ! info.AddValue("arrayHolders", arrayHolders); ! } ! ! public void OnDeserialization(Object sender) ! { ! log.Info("deserializing session"); ! entries = (IdentityMap)siInfo.GetValue("entries", typeof(IdentityMap)); ! collections = (IdentityMap)siInfo.GetValue("collections", typeof(IdentityMap)); ! arrayHolders = (IdentityMap)siInfo.GetValue("arrayHolders", typeof(IdentityMap)); ! InitTransientCollections(); ! foreach(DictionaryEntry e in collections) ! { ! try ! { ! ((PersistentCollection)e.Key).SetSession(this); ! CollectionEntry ce = (CollectionEntry)e.Value; ! ce.loadedPersister = factory.GetCollectionPersister(ce.Role); ! } ! catch (HibernateException he) ! { ! // Different from h2.0.3 ! throw new InvalidOperationException(he.Message); ! } ! } ! ! IDictionary newProxiesByKey = new Hashtable(proxiesByKey); ! foreach(object proxy in proxiesByKey) ! { ! if (proxy is HibernateProxy) ! HibernateProxyHelper.GetLazyInitializer(proxy as HibernateProxy).SetSession(this); ! else ! newProxiesByKey.Remove(proxy); ! } ! proxiesByKey = newProxiesByKey; ! newProxiesByKey = null; ! ! foreach(EntityEntry e in entries) ! { ! try ! { ! e.Persister = factory.GetPersister(e.ClassName); ! } ! catch (MappingException me) ! { ! // Different from h2.0.3 ! throw new InvalidOperationException(me.Message); ! } ! } ! } ! internal SessionImpl(IDbConnection connection, SessionFactoryImpl factory, bool autoClose, long timestamp, IInterceptor interceptor) { |