You are doing something very wrong here, you have an individual connection,
transaction and insert PER UPDATED ROW.
That is going to be really slow

On Wed, Nov 26, 2008 at 2:00 PM, tvbusy <[EMAIL PROTECTED]> wrote:

>
> I have Permission provider for permissions management and Repository
> for entities persistent as two separate modules.
> I want that whenever a new entity that implements ISecurityEntity is
> inserted to database, default permissions are also added for that new
> entity.
>
> By using event listener, I could this with convenient:
>
> var listerners = cfg.EventListeners;
> listerners.PostUpdateEventListeners = new[] { _listener };
> listerners.PostInsertEventListeners = new IPostInsertEventListener[]
> {_listener};
> listerners.PostDeleteEventListeners = new IPostDeleteEventListener[]
> {_listener};
>
> And code for EventListener:
>
> using System;
> using NHibernate.Event;
>
> namespace xxx
> {
>    internal class EventListener : IPostInsertEventListener,
> IPostUpdateEventListener, IPostDeleteEventListener
>    {
>        private readonly ISecurityProvider _security;
>
>        public EventListener(ISecurityProvider security)
>        {
>            if (security == null) throw new ArgumentNullException
> ("security");
>            _security = security;
>        }
>
>        /// <summary>
>        /// Grants the default permissions.
>        /// </summary>
>        /// <param name="secureEntity">The secure entity.</param>
>        public virtual void GrantDefaultPermissions(ISecurityEntity
> secureEntity)
>        {
>            if (secureEntity != null && secureEntity.SecurityEntity ==
> null)
>            {
>                _security.GrantUserEntity(secureEntity.SecurityID,
> EntityAccess.All);
>                _security.GrantGroupEntity(DefaultGroups.Everyone,
> secureEntity.SecurityID, EntityAccess.Read);
>            }
>        }
>
>        /// <summary>
>        /// </summary>
>        /// <param name="event"></param>
>        public void OnPostDelete(PostDeleteEvent @event)
>        {
>            var auditable = @event.Entity as IAuditable;
>            if (auditable != null)
>            {
>                BeginInvoke(() =>
>                {
>                    var entry = new AuditEntry
>                    {
>                        AffectedEntityID = auditable.ID,
>                        EntityType = auditable.GetType(),
>                        Category = AuditCategories.Deleted,
>                        Message = string.Format
> (Properties.Resources.MsgDelete)
>                    };
>
>                    using (var session =
> @event.Persister.Factory.OpenStatelessSession())
>                        session.Insert(entry);
>                });
>            }
>
>            var notifyDeleted = @event.Entity as Entity;
>            if (notifyDeleted != null)
>                notifyDeleted.NotifyDeleted();
>        }
>
>        /// <summary>
>        ///  Return true if the operation should be vetoed
>        /// </summary>
>        /// <param name="event"></param>
>        public void OnPostInsert(PostInsertEvent @event)
>        {
>            var auditable = @event.Entity as IAuditable;
>            if (auditable != null)
>            {
>                BeginInvoke(() =>
>                {
>                    var entry = new AuditEntry
>                    {
>                        AffectedEntityID = auditable.ID,
>                        EntityType = auditable.GetType(),
>                        Category = AuditCategories.Created,
>                        Message = string.Format
> (Properties.Resources.MsgCreated)
>                    };
>
>                    using (var session =
> @event.Persister.Factory.OpenStatelessSession())
>                        session.Insert(entry);
>                });
>            }
>
>            BeginInvoke(() => GrantDefaultPermissions(@event.Entity as
> ISecurityEntity));
>        }
>
>        /// <summary>
>        ///  Return true if the operation should be vetoed
>        /// </summary>
>        /// <param name="event"></param>
>        public void OnPostUpdate(PostUpdateEvent @event)
>        {
>            var auditable = @event.Entity as IAuditable;
>            if (auditable != null)
>            {
>                BeginInvoke(() =>
>                {
>                    var entry = new AuditEntry
>                    {
>                        AffectedEntityID = auditable.ID,
>                        EntityType = auditable.GetType(),
>                        Category = AuditCategories.Modified,
>                        Message = string.Format
> (Properties.Resources.MsgModify)
>                    };
>
>                    using (var session =
> @event.Persister.Factory.OpenStatelessSession())
>                        session.Insert(entry);
>                });
>            }
>        }
>
>        protected virtual void BeginInvoke(Action action)
>        {
>            action.BeginInvoke(null, null);
>        }
>    }
> }
>
> The problem that I have is the event listener sometimes causes the
> main session to hang at Flush, or at transaction commit (which calls
> session's Flush).
>
> I've tried with both Firebird and SQL Server 2005 Express, and it
> seems the problem is not from the database.
> PS: My application perform inserting of large data by opening a
> session, insert about 10MB and then close the session to avoid caching
> of data, and then open another session.
>
> Number of entities that implements ISecurityEntity is about 20 over
> 350 entities per session (for 10MB as above).
>
> PSS: 10MB is an approximate of data load, not an exact number.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to