コード例 #1
0
 public override void OnFlushEntity(FlushEntityEvent @event)
 {
     var entity = @event.Entity as IUpdateAwareEntity;
     if (entity != null)
         entity.OnUpdate(); 
     base.OnFlushEntity(@event);
 }
		public void OnFlushEntity(FlushEntityEvent @event)
		{
			var validator = @event.Session.SessionFactory.GetValidator();

			if (validator != null)
			{
				validator.Validate(@event.Entity);
			}
		}
コード例 #3
0
 protected override void DirtyCheck(FlushEntityEvent @event)
 {
     base.DirtyCheck(@event);
     if (@event.DirtyProperties != null &&
         @event.DirtyProperties.Any() &&
         @event.Entity is IAuditableEntity)
     {
         @event.DirtyProperties = @event.DirtyProperties.Concat(GetAdditionalDirtyProperties(@event)).ToArray();
     }
 }
コード例 #4
0
 protected override void DirtyCheck(FlushEntityEvent e)
 {
     base.DirtyCheck(e);
     if (e.DirtyProperties != null &&
         e.DirtyProperties.Any() &&
         //IAuditableEntity is my inteface for audited entities
         e.Entity is IAuditableEntity)
         e.DirtyProperties = e.DirtyProperties
          .Concat(GetAdditionalDirtyProperties(e)).ToArray();
 }
コード例 #5
0
 private static IEnumerable<int> _GetAdditionalDirtyProperties(FlushEntityEvent @event)
 {
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "UpdatedAt");
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "UpdatedBy");
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "CreatedBy");
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "CreatedAt");
 }
        protected override void DirtyCheck(FlushEntityEvent @event)
        {
            base.DirtyCheck(@event);
            if (@event.DirtyProperties == null || [email protected]())
                return;

            var auditableEntity = @event.Entity as IEntityWithAuditing;
            if (auditableEntity == null)
                return;

            @event.DirtyProperties = @event
                .DirtyProperties
                .Concat(GetAdditionalDirtyProperties(@event.EntityEntry.Persister))
                .ToArray();
        }
コード例 #7
0
        private bool HasDirtyProperties(FlushEntityEvent @event)
        {
            var session = @event.Session;
            var entry = @event.EntityEntry;
            var entity = @event.Entity;
            if (!entry.RequiresDirtyCheck(entity) || !entry.ExistsInDatabase || entry.LoadedState == null)
            {
                return false;
            }
            var persister = entry.Persister;

            var currentState = persister.GetPropertyValues(entity, session.EntityMode);
            var loadedState = entry.LoadedState;

            return persister.EntityMetamodel.Properties
                            .Where((property, i) => !LazyPropertyInitializer.UnfetchedProperty.Equals(currentState[i]) && property.Type.IsDirty(loadedState[i], currentState[i], session))
                            .Any();
        }
        public void OnFlushEntity(FlushEntityEvent @event)
        {
            var entity = @event.Entity;
            var entityEntry = @event.EntityEntry;

            if (entityEntry.Status == Status.Deleted)
            {
                return;
            }
            var trackable = entity as ITrackModificationDate;
            if (trackable == null)
            {
                return;
            }
            if (HasDirtyProperties(@event))
            {
                trackable.LastModified = CurrentDateTimeProvider();
            }
        }
コード例 #9
0
        public override void OnFlushEntity(FlushEntityEvent @event)
        {
            EntityEntry entry = @event.EntityEntry;

            // It makes sense to check concurrency access via custom flush entity event listener if entity already exists in the DB
            if (entry.ExistsInDatabase)
            {
                IEventSource session = @event.Session;
                object entity = @event.Entity;
                IEntityPersister persister = entry.Persister;

                if (persister.IsVersioned)
                {
                    object version = persister.GetVersion(entity, session.EntityMode);
                    {
                        if (!persister.VersionType.IsEqual(version, entry.Version))
                        {
                            throw new ConcurrencyException(persister.EntityName, entry.Id);
                        }
                    }
                }
            }
            base.OnFlushEntity(@event);
        }
コード例 #10
0
 public void OnFlushEntity(FlushEntityEvent @event)
 {
     throw new System.NotImplementedException();
 }
コード例 #11
0
        public void OnFlushEntity(FlushEntityEvent @event)
        {
            var entity = @event.Entity;
            var entityEntry = @event.EntityEntry;

            if (entityEntry.Status == Status.Deleted)
            {
                return;
            }
            var audit = entity as Entity;
            if (audit == null)
                return;

            if (HasDirtyProperties(@event))
                audit.ModifiedOn = CurrentDateTimeProvider();
        }
コード例 #12
0
        protected virtual IEnumerable<int> GetAdditionalDirtyProperties(FlushEntityEvent @event)
        {
            yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames, "CreateDate");

            yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames, "EditDate");
        }
コード例 #13
0
 static IEnumerable<int> GetAdditionalDirtyProperties(FlushEntityEvent @event)
 {
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "UpdatedAt");
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "UpdatedBy");
     yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
                                "CreatedBy");
     //You can add any additional properties here.
     //Some of my entities do not track the user, for example.
 }
コード例 #14
0
 public void OnFlushEntity(FlushEntityEvent @event)
 {
     log.Debug("OnFlushEntity :" + @event);
 }
        public void OnFlushEntity(FlushEntityEvent @event)
        {
            if (@event.EntityEntry.Status == Status.Deleted) return;

            SetModificationDateIfPossible(@event.Entity);
        }