public override void Process(RemovalContext context, AssociationInfo association, Entity removingObject, Entity target, Entity referencingObject, Entity referencedObject)
 {
     if (!context.Contains(target) && referencingObject != referencedObject)
     {
         throw new ReferentialIntegrityException(association, removingObject, referencingObject, referencedObject);
     }
 }
 public override void Process(RemovalContext context, AssociationInfo association, Entity removingObject, Entity target, Entity referencingObject, Entity referencedObject)
 {
     switch (association.Multiplicity)
     {
     case Multiplicity.ZeroToMany:
     case Multiplicity.OneToMany:
     case Multiplicity.ManyToMany:
         ReferentialActions.RemoveReference(association, referencingObject, referencedObject, null, context);
         break;
     }
     target.RemoveLaterInternal(EntityRemoveReason.Association);
 }
Exemplo n.º 3
0
        public override void Process(RemovalContext context, AssociationInfo association, Entity removingObject, Entity target, Entity referencingObject, Entity referencedObject)
        {
            switch (association.Multiplicity)
            {
            case Multiplicity.ZeroToOne:
            case Multiplicity.OneToOne:
                ReferentialActions.ClearReference(association, referencingObject, null, null, context);
                break;

            case Multiplicity.ManyToOne:
                ReferentialActions.RemoveReference(association.Reversed, referencedObject, referencingObject, null, context);
                break;

            case Multiplicity.ZeroToMany:
            case Multiplicity.OneToMany:
            case Multiplicity.ManyToMany:
                ReferentialActions.RemoveReference(association, referencingObject, referencedObject, null, context);
                break;
            }
        }
Exemplo n.º 4
0
        public void Remove(IEnumerable <Entity> entities)
        {
            ArgumentValidator.EnsureArgumentNotNull(entities, "entities");
            bool isEmpty = true;

            foreach (var entity in entities)
            {
                isEmpty = false;
                entity.EnsureNotRemoved();
            }
            if (isEmpty)
            {
                return;
            }
            var processedEntities = new List <Entity>();
            var notifiedEntities  = new HashSet <Entity>();

            try {
                var operations = Session.Operations;
                using (var scope = operations.BeginRegistration(OperationType.System))
                    using (Context = new RemovalContext(this)) {
                        Session.EnforceChangeRegistrySizeLimit();
                        if (operations.CanRegisterOperation)
                        {
                            operations.RegisterOperation(
                                new EntitiesRemoveOperation(entities.Select(e => e.Key)));
                        }

                        Context.Enqueue(entities);

                        bool isOperationStarted = false;
                        while (!Context.QueueIsEmpty)
                        {
                            var entitiesForProcessing = Context.GatherEntitiesForProcessing();
                            foreach (var entity in entitiesForProcessing)
                            {
                                entity.SystemBeforeRemove();
                            }
                            if (!isOperationStarted)
                            {
                                isOperationStarted = true;
                                operations.NotifyOperationStarting();
                            }
                            ProcessItems(entitiesForProcessing);
                        }
                        if (!isOperationStarted)
                        {
                            operations.NotifyOperationStarting();
                        }

                        processedEntities = Context.GetProcessedEntities().ToList();
                        foreach (var entity in processedEntities)
                        {
                            entity.SystemRemove();
                            entity.State.PersistenceState = PersistenceState.Removed;
                        }
                        Context.ProcessFinalizers();
                        Session.EnforceChangeRegistrySizeLimit();

                        scope.Complete(); // Successful anyway

                        using (var ea = new ExceptionAggregator()) {
                            foreach (var entity in processedEntities)
                            {
                                ea.Execute(() => {
                                    notifiedEntities.Add(entity);
                                    entity.SystemRemoveCompleted(null);
                                });
                            }
                            ea.Complete();
                        }
                    }
            }
            catch (Exception e) {
                foreach (var entity in processedEntities)
                {
                    if (notifiedEntities.Contains(entity))
                    {
                        continue;
                    }
                    try {
                        entity.SystemRemoveCompleted(e);
                    }
// ReSharper disable EmptyGeneralCatchClause
                    catch {}
// ReSharper restore EmptyGeneralCatchClause
                }
                throw;
            }
        }
        // Constructors

        public RemovalContext(RemovalProcessor processor)
        {
            this.processor = processor;
            parent         = processor.Context;
        }
Exemplo n.º 6
0
 public abstract void Process(RemovalContext context, AssociationInfo association, Entity removingObject, Entity target, Entity referencingObject, Entity referencedObject);
 public override void Process(RemovalContext context, AssociationInfo association, Entity removingObject, Entity target, Entity referencingObject, Entity referencedObject)
 {
 }