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

            rootPage.AddRecord(dbRoot);
            rootPage.WritePageData(this.dataFile, RootPage);
        }
Beispiel #2
0
 private void AddRecords(StoragePage page, TestData[] data)
 {
     foreach (TestData test in data)
     {
         try
         {
             int result = page.AddRecord(test.data);
             Assert.AreEqual(test.recordIdx, result,
                 string.Format("Return value did not match. Test Data=[{0}]", test.ToString()));
         }
         catch (Exception e)
         {
             Assert.AreEqual(test.exception, e.GetType().Name,
                 "Unexpected exception. Test Data = [{0}]", test.ToString());
         }
     }
 }
Beispiel #3
0
        // writes a resource or reservation data item
        protected virtual bool Write <I, R>(Transaction context, StorageContext storageContext, StorageIndex <I> index, I rID, R data)
        {
            // look for the resource in the index
            IndexItem <I> address = index.GetResourceAddress(rID);

            if (null == address &&
                null == data)
            {
                // nothing to do:
                // user probably wanted to delete an non-existing item
                return(true);
            }
            else if (null == address &&
                     null != data)
            {
                address = new IndexItem <I>
                {
                    Page   = storageContext.PageTable.GetLastLogicalPage(),
                    Record = -1
                };
            }

            // Aquire a lock on the logical page address to ensure that we have access to the page
            this.LockPage(context, MyLM.LockMode.Write, address.Page);

            // find the physical page
            int fileAddress = storageContext.PageTable.GetPhysicalPage(address.Page);

            // get the page
            StoragePage page = new StoragePage();

            if (0 <= fileAddress)
            {
                this.aReadPageData(page, fileAddress);
            }

            // write the record
            while (true)
            {
                try
                {
                    if (0 > address.Record)
                    {
                        address.Record = page.AddRecord(data);
                    }
                    else
                    {
                        page.WriteRecord(address.Record, data);
                    }
                }
                catch (StoragePage.InsuffcientSpaceException)
                {
                    // did not fit on last page so allocate a new page
                    page         = new StoragePage();
                    address.Page = -1;
                    fileAddress  = -1;
                    continue;
                }

                break;
            }

            // write the page
            fileAddress = this.aWritePageData(page, storageContext, fileAddress);

            // update the page table
            if (0 > address.Page)
            {
                address.Page = storageContext.PageTable.SetLogicalPage(fileAddress);
            }
            else
            {
                storageContext.PageTable.UpdatePage(address.Page, fileAddress);
            }

            // update the index
            if (null == data)
            {
                // handle deletes
                address = null;
            }
            index.SetResourceAddress(rID, address);

            return(true);
        }