Пример #1
0
        public ObjectStore <OKey, OValue> RebuildObjectStore <OKey, OValue>(ObjectStore <OKey, OValue> currentStore, ObjectStoreParameters newparas)
        {
            string storename = currentStore.Name;
            string newname   = "_koobootemp" + storename;

            if (currentStore == null)
            {
                throw new FileNotFoundException("store does not exists, name: " + Name);
            }

            if (string.IsNullOrEmpty(newparas.PrimaryKey))
            {
                throw new Exception("rebuild index requires setting the primary key field in ObjectStoreParameters.");
            }
            else
            {
                var valuetype = typeof(OValue);
                var fieldtype = valuetype.GetField(newparas.PrimaryKey);
                if (fieldtype == null)
                {
                    var property = valuetype.GetProperty(newparas.PrimaryKey);
                    if (property == null)
                    {
                        throw new Exception("rebuild index requires setting the primary key field in ObjectStoreParameters.");
                    }
                }
            }

            var newstore = this.GetOrCreateObjectStore <OKey, OValue>(newname, newparas);

            lock (_locker)
            {
                foreach (var item in currentStore.ItemCollection())
                {
                    newstore.add(item, false);
                }

                string oldfolder = currentStore.ObjectFolder;
                string newfolder = newstore.ObjectFolder;

                currentStore.Close();
                currentStore.DelSelf();
                newstore.Close();

                this.Log.DeleteByStoreName(storename);

                System.IO.Directory.Move(newfolder, oldfolder);

                if (this.openStoreList.ContainsKey(storename))
                {
                    this.openStoreList.Remove(storename);
                }
            }

            newstore.Close();
            newstore = null;

            if (this.openStoreList.ContainsKey(newname))
            {
                this.openStoreList.Remove(newname);
            }

            return(this.GetObjectStore <OKey, OValue>(storename));
        }
Пример #2
0
 public void Dispose()
 {
     this.store      = null;
     this.enumerator = null;
 }
Пример #3
0
        public ObjectStore <Tkey, TValue> GetOrCreateObjectStore <Tkey, TValue>(string StoreName, ObjectStoreParameters Parameters = null)
        {
            StoreName = StoreName.ToValidPath();

            if (this.HasObjectStore(StoreName))
            {
                return(this.GetObjectStore <Tkey, TValue>(StoreName));
            }
            else
            {
                lock (_locker)
                {
                    if (!HasObjectStore(StoreName))
                    {
                        // Should be removed.
                        #region TempUpgrade2017end

                        var oldsettingfile = objectSettingFile(StoreName);
                        if (System.IO.File.Exists(oldsettingfile))
                        {
                            var oldsetting = SettingSerializer.DeserializeObjectStoreSetting(oldsettingfile);

                            if (oldsetting.UseDefaultNETBinaryFormater)
                            {
                                //clean everything. does not want to upgrade those....
                                var folder = objectFolder(StoreName);
                                System.IO.Directory.Delete(folder, true);
                                return(GetOrCreateObjectStore <Tkey, TValue>(StoreName, Parameters));
                            }

                            int keyoffset = oldsetting.primaryKeyLength;
                            foreach (var item in oldsetting.ColumnList)
                            {
                                if (item.KeyType == typeof(string))
                                {
                                    keyoffset += item.length;
                                }
                                else
                                {
                                    keyoffset += Helper.KeyHelper.GetKeyLen(item.KeyType, item.length);
                                }
                            }

                            var oldfolder = this.objectFolder(StoreName);

                            // primary key.
                            var primaryIndex = new Btree.BtreeIndex <Tkey>(oldsetting.primaryKeyFieldName, true, oldsetting.primaryKeyLength, Helper.IndexHelper.GetIndexFileName(oldfolder, oldsetting.primaryKeyFieldName), oldsetting.MaxCacheLevel);

                            string blockfileName = System.IO.Path.Combine(oldfolder, "Data.block");
                            var    blockfile     = new BlockFile(blockfileName);
                            blockfile.OpenOrCreate();

                            var converter = new Serializer.Simple.SimpleConverter <TValue>();

                            string newname = "_koobootemp" + StoreName;

                            var newfolder = this.objectFolder(newname);

                            var upStore = this.GetOrCreateObjectStore <Tkey, TValue>(newname, Parameters);

                            lock (_locker)
                            {
                                foreach (var item in primaryIndex.allItemCollection(true))
                                {
                                    var bytes  = blockfile.GetContent(item, keyoffset);
                                    var newobj = converter.FromBytes(bytes);
                                    upStore.add(newobj);
                                }

                                blockfile.Close();
                                primaryIndex.Close();
                                upStore.Close();

                                this.DeleteObjectStore(StoreName);

                                if (System.IO.Directory.Exists(oldfolder))
                                {
                                    System.IO.Directory.Delete(oldfolder, true);
                                }

                                System.IO.Directory.Move(newfolder, oldfolder);

                                if (this.openStoreList.ContainsKey(StoreName))
                                {
                                    this.openStoreList.Remove(StoreName);
                                }
                            }

                            return(this.GetOrCreateObjectStore <Tkey, TValue>(StoreName, Parameters));
                        }

                        #endregion

                        clearOpenStoreCache();
                        if (Parameters == null)
                        {
                            Parameters = new ObjectStoreParameters();
                        }

                        ObjectStore <Tkey, TValue> newstore = new ObjectStore <Tkey, TValue>(StoreName, this, Parameters);

                        this.openStoreList.Add(StoreName, newstore);
                    }
                }

                return(this.openStoreList[StoreName] as ObjectStore <Tkey, TValue>);
            }
        }
Пример #4
0
 public Enumerator(ObjectStore <TKey, TValue> store, IEnumerator <long> enumerator)
 {
     this.store      = store;
     this.enumerator = enumerator;
 }