Example #1
0
        /// <summary>
        /// Gets the configuration metadata list.
        /// </summary>
        /// <typeparam name="T">The type of metadata.</typeparam>
        /// <param name="conditions">The conditions dictionary.</param>
        /// <returns></returns>
        public List <T> GetConfigMetadataList <T>(Dictionary <string, object> conditions) where T : ConfigMetadata, new()
        {
            DB.AutoBox db = GetDB <T>();

            if (db != null)
            {
                Type   type      = typeof(T);
                string tableName = type.Name;
                string sql       = "from " + tableName + " where";

                int i      = 0;
                int length = conditions.Keys.Count;

                foreach (string key in conditions.Keys)
                {
                    sql += " " + key + "==?";

                    if (i < length - 1)
                    {
                        sql += " &";
                    }

                    i++;
                }

                List <object>    values = new List <object>(conditions.Values);
                IBEnumerable <T> items  = db.Select <T>(sql, values.ToArray());
                return(new List <T>(items));
            }

            return(null);
        }
Example #2
0
        /// <summary>
        /// Gets the database.
        /// </summary>
        /// <typeparam name="T">The type of metadata. </typeparam>
        /// <returns>The database object. </returns>
        private DB.AutoBox GetDB <T>() where T : ConfigMetadata, new()
        {
            Type   type      = typeof(T);
            string tableName = type.Name;

            DB.AutoBox db = null;

            if (m_metadataDBMap.ContainsKey(type))
            {
                db = m_metadataDBMap[type];
            }
            else
            {
                long localAddress = GetTableLocalAddress <T>();

                if (localAddress != -1)
                {
                    DB     server     = new DB(localAddress);
                    string primaryKey = GetPrimaryKey();

                    if (!string.IsNullOrEmpty(primaryKey))
                    {
                        server.GetConfig().EnsureTable <T>(tableName, primaryKey);
                        db = server.Open();
                        m_metadataDBMap.Add(type, db);
                    }
                    else
                    {
                        Debug.LogError("Table primary key can not be null or empty !");
                    }
                }
            }

            return(db);
        }
Example #3
0
        static public void InitDB()
        {
            string path = string.Empty;

            if (db != null)
            {
                return;
            }
            DB.Root(path);
            server = new DB(1);
            server.GetConfig().EnsureTable <Province>("Province", "ID");
            //server.GetConfig().EnsureTable<Country>("Country", "ID");
            server.GetConfig().EnsureTable <Item>("Item", "ID");

            db = server.Open();

            //using (var box = db.Cube())
            //{
            //    foreach(var it in box.Select<Province>("from Province where 1==1")){
            //        box.Bind("Province", it.ID).Delete();
            //    }

            //    box.Commit();

            //}
        }
Example #4
0
        public iBoxDBBackedTest()
        {
            var server = new DB();

            server.GetConfig().EnsureTable <Author>(DBTableNames.Authors, "Id");
            _db = server.Open();
        }
Example #5
0
 /// <summary>
 /// Opens this database.
 /// </summary>
 public void Open()
 {
     if (m_server != null)
     {
         m_db = m_server.Open();
     }
 }
Example #6
0
        public static void init(String path, bool isVM)
        {
            Console.WriteLine("DBPath=" + path);

            DB.Root(path);

            DB server = new DB(1);

            if (isVM)
            {
                server.GetConfig().DBConfig.CacheLength
                    = server.GetConfig().DBConfig.MB(16);
            }
            else
            {
                server.GetConfig().DBConfig.CacheLength
                    = server.GetConfig().DBConfig.MB(512);
            }
            server.GetConfig().DBConfig.SwapFileBuffer
                = (int)server.GetConfig().DBConfig.MB(4);
            server.GetConfig().DBConfig.FileIncSize
                = (int)server.GetConfig().DBConfig.MB(16);
            new Engine().Config(server.GetConfig().DBConfig);
            server.GetConfig().EnsureTable <Page> ("Page", "id");
            server.GetConfig().EnsureIndex <Page> ("Page", true, "url(" + Page.MAX_URL_LENGTH + ")");

            search_db = server.Open();
        }
Example #7
0
 public static void close()
 {
     if (search_db != null)
     {
         search_db.GetDatabase().Close();
     }
     search_db = null;
     Console.WriteLine("DBClosed");
 }
Example #8
0
        /// <summary>
        /// Disposes all databases.
        /// </summary>
        public void DisposeAllDB()
        {
            if (m_tableIndexDB != null)
            {
                m_tableIndexDB.GetDatabase().Dispose();
                m_tableIndexDB = null;
            }

            DisposeAllMetadataDB();
        }
Example #9
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        public void Dispose()
        {
            Close();

            if (m_server != null)
            {
                m_server.Dispose();
            }

            m_server = null;
            m_db     = null;
        }
Example #10
0
        /// <summary>
        /// Opens the database.
        /// </summary>
        /// <exception cref="ObjectDisposedException">database</exception>
        public void Open()
        {
            CheckIfDisposed();

            if (Database == null)
            {
                return;
            }

            Box    = Database.Open();
            IsOpen = true;
        }
