]> source.dussan.org Git - jackcess.git/commitdiff
continuing minor refactoring
authorJames Ahlborn <jtahlborn@yahoo.com>
Tue, 8 Apr 2008 01:34:17 +0000 (01:34 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Tue, 8 Apr 2008 01:34:17 +0000 (01:34 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@318 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/IndexPageCache.java

index 1e94f8650b7bd405d1703a66e32ff159a3d54a4f..d0a0909152b16c7fd4f9586f9f5ed65cdb3f2f6a 100644 (file)
@@ -320,32 +320,12 @@ public class IndexPageCache
     }
 
     // remove this page from it's parent page
-    removeFromParent(cacheDataPage);
+    removeParentEntry(cacheDataPage);
 
     // remove this page from any next/prev pages
     removeFromPeers(cacheDataPage);
   }
 
-  private void removeFromParent(CacheDataPage childDataPage)
-    throws IOException
-  {
-    DataPageMain childMain = childDataPage._main;
-
-    CacheDataPage parentDataPage =
-      new CacheDataPage(childMain.getParentPage());
-
-    setModified(parentDataPage);
-    
-    DataPageMain parentMain = parentDataPage._main;
-
-    if(childMain.isTail()) {
-      parentMain._childTailPageNumber = INVALID_INDEX_PAGE_NUMBER;
-    } else {
-      updateParentEntry(parentDataPage, childDataPage,
-                        childMain._firstEntry, null, UpdateType.REMOVE);
-    }
-  }
-
   private void removeFromPeers(CacheDataPage cacheDataPage)
     throws IOException
   {
@@ -371,18 +351,44 @@ public class IndexPageCache
     throws IOException
   {
     DataPageMain dpMain = cacheDataPage._main;
-    DataPageExtra dpExtra = cacheDataPage._extra;
+    if(!dpMain.isRoot()) {
+      DataPageExtra dpExtra = cacheDataPage._extra;
 
-    Entry oldEntry = dpMain._firstEntry;
-    dpMain._firstEntry = dpExtra.getFirstEntry();
-    DataPageMain parentMain = dpMain.getParentPage();
-    if(parentMain != null) {
-      updateParentEntry(new CacheDataPage(parentMain),
-                        cacheDataPage,
-                        oldEntry, dpMain._firstEntry,
-                        UpdateType.REPLACE);
+      Entry oldEntry = dpMain._firstEntry;
+      dpMain._firstEntry = dpExtra.getFirstEntry();
+      DataPageMain parentMain = dpMain.getParentPage();
+      replaceParentEntry(new CacheDataPage(parentMain),
+                         cacheDataPage,
+                         oldEntry, dpMain._firstEntry);
     }
   }
+
+  private void removeParentEntry(CacheDataPage childDataPage)
+    throws IOException
+  {
+    DataPageMain childMain = childDataPage._main;
+    updateParentEntry(new CacheDataPage(childMain.getParentPage()),
+                      childDataPage, childMain._firstEntry,
+                      null, UpdateType.REMOVE);
+  }
+  
+  private void addParentEntry(CacheDataPage parentDataPage,
+                              CacheDataPage childDataPage,
+                              Entry newEntry)
+    throws IOException
+  {
+    updateParentEntry(parentDataPage, childDataPage, null, newEntry,
+                      UpdateType.ADD);
+  }
+  
+  private void replaceParentEntry(CacheDataPage parentDataPage,
+                                 CacheDataPage childDataPage,
+                                 Entry oldEntry, Entry newEntry)
+    throws IOException
+  {
+    updateParentEntry(parentDataPage, childDataPage, oldEntry, newEntry,
+                      UpdateType.REPLACE);
+  }
   
   private void updateParentEntry(CacheDataPage parentDataPage,
                                  CacheDataPage childDataPage,
@@ -391,8 +397,23 @@ public class IndexPageCache
     throws IOException
   {
     DataPageMain childMain = childDataPage._main;
+    DataPageMain parentMain = parentDataPage._main;
     DataPageExtra parentExtra = parentDataPage._extra;
 
+    if(childMain.isTail()) {
+      int newChildTailPageNumber =
+        ((upType == UpdateType.REMOVE) ?
+         INVALID_INDEX_PAGE_NUMBER :
+         childMain._pageNumber);
+      if((int)parentMain._childTailPageNumber != newChildTailPageNumber) {
+        setModified(parentDataPage);
+        parentMain._childTailPageNumber = newChildTailPageNumber;
+      }
+
+      // nothing more to do
+      return;
+    }
+    
     if(oldEntry != null) {
       oldEntry = oldEntry.asNodeEntry(childMain._pageNumber);
     }