/// <summary> /// Handles PreDelete event to delete an entity's associated security data. /// </summary> /// <param name="deleteEvent">Event object containing the delete operation information.</param> /// <returns>False, indicating the delete operation should not be vetoed.</returns> public bool OnPreDelete(PreDeleteEvent deleteEvent) { Guid securityKey = Security.ExtractKey(deleteEvent.Entity); if (!Guid.Empty.Equals(securityKey)) { var entityReference = deleteEvent.Session.CreateCriteria<EntityReference>() .Add(Restrictions.Eq("EntitySecurityKey", securityKey)) .SetCacheable(true) .UniqueResult<EntityReference>(); if (entityReference != null) { ISession childSession = deleteEvent.Session.GetSession(EntityMode.Poco); // because default flush mode is auto, a read after a scheduled delete will invoke // the auto-flush behaviour, causing a constraint violation exception in the // underlying database, because there still are EntityGroup entities that need // the deleted EntityReference/SecurityKey. childSession.FlushMode = FlushMode.Commit; childSession.Delete(entityReference); //Also remove EntityReferencesToEntitiesGroups and Permissions that reference this entity //Get list of EntitiesGroups that have the entity as a member IEnumerable<EntitiesGroup> entitiesGroups = childSession.CreateCriteria<EntitiesGroup>() .CreateCriteria("Entities") .Add(Restrictions.Eq("EntitySecurityKey", securityKey)) .SetCacheable(true) .List<EntitiesGroup>(); foreach (EntitiesGroup group in entitiesGroups) { group.Entities.Remove(entityReference); } ////Get list of Permissions that references the entity IEnumerable<Permission> permissions = childSession.CreateCriteria<Permission>() .Add(Restrictions.Eq("EntitySecurityKey", securityKey)) .SetCacheable(true) .List<Permission>(); foreach (Permission permission in permissions) { childSession.Delete(permission); } childSession.Flush(); } } return false; }
public bool OnPreDelete(PreDeleteEvent @event) { var seatArrangement = default(SeatArrangement); if (@event.TryCatchEntity(ref seatArrangement)) { //seatArrangement.Cancel(null); //_occupationRepository.DeleteSeatArrangements(seatArrangement..Id); } return false; }
public bool OnPreDelete(PreDeleteEvent @event) { Debug.WriteLine(string.Format("OnPreDelete - {0}", @event.Entity)); if (@event.Entity is IDataObject) { // the function returns true if the operation should be vetoed // consider returning false instead of throwing ServiceDataAuthorizationConnector.Check((IDataObject)@event.Entity, DataOperation.Delete); } return false; }
/// <summary> /// Handles PreDelete event to delete an entity's associated security data. /// </summary> /// <param name="deleteEvent">Event object containing the delete operation information.</param> /// <returns>False, indicating the delete operation should not be vetoed.</returns> public bool OnPreDelete(PreDeleteEvent deleteEvent) { var securityKey = Security.ExtractKey(deleteEvent.Entity); if (!Guid.Empty.Equals(securityKey)) { EntityReference entityReference = deleteEvent.Session.CreateCriteria<EntityReference>() .Add(Restrictions.Eq("EntitySecurityKey", securityKey)) .SetCacheable(true) .UniqueResult<EntityReference>(); if (entityReference != null) { var childSession = deleteEvent.Session.GetSession(NHibernate.EntityMode.Poco); childSession.Delete(entityReference); //Also remove EntityReferencesToEntitiesGroups and Permissions that reference this entity //Get list of EntitiesGroups that have the entity as a member IEnumerable<EntitiesGroup> entitiesGroups = childSession.CreateCriteria<EntitiesGroup>() .CreateCriteria("Entities") .Add(Restrictions.Eq("EntitySecurityKey", securityKey)) .SetCacheable(true) .List<EntitiesGroup>(); foreach (EntitiesGroup group in entitiesGroups) { group.Entities.Remove(entityReference); } ////Get list of Permissions that references the entity IEnumerable<Permission> permissions = childSession.CreateCriteria<Permission>() .Add(Restrictions.Eq("EntitySecurityKey", securityKey)) .SetCacheable(true) .List<Permission>(); foreach (Permission permission in permissions) { childSession.Delete(permission); } childSession.Flush(); } } return false; }
public bool OnPreDelete(PreDeleteEvent preDeleteEvent) { var softDeletable = preDeleteEvent.Entity as ISoftDeletable; if (softDeletable != null) { // TODO: process all subproperties and delete them if softdeletable? // should be normal subproperties deleted? var session = preDeleteEvent.Session.GetSession(EntityMode.Poco); softDeletable.IsDeleted = true; session.Update(softDeletable); session.Flush(); return true; } return false; }
public bool OnPreDelete(PreDeleteEvent @event) { if (IsEnabled) { var entity = default(Term); if (@event.TryCatchEntity(ref entity)) { if (DeleteSession == null) DeleteSession = @event.Persister.Factory.GetCurrentSession(); var employeeId = entity.GetSnapshotValue<Guid>("EmployeeId"); var key = string.Format("{0}{1}", employeeId, entity.Start.Date); if (!SqlCaches.ContainsKey(key)) { var sql = string.Format("delete BackupTerm where BackupTerm.EmployeeId ='{0}' and datediff(d,starttime,'{1:yyyy/MM/dd HH:mm}')=0", employeeId, entity.Start.Date); SqlCaches[key] = sql; DeleteSession.CreateSQLQuery(sql).ExecuteUpdate(); } } } return false; }
private bool PreDelete() { IPreDeleteEventListener[] preListeners = Session.Listeners.PreDeleteEventListeners; bool veto = false; if (preListeners.Length > 0) { var preEvent = new PreDeleteEvent(Instance, Id, state, Persister, (IEventSource)Session); foreach (IPreDeleteEventListener listener in preListeners) { veto |= listener.OnPreDelete(preEvent); } } return veto; }
/// <summary> /// /// </summary> /// <param name="evt"></param> /// <returns></returns> public bool OnPreDelete(PreDeleteEvent evt) { return false; }
public bool OnPreDelete(PreDeleteEvent e) { var entity = (EntityBase) e.Entity; PopulateAuditFields(e.DeletedState, e.Persister.PropertyNames, entity); return false; }
public bool OnPreDelete(PreDeleteEvent @event) { Debug.WriteLine("EventListener.OnPreDelete: {0}", @event.Id); return false; }
public bool OnPreDelete(PreDeleteEvent @event) { Logger.Delete(@event.Entity as IStateEntity); return false; }
public bool OnPreDelete(PreDeleteEvent e) { _logger.Delete(e.Entity as Entity); return false; }
public bool OnPreDelete(PreDeleteEvent @event) { log.Debug("OnPreDelete :" + @event); return false; }
/// <summary> /// Return true if the operation should be vetoed /// </summary> /// <param name="event"/> public bool OnPreDelete(PreDeleteEvent @event) { try { AggregateDataInterceptor.OnDeleteCheckAggregate(@event.Entity, @event.Session); return false; } catch(Exception ex) { throw new InvalidOperationException("Error trying to flush aggregates during pre-delete phase: {0}".InvariantFormat(GetUsefulEntityName(@event.Entity, null, null)), ex); } }