Пример #1
0
 public ObjectStore(string name, Database ownerdatabase, ObjectStoreParameters parameters)
 {
     this.Name             = name;
     this.ObjectFolder     = ownerdatabase.objectFolder(name);
     this.StoreSettingFile = ownerdatabase.StoreSetitingFile(name);
     this.OwnerDatabase    = ownerdatabase;
     this.StoreSetting     = Helper.SettingHelper.GetOrSetSetting <TValue, TKey>(this.StoreSettingFile, parameters);
     Init();
 }
Пример #2
0
 public ObjectStorePool(Database Database, string StoreName, ObjectStoreParameters Parameters)
 {
     this.database  = Database;
     this.storeName = StoreName;
     if (parameters != null)
     {
         this.parameters = Parameters;
     }
     else
     {
         this.parameters = new ObjectStoreParameters();
     }
 }
Пример #3
0
        /// <summary>
        /// Get an new instance of the ObjectStore.
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="name"></param>
        /// <returns></returns>
        public ObjectStore <TKey, TValue> GetReadingStore <TKey, TValue>(string name, ObjectStoreParameters paras = null)
        {
            string storename = name.ToValidPath();

            if (paras == null)
            {
                paras = new ObjectStoreParameters();
            }
            if (!HasObjectStore(storename))
            {
                throw new Exception("store: " + name + " does not exists");
            }
            return(new ObjectStore <TKey, TValue>(storename, this, paras));
        }
Пример #4
0
        private static ObjectStore <long, LogEntry> GetLog(Database db)
        {
            string storename = GlobalSettings.EditLogUniqueName;

            ObjectStoreParameters paras = new ObjectStoreParameters();

            paras.EnableLog     = false;
            paras.EnableVersion = false;
            paras.AddIndex <LogEntry>(o => o.KeyHash);
            paras.AddColumn <LogEntry>(o => o.StoreNameHash);
            paras.AddColumn <LogEntry>(o => o.TimeTick);
            paras.SetPrimaryKeyField <LogEntry>(o => o.Id);
            return(db.GetOrCreateObjectStore <Int64, LogEntry>(storename, paras));
        }
Пример #5
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));
        }
Пример #6
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>);
            }
        }
Пример #7
0
        public bool CheckSameSetting(ObjectStoreParameters ParametersToCheck)
        {
            var parasetting = Helper.SettingHelper.GetSetting <TValue>(ParametersToCheck);

            return(Helper.SettingHelper.IsSameSetting(this.StoreSetting, parasetting));
        }