Example #11
0
        /// <summary>
        /// Disposes the metadata database.
        /// </summary>
        /// <typeparam name="T">The type of metadata database.</typeparam>
        public void DisposeMetadataDB <T>()
        {
            Type type = typeof(T);

            DB.AutoBox db = m_metadataDBMap[type];

            if (db != null)
            {
                db.GetDatabase().Dispose();
                m_metadataDBMap.Remove(type);
                db = null;
            }
        }
Example #12
0
        /// <summary>
        /// Destroys the database.
        /// </summary>
        private static void DestroyDatabase()
        {
            if (s_tableIndexDB != null)
            {
                s_tableIndexDB = null;
            }

            if (s_tableIndexServer != null)
            {
                s_tableIndexServer.Dispose();
                s_tableIndexServer = null;
            }
        }
Example #13
0
        /// <summary>
        /// Gets the configuration metadata.
        /// </summary>
        /// <typeparam name="T">The type of metadata. </typeparam>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public T GetConfigMetadata <T>(long id) where T : ConfigMetadata, new()
        {
            DB.AutoBox db = GetDB <T>();

            if (db != null)
            {
                Type   type      = typeof(T);
                string tableName = type.Name;
                T      item      = db.SelectKey <T>(tableName, id);
                return(item);
            }

            return(null);
        }
Example #14
0
        /// <summary>
        /// Disposes all metadata databases.
        /// </summary>
        public void DisposeAllMetadataDB()
        {
            foreach (KeyValuePair <Type, DB.AutoBox> kvp in m_metadataDBMap)
            {
                DB.AutoBox db = kvp.Value;

                if (db != null)
                {
                    db.GetDatabase().Dispose();
                }
            }

            m_metadataDBMap.Clear();
        }
Example #15
0
        /// <summary>
        /// Creates the table index database.
        /// </summary>
        private void CreateTableIndexDB()
        {
            if (m_tableIndexDB == null)
            {
                DB server = new DB(ConfigMetadata.IndexTableLocalAddress);
                DatabaseConfig.Config serverConfig = server.GetConfig();

                if (serverConfig != null)
                {
                    serverConfig.EnsureTable <MetadataLocalAddress>(MetadataLocalAddress.TableName, MetadataLocalAddress.PrimaryKey);
                    serverConfig.EnsureTable <ConfigParameter>(ConfigParameter.TableName, ConfigParameter.PrimaryKey);
                }

                m_tableIndexDB = server.Open();
            }
        }
Example #16
0
 public DefaultServiceManager(ICache cache, ILogService logService,
                              IEncryptionProvider encryptionProvider,
                              IDiaryService diaryService,
                              IDiaryCommentService diaryCommentService,
                              IMovieCommentService movieCommentService,
                              IAccountService accountService)
 {
     this._cache               = cache;
     this._autoBox             = null;
     this._logService          = logService;
     this._encryptionProvider  = encryptionProvider;
     this._diaryService        = diaryService;
     this._diaryCommentService = diaryCommentService;
     this._movieCommentService = movieCommentService;
     this._accountService      = accountService;
 }
Example #17
0
        /// <summary>
        /// Releases unmanaged and - optionally - managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                Box?.Dispose();
                Box = null;

                Database?.Dispose();
                Database = null;

                IsOpen = false;
            }

            disposed = true;
        }
Example #18
0
        public static void init(String path)
        {
            Console.WriteLine("DBPath=" + path);

            DB.Root(path);

            DB server = new DB(1);

            /*
             * server.GetConfig().DBConfig.CacheLength
             * = server.GetConfig().DBConfig.MB(8);
             */
            server.GetConfig().DBConfig.SwapFileBuffer
                = (int)server.GetConfig().DBConfig.MB(2);
            new Engine().Config(server.GetConfig().DBConfig);
            server.GetConfig().EnsureTable <Page> ("Page", "id");
            server.GetConfig().EnsureIndex <Page> ("Page", true, "url(100)");

            search_db = server.Open();
        }
        private void BtnConnect_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(this.tbFilePath.Text))
            {
                System.Windows.MessageBox.Show("Please select iBoxDB file", "Warning");
                return;
            }
            if (db == null)
            {
                server = new DB(this.tbFilePath.Text);
                db     = server.Open();
            }
            var tables = db.GetDatabase().GetSchemata().Keys;

            foreach (string table in tables)
            {
                if (!table.StartsWith("__"))
                {
                    this.cbTable.Items.Add(table);
                }
            }
        }
Example #20
0
 public EditPostCommandInvoker(DB.AutoBox db)
 {
     _db = db;
 }
Example #21
0
 public ChangePasswordCommandInvoker(DB.AutoBox db)
 {
     _db = db;
 }
Example #22
0
 public iBoxDBBackedTest()
 {
     var server = new DB();
     server.GetConfig().EnsureTable<Author>(DBTableNames.Authors, "Id");
     _db = server.Open();
 }
