From: Michael D. <mik...@us...> - 2004-11-29 15:31:19
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6702/NHibernate/Impl Modified Files: ScheduledCollectionAction.cs ScheduledCollectionRecreate.cs ScheduledCollectionRemove.cs ScheduledCollectionUpdate.cs ScheduledEntityAction.cs SessionImpl.cs Log Message: Added more comments for scheduling of collection actions. Index: SessionImpl.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/SessionImpl.cs,v retrieving revision 1.50 retrieving revision 1.51 diff -C2 -d -r1.50 -r1.51 *** SessionImpl.cs 29 Nov 2004 04:45:51 -0000 1.50 --- SessionImpl.cs 29 Nov 2004 15:31:07 -0000 1.51 *************** *** 97,116 **** /// this session. These statuses are for internal /// book-keeping only and are not intended to represent ! /// any notion that is visible to the _application_. /// </summary> [Serializable] internal enum Status { Loaded, Deleted, Gone, Loading, Saving } internal interface IExecutable { void Execute(); void AfterTransactionCompletion(); object[] PropertySpaces { get; } } --- 97,159 ---- /// this session. These statuses are for internal /// book-keeping only and are not intended to represent ! /// any notion that is visible to the <b>application</b>. /// </summary> [Serializable] internal enum Status { + /// <summary> + /// The Entity is snapshotted in the Session with the same state as the database. + /// </summary> Loaded, + + /// <summary> + /// The Entity is in the Session and has been marked for deletion but not + /// deleted from the database yet. + /// </summary> Deleted, + + /// <summary> + /// The Entity has been deleted from database. + /// </summary> Gone, + + /// <summary> + /// The Entity is in the process of being loaded. + /// </summary> Loading, + + /// <summary> + /// The Entity is in the process of being saved. + /// </summary> Saving } + /// <summary> + /// An action that <see cref="ISession"/> can Execute during a + /// <c>Flush</c>. + /// </summary> internal interface IExecutable { + /// <summary> + /// Execute the action required to write changes to the database. + /// </summary> void Execute(); + + /// <summary> + /// Called after the Transaction has been completed. + /// </summary> + /// <remarks> + /// Actions should make sure that the Cache is notified about + /// what just happened. + /// </remarks> void AfterTransactionCompletion(); + + /// <summary> + /// The spaces (tables) that are affectd by this Executable action. + /// </summary> + /// <remarks> + /// This is used to determine if the ISession needs to be flushed before + /// a query is executed so stale data is not returned. + /// </remarks> object[] PropertySpaces { get; } } *************** *** 267,275 **** --- 310,360 ---- { internal bool dirty; + + /// <summary> + /// Indicates that the Collection can still be reached by an Entity + /// that exist in the <see cref="ISession"/>. + /// </summary> + /// <remarks> + /// It is also used to ensure that the Collection is not shared between + /// two Entities. + /// </remarks> [NonSerialized] internal bool reached; + + /// <summary> + /// Indicates that the Collection has been processed and is ready + /// to have its state synchronized with the database. + /// </summary> [NonSerialized] internal bool processed; + + /// <summary> + /// Indicates that a Collection needs to be updated. + /// </summary> + /// <remarks> + /// A Collection needs to be updated whenever the contents of the Collection + /// have been changed. + /// </remarks> [NonSerialized] internal bool doupdate; + + /// <summary> + /// Indicates that a Collection has old elements that need to be removed. + /// </summary> + /// <remarks> + /// A Collection needs to have removals performed whenever its role changes or + /// the key changes and it has a loadedPersister - ie - it was loaded by NHibernate. + /// </remarks> [NonSerialized] internal bool doremove; + + /// <summary> + /// Indicates that a Collection needs to be recreated. + /// </summary> + /// <remarks> + /// A Collection needs to be recreated whenever its role changes + /// or the owner changes. + /// </remarks> [NonSerialized] internal bool dorecreate; + + /// <summary> + /// Indicates that the Collection has been fully initialized. + /// </summary> internal bool initialized; Index: ScheduledCollectionAction.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledCollectionAction.cs,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ScheduledCollectionAction.cs 28 Nov 2004 03:13:44 -0000 1.6 --- ScheduledCollectionAction.cs 29 Nov 2004 15:31:07 -0000 1.7 *************** *** 6,10 **** namespace NHibernate.Impl { ! internal abstract class ScheduledCollectionAction : SessionImpl.IExecutable { --- 6,13 ---- namespace NHibernate.Impl { ! /// <summary> ! /// The base class for a scheduled action to perform on a Collection during a ! /// flush. ! /// </summary> internal abstract class ScheduledCollectionAction : SessionImpl.IExecutable { *************** *** 13,16 **** --- 16,25 ---- private ISessionImplementor _session; + /// <summary> + /// Initializes a new instance of <see cref="ScheduledCollectionAction"/>. + /// </summary> + /// <param name="persister">The <see cref="CollectionPersister"/> that is responsible for the persisting the Collection.</param> + /// <param name="id">The identifier of the Collection owner.</param> + /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> public ScheduledCollectionAction(CollectionPersister persister, object id, ISessionImplementor session) { *************** *** 20,33 **** } ! public void AfterTransactionCompletion() ! { ! _persister.ReleaseSoftlock( _id ); ! } ! ! public object[] PropertySpaces ! { ! get { return new string[] { _persister.QualifiedTableName }; } //TODO: cache the array on the persister ! } ! public CollectionPersister Persister { --- 29,35 ---- } ! /// <summary> ! /// Gets the <see cref="CollectionPersister"/> that is responsible for persisting the Collection. ! /// </summary> public CollectionPersister Persister { *************** *** 35,38 **** --- 37,43 ---- } + /// <summary> + /// Gets the identifier of the Collection owner. + /// </summary> public object Id { *************** *** 40,43 **** --- 45,51 ---- } + /// <summary> + /// Gets the <see cref="ISessionImplementor"/> the action is executing in. + /// </summary> public ISessionImplementor Session { *************** *** 45,49 **** --- 53,72 ---- } + #region SessionImpl.IExecutable Members + + public void AfterTransactionCompletion() + { + _persister.ReleaseSoftlock( _id ); + } + public abstract void Execute(); + + public object[] PropertySpaces + { + get { return new string[] { _persister.QualifiedTableName }; } //TODO: cache the array on the persister + } + + #endregion + } } Index: ScheduledEntityAction.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledEntityAction.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ScheduledEntityAction.cs 28 Nov 2004 21:47:46 -0000 1.5 --- ScheduledEntityAction.cs 29 Nov 2004 15:31:07 -0000 1.6 *************** *** 34,42 **** - public object[] PropertySpaces - { - get { return _persister.PropertySpaces; } - } - /// <summary> /// Gets the <see cref="ISessionImplementor"/> the action is executing in. --- 34,37 ---- *************** *** 70,74 **** --- 65,72 ---- get { return _instance; } } + + #region SessionImpl.IExecutable Members + /// <summary> /// Called when the Transaction this action occurred in has completed. *************** *** 81,84 **** --- 79,89 ---- public abstract void Execute(); + public object[] PropertySpaces + { + get { return _persister.PropertySpaces; } + } + + #endregion + } } Index: ScheduledCollectionRecreate.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledCollectionRecreate.cs,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ScheduledCollectionRecreate.cs 28 Nov 2004 03:13:44 -0000 1.3 --- ScheduledCollectionRecreate.cs 29 Nov 2004 15:31:07 -0000 1.4 *************** *** 5,14 **** namespace NHibernate.Impl { ! internal sealed class ScheduledCollectionRecreate : ScheduledCollectionAction { private PersistentCollection _collection; ! public ScheduledCollectionRecreate(PersistentCollection collection, CollectionPersister persister, object id, ISessionImplementor session) : base(persister, id, session) { _collection = collection; --- 5,24 ---- namespace NHibernate.Impl { ! /// <summary> ! /// A scheduled recreation of the Collection in the database. ! /// </summary> internal sealed class ScheduledCollectionRecreate : ScheduledCollectionAction { private PersistentCollection _collection; ! /// <summary> ! /// Initializes a new instance of <see cref="ScheduledCollectionRecreate"/>. ! /// </summary> ! /// <param name="collection">The <see cref="PersistentCollection"/> to recreate.</param> ! /// <param name="persister">The <see cref="CollectionPersister"/> that is responsible for the persisting the Collection.</param> ! /// <param name="id">The identifier of the Collection owner.</param> ! /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionRecreate(PersistentCollection collection, CollectionPersister persister, object id, ISessionImplementor session) ! : base(persister, id, session) { _collection = collection; Index: ScheduledCollectionUpdate.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledCollectionUpdate.cs,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ScheduledCollectionUpdate.cs 28 Nov 2004 03:13:44 -0000 1.5 --- ScheduledCollectionUpdate.cs 29 Nov 2004 15:31:07 -0000 1.6 *************** *** 5,16 **** namespace NHibernate.Impl { ! internal sealed class ScheduledCollectionUpdate : ScheduledCollectionAction { - private readonly PersistentCollection _collection; private readonly bool _emptySnapshot; ! public ScheduledCollectionUpdate(PersistentCollection collection, CollectionPersister persister, object id, bool emptySnapshot, ISessionImplementor session) : base(persister, id, session) { _collection = collection; --- 5,30 ---- namespace NHibernate.Impl { ! /// <summary> ! /// A scheduled update of the Collection in the database. ! /// </summary> ! /// <remarks> ! /// Entities in the Collection or the contents of the Collection have been modified ! /// and the database should be updated accordingly. ! /// </remarks> internal sealed class ScheduledCollectionUpdate : ScheduledCollectionAction { private readonly PersistentCollection _collection; private readonly bool _emptySnapshot; ! /// <summary> ! /// Initializes a new instance of <see cref="ScheduledCollectionUpdate"/>. ! /// </summary> ! /// <param name="collection">The <see cref="PersistentCollection"/> to update.</param> ! /// <param name="persister">The <see cref="CollectionPersister"/> that is responsible for the persisting the Collection.</param> ! /// <param name="id">The identifier of the Collection owner.</param> ! /// <param name="emptySnapshot">Indicates if the Collection was empty when it was loaded.</param> ! /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionUpdate(PersistentCollection collection, CollectionPersister persister, object id, bool emptySnapshot, ISessionImplementor session) ! : base(persister, id, session) { _collection = collection; *************** *** 23,44 **** if( !_collection.WasInitialized ) { ! if ( !_collection.HasQueuedAdds ) throw new AssertionFailure("bug processing queued adds"); ! //do nothing - we only need to notify the cache... } else if( _collection.Empty ) { ! if( !_emptySnapshot ) Persister.Remove( Id, Session ); } else if( _collection.NeedsRecreate( Persister ) ) { ! if( !_emptySnapshot ) Persister.Remove( Id, Session ); Persister.Recreate( _collection, Id, Session ); } else { Persister.DeleteRows( _collection, Id, Session ); Persister.UpdateRows( _collection, Id, Session ); Persister.InsertRows( _collection, Id, Session ); - } --- 37,77 ---- if( !_collection.WasInitialized ) { ! if ( !_collection.HasQueuedAdds ) ! { ! throw new AssertionFailure("bug processing queued adds"); ! } ! ! // do nothing - collection was not initialized ! // we only need to notify the cache... } else if( _collection.Empty ) { ! // the collection had all elements removed - check to see if it ! // was empty when it was loaded or if the contents were actually ! // deleted ! if( !_emptySnapshot ) ! { ! Persister.Remove( Id, Session ); ! } } else if( _collection.NeedsRecreate( Persister ) ) { ! // certain collections (Bag) have to be recreated in the db each ! // time - if the snapshot was not empty then there are some existing ! // rows that need to be removed. ! if( !_emptySnapshot ) ! { ! Persister.Remove( Id, Session ); ! } ! Persister.Recreate( _collection, Id, Session ); } else { + // this is a normal collection that needs to have its state + // synched with the database. Persister.DeleteRows( _collection, Id, Session ); Persister.UpdateRows( _collection, Id, Session ); Persister.InsertRows( _collection, Id, Session ); } Index: ScheduledCollectionRemove.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Impl/ScheduledCollectionRemove.cs,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ScheduledCollectionRemove.cs 28 Nov 2004 03:13:44 -0000 1.4 --- ScheduledCollectionRemove.cs 29 Nov 2004 15:31:07 -0000 1.5 *************** *** 3,14 **** using NHibernate.Engine; ! namespace NHibernate.Impl { ! internal sealed class ScheduledCollectionRemove : ScheduledCollectionAction { - private bool _emptySnapshot; ! public ScheduledCollectionRemove(CollectionPersister persister, object id, bool emptySnapshot, ISessionImplementor session) : base(persister, id, session) { _emptySnapshot = emptySnapshot; --- 3,27 ---- using NHibernate.Engine; ! namespace NHibernate.Impl ! { ! /// <summary> ! /// A scheduled removal of the Collection from the database. ! /// </summary> ! /// <remarks> ! /// This Collection is not represented in the database anymore. ! /// </remarks> internal sealed class ScheduledCollectionRemove : ScheduledCollectionAction { private bool _emptySnapshot; ! /// <summary> ! /// Initializes a new instance of <see cref="ScheduledCollectionRemove"/>. ! /// </summary> ! /// <param name="persister">The <see cref="CollectionPersister"/> that is responsible for the persisting the Collection.</param> ! /// <param name="id">The identifier of the Collection owner.</param> ! /// <param name="emptySnapshot">Indicates if the Collection was empty when it was loaded.</param> ! /// <param name="session">The <see cref="ISessionImplementor"/> that the Action is occuring in.</param> ! public ScheduledCollectionRemove(CollectionPersister persister, object id, bool emptySnapshot, ISessionImplementor session) ! : base(persister, id, session) { _emptySnapshot = emptySnapshot; *************** *** 18,22 **** { Persister.Softlock( Id ); ! if( !_emptySnapshot ) Persister.Remove( Id, Session ); } } --- 31,41 ---- { Persister.Softlock( Id ); ! ! // if there were no entries in the snapshot of the collection then there ! // is nothing to remove so verify that the snapshot was not empty. ! if( !_emptySnapshot ) ! { ! Persister.Remove( Id, Session ); ! } } } |