Beispiel #1
0
        /// <summary>
        /// Clear all items of the Collection
        /// </summary>
        public override void Clear()
        {
            if (RootNode == null)
            {
                throw new InvalidOperationException("Can't Clear items of a Close ObjectStore.");
            }

            RemoveDeletedDataBlocks();
            if (HintSequentialRead)
            {
                HintSequentialRead = false;
            }
            if (Count > 0)
            {
                CurrentSequence = 0;
                RootNode.Clear();
                SetCurrentItemAddress(-1, 0);
                if (DataSet != null)
                {
                    DataSet.Clear();
                }
                if (KeySet != null)
                {
                    KeySet.Clear();
                }
                base.Clear();
            }
            PromoteLookup.Clear();
        }
Beispiel #2
0
        /// <summary>
        /// Save the modified nodes/items to disk/virtual store.
        /// </summary>
        public override void Flush()
        {
            #region for removal...

            /*
             * Log.Logger.Instance.Log(Log.LogLevels.Verbose, "BTreeAlgorithm.Flush {0}: Enter.", Name);
             *
             * if (RootNode == null)
             * {
             *  Log.Logger.Instance.Log(Log.LogLevels.Warning, "Flush: RootNode == null detected.");
             *  return;
             * }
             * bool registerChange = false;
             * RemoveDeletedDataBlocks();
             * if (PromoteLookup.Count > 0)
             * {
             *  Log.Logger.Instance.Log(Log.LogLevels.Information, "BTreeAlgorithm.Flush: PromoteLookup(Count={0}), SaveState = {1}, calling SaveNode(PromoteLookup).",
             *      PromoteLookup.Count, SaveState);
             *  SaveNode(PromoteLookup);
             *  registerChange = true;
             *  IsDirty = true;
             * }
             * //if (Blocks.Count > 0)
             * //    registerChange = true;
             * //if (!IsDirty)
             * //{
             * //    if (Blocks.Count > 0)
             * //    {
             * //        Log.Logger.Instance.Log(Log.LogLevels.Information, "Flush: BTreeAlgorithm isn't dirty, Blocks Count = {0} returning.", Blocks.Count);
             * //        SaveBlocks(false);
             * //    }
             * //    return;
             * //}
             * //if (registerChange)
             * RegisterChange();
             *
             * if (DataSet != null && DataSet.DataBlockDriver != null &&
             *  (DataSet.MruManager == null || DataSet.OnDiskBinaryReader == null))
             *  DataSet.Open();
             * if (KeySet.DataBlockDriver != null &&
             *  (KeySet.MruManager == null || KeySet.OnDiskBinaryReader == null))
             *  KeySet.Open();
             * if (RootNode != null && (Count > 0 || RootNode.GetAddress(this) >= 0) &&
             *  (DataSet == null || DataSet.IsOpen) && KeySet.IsOpen)
             * {
             *  SaveState |= SaveTypes.CollectionSave;
             *  OnMaxCapacity(RootNode);
             *  RootNode.IsDirty = false;
             *  SaveState ^= SaveTypes.CollectionSave;
             * }
             * //bool reSave = false;
             * base.Flush();
             *
             * if (PromoteLookup.Count > 0)
             * {
             *  SaveNode(PromoteLookup);
             * }
             *
             * if (DataSet != null && DataSet.IsOpen)
             * {
             *  if (DataSet.MruManager != null && DataSet.OnDiskBinaryReader != null)
             *  {
             *      //reSave = DataSet.DataAddress == -1;
             *      bool hdsame = DataSet.HeaderData == HeaderData;
             *      if (hdsame)
             *          DataSet.HeaderData = null;
             *      DataSet.Flush();
             *      if (hdsame)
             *          DataSet.HeaderData = HeaderData;
             *  }
             * }
             * if (KeySet.IsOpen)
             * {
             *  if (KeySet.MruManager != null && KeySet.OnDiskBinaryReader != null)
             *  {
             *      //if (!reSave)
             *      //    reSave = KeySet.DataAddress == -1;
             *      bool hdsame = KeySet.HeaderData == HeaderData;
             *      if (hdsame)
             *          KeySet.HeaderData = null;
             *      KeySet.Flush();
             *      if (hdsame)
             *          KeySet.HeaderData = HeaderData;
             *  }
             * }
             * //if (!reSave)
             * //{
             * //    Log.Logger.Instance.Log(Log.LogLevels.Information, "Flush: reSave is false, Blocks Count = {0} base.Flush will be skipped.", Blocks.Count);
             * //    if (Blocks.Count > 0) SaveBlocks(false);
             * //    return;
             * //}
             * IsDirty = true;
             * base.Flush();
             *
             * Log.Logger.Instance.Log(Log.LogLevels.Verbose, "BTreeAlgorithm.Flush {0}: Exit.", Name);
             */
            #endregion

            Log.Logger.Instance.Log(Log.LogLevels.Verbose, "BTreeAlgorithm.Flush {0}: Enter.", Name);

            if (RootNode == null)
            {
                Log.Logger.Instance.Log(Log.LogLevels.Warning, "Flush: RootNode == null detected.");
                return;
            }
            RemoveDeletedDataBlocks();
            if (PromoteLookup.Count > 0)
            {
                Log.Logger.Instance.Log(Log.LogLevels.Information, "BTreeAlgorithm.Flush: PromoteLookup(Count={0}), SaveState = {1}, calling SaveNode(PromoteLookup).",
                                        PromoteLookup.Count, SaveState);
                SaveNode(PromoteLookup);
                PromoteLookup.Clear();
            }
            if (!IsDirty)
            {
                if (Blocks.Count > 0)
                {
                    Log.Logger.Instance.Log(Log.LogLevels.Information, "Flush: BTreeAlgorithm isn't dirty, Blocks Count = {0} returning.", Blocks.Count);
                    SaveBlocks(false);
                }
                return;
            }

            if (DataSet != null && DataSet.DataBlockDriver != null &&
                (DataSet.MruManager == null || DataSet.OnDiskBinaryReader == null))
            {
                DataSet.Open();
            }
            if (KeySet.DataBlockDriver != null &&
                (KeySet.MruManager == null || KeySet.OnDiskBinaryReader == null))
            {
                KeySet.Open();
            }
            if (RootNode != null && (Count > 0 || RootNode.GetAddress(this) >= 0) &&
                (DataSet == null || DataSet.IsOpen) && KeySet.IsOpen)
            {
                SaveState |= SaveTypes.CollectionSave;
                OnMaxCapacity(RootNode);
                RootNode.IsDirty = false;
                SaveState       ^= SaveTypes.CollectionSave;
            }
            bool reSave = false;
            base.Flush();

            if (PromoteLookup.Count > 0)
            {
                SaveNode(PromoteLookup);
                PromoteLookup.Clear();
            }

            if (DataSet != null && DataSet.IsOpen)
            {
                if (DataSet.MruManager != null && DataSet.OnDiskBinaryReader != null)
                {
                    reSave = DataSet.DataAddress == -1;
                    bool hdsame = DataSet.HeaderData == HeaderData;
                    if (hdsame)
                    {
                        DataSet.HeaderData = null;
                    }
                    DataSet.Flush();
                    if (hdsame)
                    {
                        DataSet.HeaderData = HeaderData;
                    }
                }
            }
            if (KeySet.IsOpen)
            {
                if (KeySet.MruManager != null && KeySet.OnDiskBinaryReader != null)
                {
                    if (!reSave)
                    {
                        reSave = KeySet.DataAddress == -1;
                    }
                    bool hdsame = KeySet.HeaderData == HeaderData;
                    if (hdsame)
                    {
                        KeySet.HeaderData = null;
                    }
                    KeySet.Flush();
                    if (hdsame)
                    {
                        KeySet.HeaderData = HeaderData;
                    }
                }
            }
            if (!reSave)
            {
                Log.Logger.Instance.Log(Log.LogLevels.Information, "Flush: reSave is false, Blocks Count = {0} base.Flush will be skipped.", Blocks.Count);
                if (Blocks.Count > 0)
                {
                    SaveBlocks(false);
                }
                return;
            }
            IsDirty = true;
            base.Flush();

            Log.Logger.Instance.Log(Log.LogLevels.Verbose, "BTreeAlgorithm.Flush {0}: Exit.", Name);
        }