Ejemplo n.º 1
0
        protected virtual void RemoveDeleted(object forObj, int exceptionLimit)
        {
            this.Context.LogManager.Debug(this, "Removing objects that are up for deletion", "");             // do not localize

            try
            {
                long      cnt;
                long      staleCnt      = 0;
                bool      tryForce      = false;
                ArrayList removeObjects = new ArrayList();
                cnt = m_listDeleted.Count;
                IObjectManager     om = this.Context.ObjectManager;
                IPersistenceEngine pe = this.Context.PersistenceEngine;
                while (cnt > 0)
                {
                    try
                    {
                        removeObjects.Clear();
                        foreach (object obj in m_listDeleted)
                        {
                            try
                            {
                                if (forObj != null)
                                {
                                    if (obj == forObj)
                                    {
                                        removeObjects.Add(obj);
                                    }
                                }
                                else
                                {
                                    if (tryForce)
                                    {
                                        if (MayForceDelete(obj))
                                        {
                                            //Force an update all the referencing objects, which should have had their
                                            //references to our object set to null in advance during the delete operation.
                                            //This way all the references to our object should be set to null in the database.
                                            TopologicalNode node = (TopologicalNode)m_topologicalDelete.Graph[obj];
                                            if (node != null)
                                            {
                                                foreach (TopologicalNode waitForNode in node.WaitFor)
                                                {
                                                    IList dummyStillDirty = new ArrayList();
                                                    pe.UpdateObject(waitForNode.Obj, dummyStillDirty);
                                                    AddSpeciallyUpdated(waitForNode.Obj);
                                                }
                                            }
                                            tryForce = false;
                                            removeObjects.Add(obj);
                                        }
                                    }
                                    else
                                    {
                                        if (MayRemove(obj))
                                        {
                                            removeObjects.Add(obj);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                                {
                                    throw ex;
                                }
                                exceptions.Add(ex);
                            }
                        }
                        foreach (object obj in removeObjects)
                        {
                            try
                            {
                                m_listDeleted.Remove(obj);
                                m_listRemoved.Add(obj);
                                m_topologicalDelete.RemoveNode(obj);
                                pe.RemoveObject(obj);
                                this.Context.LogManager.Debug(this, "Removed object", "");                                  // do not localize
                            }
                            catch (Exception ex)
                            {
                                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                                {
                                    throw ex;
                                }
                                exceptions.Add(ex);
                            }
                        }
                        if (m_listDeleted.Count == cnt)
                        {
                            if (staleCnt > 0)
                            {
                                throw new UnitOfWorkException("The objects that are up for deletion in the unit of work are arranged in an unresolvable graph!");
                            }
                            else
                            {
                                tryForce = true;
                                staleCnt++;
                            }
                        }
                        else
                        {
                            staleCnt = 0;
                        }
                        if (forObj != null)
                        {
                            cnt = 0;
                        }
                        else
                        {
                            cnt = m_listDeleted.Count;
                        }
                    }
                    catch (Exception ex)
                    {
                        if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                        {
                            throw ex;
                        }
                        exceptions.Add(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                {
                    throw ex;
                }
                exceptions.Add(ex);
            }
        }