Ejemplo n.º 1
0
 internal NdxPage InternalGetPage(NdxPage parentPage, UInt32 recordNo, bool returnNullIfNotInCache)
 {
     NdxPage record = (NdxPage)base.InternalGetRecord(recordNo, returnNullIfNotInCache);
     if (record != null)
     {
         record.ParentPage = parentPage;
     }
     return record;
 }
Ejemplo n.º 2
0
        internal void Dump(string indent, NdxPage parentPage, NdxEntry parentEntry,  bool withChildren, ref NdxEntry lastLeaf)
        {
            var ndxFile = (NdxFile)mHolder.mFile;

            System.Diagnostics.Debug.WriteLine(indent
                + "Page #" + mHolder.RecordNo
                +" " + this.EntriesCount + " entries (parent: " + (ParentPage == null ? "none" : "#" + ParentPage.RecordNo)+")");
            System.Diagnostics.Debug.Assert(parentPage == ParentPage, "Invalid NDX Parent page");
            for (int i = 0; i < EntriesCount; i++)
            {
                var e = GetEntry(i);

                System.Diagnostics.Debug.WriteLine(
                    indent + "   "
                    + "Entry " + i + " (page #" + mHolder.RecordNo + ") - "
                    + " SubPage: " + (e.LowerPageRecordNo == UInt32.MaxValue ? "none" : "#" + e.LowerPageRecordNo)
                    + ", Key: " + e.Fields.ToString()
                    + " #" + e.DbfRecordNo
                    );
                if (e.mNdxNativeLowerPageNo != 0)
                {
                    NdxPage subPage = (NdxPage)ndxFile.InternalGetPage(this, (uint)e.LowerPageRecordNo,
                        /*returnNullIfNotInCache*/ false);
                    if (withChildren)
                    {
                        subPage.Dump(indent + "    ", this, e, true, ref lastLeaf);
                    }
                }
                else
                {

            #if DEBUG
                    if (lastLeaf != null)
                    {
                        int[] cmpArray = new int[ndxFile.mSortFieldsCount];
                        int cmp = e.ChainCompare(cmpArray, ndxFile, lastLeaf);
                        if (cmp <= 0) System.Diagnostics.Trace.WriteLine("*** ERRROR HERE THE ORDER IS MESSED UP ***");
                    }
                    lastLeaf = e;
            #endif
                }
            }
        }
Ejemplo n.º 3
0
        private void SplitPage()
        {
            #if DUMP_INSERTS
            System.Diagnostics.Trace.WriteLine("Split page #" + this.RecordNo);
            #endif
            var ndxFile = (NdxFile)mHolder.mFile;
            // split needed (on save)
            int mid = EntriesCount / 2;
            if (ParentPage == null)
            {
                ParentPage = (NdxPage)ndxFile.NewPage(null);

                var rootEntry = new NdxEntry();
                var lastEntry = GetEntry(EntriesCount - 1);
                rootEntry.DbfRecordNo = lastEntry.DbfRecordNo;
                rootEntry.Fields = lastEntry.Fields.Clone();
                rootEntry.LowerPageRecordNo = this.RecordNo;

                ParentPage.EntriesClear();
                ParentPage.EntriesInsert(0,rootEntry);
                ndxFile.mNdxHeader.StartingPageRecordNo = ParentPage.RecordNo;

                //ParentPage.mNbChildEntries = mNbChildEntries;
                ParentPage.mIsModified = true;
            #if DUMP_INSERTS
                System.Diagnostics.Trace.WriteLine("  Create new parent page #" + mParentPage.RecordNo);
                mParentPage.Dump("      ");
            #endif
            }

            var newPage = (NdxPage)ndxFile.NewPage(ParentPage);
            newPage.EntriesClear();
            newPage.mIsModified = true;
            newPage.ParentPage = ParentPage;

            for (int i = 0; i < mid; i++)
            {
                //mNbChildEntries = mNbChildEntries;
                newPage.EntriesInsert(i, GetEntry(i));
                var lowerPageRecordNo = GetEntry(i).LowerPageRecordNo;
                if (lowerPageRecordNo != UInt32.MaxValue)
                {
                    var ndxPage2 = ndxFile.InternalGetPage(
                        ParentPage,
                        lowerPageRecordNo,
                        /* returnNullIfNotInCache */ true) as NdxPage;
                    if (ndxPage2 != null)
                    {
                        ndxPage2.ParentPage = newPage;
                    }
                }
            }
            EntriesRemoveRange(0, mid);

            var midEntry = newPage.GetEntry(mid - 1);
            var newMidEntry = new NdxEntry() {
                DbfRecordNo = midEntry.DbfRecordNo,
                LowerPageRecordNo = newPage.RecordNo,
                Fields = midEntry.Fields.Clone() };

            #if DUMP_INSERTS
            System.Diagnostics.Trace.WriteLine("  newPage #" + newPage.RecordNo);
            newPage.Dump("      ");

            System.Diagnostics.Trace.WriteLine("  this page #" + RecordNo);
            Dump("      ");
            #endif
            int midEntryPos = ParentPage.FindInsertPos(newMidEntry, ndxFile);
            ParentPage.InsertInThisPage(newMidEntry, midEntryPos);
        }
Ejemplo n.º 4
0
 public NdxPage NewPage(NdxPage parentPage)
 {
     NdxPage record = (NdxPage)base.NewRecord();
     record.ParentPage = parentPage;
     return record;
 }