示例#1
0
        private void WriteDBRoot(DBHdr dbRoot)
        {
            StoragePage rootPage = new StoragePage();

            rootPage.AddRecord(dbRoot);
            rootPage.WritePageData(this.dataFile, RootPage);
        }
示例#2
0
        // writes a page to persistent storage and does book-keeping for allocated and freed pages
        private int aWritePageData(StoragePage page, StorageContext storageContext, int fileAddress)
        {
            lock (ManagerLock)
            {
                // store the index of the current page
                if (0 <= fileAddress)
                {
                    storageContext.FreedPageList.Add(fileAddress);
                }

                // write the page
                fileAddress = page.WritePageData(
                    this.dataFile, this.pageManager.GetFreePage());

                // store the index of the page we just wrote to
                storageContext.AllocatedPageList.Add(fileAddress);

                return(fileAddress);
            }
        }
示例#3
0
        public void SP_TestReadWritePage()
        {
            string dataFile = "SP_TestData1.tpdb";
            if (File.Exists(dataFile))
            {
                File.Delete(dataFile);
            }

            TestData[] pageData =
            {
                new TestData{data = "Record_0", recordIdx = 0},
                new TestData{data = "Record_1", recordIdx = 1},
                new TestData{data = "Record_2", recordIdx = 2}
            };

            int pageIndex = int.MinValue;

            // write the page
            using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile))
            {
                // populate the page with some data
                StoragePage page = new StoragePage();
                AddRecords(page, pageData);

                // write the file to disk
                pageIndex = page.WritePageData(dataFileStream, -1);
            }

            // read the page
            using (FileStreamWrapper dataFileStream = FileStreamWrapper.CreateObject(dataFile))
            {
                // read page from file
                StoragePage page = new StoragePage();
                page.ReadPageData(dataFileStream, pageIndex);

                // validate the page data
                ReadRecords(page, pageData);
            }
        }