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); } }
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(); } }
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(); }
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(); }
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(); } }
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); }
public void OnFlushEntity(FlushEntityEvent @event) { throw new System.NotImplementedException(); }
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(); }
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"); }
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. }
public void OnFlushEntity(FlushEntityEvent @event) { log.Debug("OnFlushEntity :" + @event); }
public void OnFlushEntity(FlushEntityEvent @event) { if (@event.EntityEntry.Status == Status.Deleted) return; SetModificationDateIfPossible(@event.Entity); }