Example #23
0
 public AllBlogPostViewProjection(DB.AutoBox db)
 {
     _db = db;
 }
Example #24
0
 public DeleteCommentCommandInvoker(DB.AutoBox db)
 {
     _db = db;
 }
Example #25
0
 public SpamShieldService(DB.AutoBox db)
 {
     _db = db;
 }
Example #26
0
        public static void init(String path)
        {
            Console.WriteLine ("DBPath=" + path);

            DB.Root (path);

            DB server = new DB (1);
            /*
            server.GetConfig().DBConfig.CacheLength
                = server.GetConfig().DBConfig.MB(8);
             */
            server.GetConfig ().DBConfig.SwapFileBuffer
                = (int)server.GetConfig ().DBConfig.MB (2);
            new Engine ().Config (server.GetConfig ().DBConfig);
            server.GetConfig ().EnsureTable<Page> ("Page", "id");
            server.GetConfig ().EnsureIndex<Page> ("Page", true, "url(100)");

            search_db = server.Open ();
        }
Example #27
0
 public static void close()
 {
     if (search_db != null) {
         search_db.GetDatabase ().Close ();
     }
     search_db = null;
     Console.WriteLine ("DBClosed");
 }
Example #28
0
 public BlogCommentsViewProjection(DB.AutoBox db)
 {
     _db = db;
 }
Example #29
0
 public ChangeProfileCommandInvoker(DB.AutoBox db)
 {
     _db = db;
 }
Example #30
0
 public BlogPostEditViewProjection(DB.AutoBox db)
 {
     _db = db;
 }
Example #31
0
 public TaggedBlogPostsViewProjection(DB.AutoBox db)
 {
     _db = db;
 }
Example #32
0
 public AuthorProfileViewProjection(DB.AutoBox db)
 {
     _db = db;
 }
Example #33
0
		public static void init (String path, bool isVM)
		{

			Console.WriteLine ("DBPath=" + path);

			DB.Root (path);
		 
			DB server = new DB (1);
			if (isVM) {
				server.GetConfig ().DBConfig.CacheLength
                = server.GetConfig ().DBConfig.MB (16);
			} else {
				server.GetConfig ().DBConfig.CacheLength
					= server.GetConfig ().DBConfig.MB (512);
			}
			server.GetConfig ().DBConfig.SwapFileBuffer
				= (int)server.GetConfig ().DBConfig.MB (4);
			server.GetConfig ().DBConfig.FileIncSize
				= (int)server.GetConfig ().DBConfig.MB (16);
			new Engine ().Config (server.GetConfig ().DBConfig);
			server.GetConfig ().EnsureTable<Page> ("Page", "id");
			server.GetConfig ().EnsureIndex<Page> ("Page", true, "url(" + Page.MAX_URL_LENGTH + ")");

			search_db = server.Open ();

		}
Example #34
0
        public static bool Test(bool background)
        {
            var bakAddr = 0 - Math.Abs(DateTime.Now.Ticks);

            DDebug.DeleteDBFiles(1);
            DB server = new DB(1);

            server.SetBoxRecycler(new FileBackupBoxRecycler());
            server.GetConfig().EnsureTable <DBObject>("DBObject", "ID");
            DB.AutoBox auto = server.Open();

            Parallel.For(0, 300, (i) =>
            {
                var obj   = new DBObject();
                obj.ID    = auto.NewId(0);
                obj.Value = "Value " + obj.ID;
                obj.DT    = DateTime.Now;
                auto.Insert("DBObject", obj);
            });


            // Export
            if (background)
            {
                Thread backupThread = new Thread(() =>
                {
                    ((FileBackupBoxRecycler)auto.GetDatabase().GetBoxRecycler()).Phase1(auto.GetDatabase(), bakAddr);
                });
                backupThread.Start();

                Parallel.For(0, 300, (i) =>
                {
                    var obj   = new DBObject();
                    obj.ID    = auto.NewId(0);
                    obj.Value = "Value " + obj.ID;
                    obj.DT    = DateTime.Now;
                    auto.Insert("DBObject", obj);
                });

                backupThread.Join();
                ((FileBackupBoxRecycler)auto.GetDatabase().GetBoxRecycler()).Phase2();
            }
            else
            {
                ((FileBackupBoxRecycler)auto.GetDatabase().GetBoxRecycler()).Backup(auto.GetDatabase(), bakAddr);
            }


            //Import
            DB bakserver = new DB(bakAddr);

            bakserver.GetConfig().DBConfig.SwapFileBuffer = 0;
            DB.AutoBox bakauto = bakserver.Open();

            DBObject[] s1 = auto.Select <DBObject>("from DBObject").ToArray();
            DBObject[] s2 = bakauto.Select <DBObject>("from DBObject").ToArray();

            server.Dispose();
            bakserver.Dispose();
            DDebug.DeleteDBFiles(bakAddr);
            return(s1.SequenceEqual(s2));
        }
Example #35
0
 public SpamShieldService(DB.AutoBox db)
 {
     _db = db;
 }