Пример #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);
            }
        }
Пример #2
0
        protected virtual void UpdateStillDirty(object forObj, int exceptionLimit)
        {
            this.Context.LogManager.Debug(this, "Updating still dirty objects", "");             // do not localize

            try
            {
                long      cnt;
                bool      noCheck       = false;
                ArrayList updateObjects = new ArrayList();
                IList     stillDirty;
                cnt = m_hashStillDirty.Count;
                IObjectManager     om = this.Context.ObjectManager;
                IPersistenceEngine pe = this.Context.PersistenceEngine;
                while (cnt > 0)
                {
                    try
                    {
                        updateObjects.Clear();
                        foreach (object obj in m_hashStillDirty.Keys)
                        {
                            try
                            {
                                if (forObj != null)
                                {
                                    if (obj == forObj)
                                    {
                                        updateObjects.Add(obj);
                                    }
                                }
                                else
                                {
                                    if (noCheck || MayUpdate(obj))
                                    {
                                        updateObjects.Add(obj);
                                        noCheck = false;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                                {
                                    throw ex;
                                }
                                exceptions.Add(ex);
                            }
                        }
                        foreach (object obj in updateObjects)
                        {
                            try
                            {
                                stillDirty = (IList)m_hashStillDirty[obj];
                                m_hashStillDirty.Remove(obj);
                                pe.UpdateObject(obj, stillDirty);
                                this.Context.LogManager.Debug(this, "Updated still dirty object", "Type: " + obj.GetType().ToString() + " Still dirty: " + stillDirty.Count.ToString());                                  // do not localize
                                if (stillDirty.Count > 0)
                                {
                                    IList cloneList = new ArrayList();
                                    foreach (object clone in stillDirty)
                                    {
                                        cloneList.Add(clone);
                                    }
                                    m_hashStillDirty[obj] = cloneList;
                                }
                            }
                            catch (Exception ex)
                            {
                                if (exceptionLimit > 0 && exceptions.Count >= exceptionLimit - 1)
                                {
                                    throw ex;
                                }
                                exceptions.Add(ex);
                            }
                        }
                        if (m_hashStillDirty.Count == cnt)
                        {
                            noCheck = true;
                        }
                        if (forObj != null)
                        {
                            cnt = 0;
                        }
                        else
                        {
                            cnt = m_hashStillDirty.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);
            }
        }