/// <summary> /// Performs the update. /// </summary> /// <param name="evt">The event.</param> /// <param name="entity">The entity.</param> /// <param name="persister">The persister.</param> protected override void PerformUpdate(SaveOrUpdateEvent evt, object entity, NHibernate.Persister.Entity.IEntityPersister persister) { if (evt.Session.IsDirtyEntity(entity)) { eventListenerHelper.OnModify(entity); } base.PerformUpdate(evt, entity, persister); }
public void OnSaveOrUpdate(NHibernate.Event.SaveOrUpdateEvent e) { NHibernate.Persister.Entity.IEntityPersister p = e.Session.GetEntityPersister(null, e.Entity); if (p.IsVersioned) { object version = p.GetVersion(e.Entity, e.Session.EntityMode); object currversion = p.GetCurrentVersion(e.Entity, e.Session); if (version.Equals(currversion)) throw new StaleObjectStateException(e.EntityName, e.Entry.Id); } }
/// <summary> /// Prepares the save call by checking the session caches for a pre-existing /// entity and performing any lifecycle callbacks. /// </summary> /// <param name="entity">The entity to be saved.</param> /// <param name="id">The id by which to save the entity.</param> /// <param name="persister">The entity's persister instance.</param> /// <param name="useIdentityColumn">Is an identity column being used?</param> /// <param name="anything">Generally cascade-specific information.</param> /// <param name="source">The session from which the event originated.</param> /// <param name="requiresImmediateIdAccess">does the event context require /// access to the identifier immediately after execution of this method (if /// not, post-insert style id generators may be postponed if we are outside /// a transaction).</param> /// <returns> /// The id used to save the entity; may be null depending on the /// type of id generator used and the requiresImmediateIdAccess value /// </returns> protected override object PerformSave(object entity, object id, NHibernate.Persister.Entity.IEntityPersister persister, bool useIdentityColumn, object anything, IEventSource source, bool requiresImmediateIdAccess) { if (entity is IEntity) { Events.CoreEvents.Instance.OnEntitySaving((IEntity)entity); } eventListenerHelper.OnCreate(entity); return(base.PerformSave(entity, id, persister, useIdentityColumn, anything, source, requiresImmediateIdAccess)); }
public void OnSaveOrUpdate(NHibernate.Event.SaveOrUpdateEvent e) { NHibernate.Persister.Entity.IEntityPersister p = e.Session.GetEntityPersister(null, e.Entity); if (p.IsVersioned) { //TODO: check types etc... DateTime oldversion = (DateTime) p.GetVersion(e.Entity, e.Session.EntityMode); DateTime currversion = (DateTime) p.GetCurrentVersion(e.Entity, e.Session); if (oldversion < currversion.AddMinutes(-30)) throw new StaleObjectStateException(e.EntityName, e.Entry.Id); } }
/// <summary> /// Performs the update. /// </summary> /// <param name="evt">The event.</param> /// <param name="entity">The entity.</param> /// <param name="persister">The entity's persister.</param> protected override void PerformUpdate(SaveOrUpdateEvent evt, object entity, NHibernate.Persister.Entity.IEntityPersister persister) { if (entity is IEntity) { Events.CoreEvents.Instance.OnEntitySaving((IEntity)entity, evt.Session); } if (evt.Session.IsDirtyEntity(entity)) { eventListenerHelper.OnModify(entity); } base.PerformUpdate(evt, entity, persister); }
protected override void DeleteEntity(IEventSource session, object entity, EntityEntry entityEntry, bool isCascadeDeleteEnabled, NHibernate.Persister.Entity.IEntityPersister persister, Iesi.Collections.ISet transientEntities) { var entityBase = entity as EntityBase; if (entityBase != null) { entityBase.IsDeleted = true; } }
private static FieldChange CreateChange(object valueNew, object valueOld, NHibernate.Persister.Entity.IEntityPersister persister, int i) { if (valueOld == null && valueNew == null) { return(null); } NHibernate.Type.IType propType = persister.PropertyTypes[i]; string propName = persister.PropertyNames[i]; var propInfo = persister.MappedClass.GetProperty(propName); if (propInfo.GetCustomAttributes(typeof(IgnoreHistoryTraceAttribute), true).Length > 0) { return(null); } FieldChange change = null; #region Обработка в зависимости от типа данных if (propType is NHibernate.Type.StringType && !StringCompare(ref change, (string)valueOld, (string)valueNew)) { return(null); } var link = propType as NHibernate.Type.ManyToOneType; if (link != null) { if (!EntityCompare(ref change, valueOld, valueNew)) { return(null); } } if ((propType is NHibernate.Type.DateTimeType || propType is NHibernate.Type.TimestampType) && !DateTimeCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.DecimalType && !DecimalCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.BooleanType && !BooleanCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.Int16Type && !IntCompare <Int16>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.Int32Type && !IntCompare <Int32>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.Int64Type && !IntCompare <Int64>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.UInt16Type && !IntCompare <UInt16>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.UInt32Type && !IntCompare <UInt32>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.UInt64Type && !IntCompare <UInt64>(ref change, propInfo, valueOld, valueNew)) { return(null); } if (propType is NHibernate.Type.EnumStringType && !EnumCompare(ref change, propInfo, valueOld, valueNew)) { return(null); } #endregion if (change != null) { change.Path = propName; change.UpdateType(); return(change); } logger.Warn("Трекер не умеет сравнивать изменения в полях типа {0}. Поле {1} пропущено.", propType, propName); return(null); }