diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2008-04-08 01:34:17 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2008-04-08 01:34:17 +0000 |
commit | 2c480d7a1b9bedf6476162481f1ad64c2e03974b (patch) | |
tree | 5dccb6f4d64da69bdb13574c75b10db26e59e245 /src/java/com/healthmarketscience/jackcess/IndexPageCache.java | |
parent | 4bf77267a5871e0da49c07e7e750e9207a9daddd (diff) | |
download | jackcess-2c480d7a1b9bedf6476162481f1ad64c2e03974b.tar.gz jackcess-2c480d7a1b9bedf6476162481f1ad64c2e03974b.zip |
continuing minor refactoring
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@318 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/IndexPageCache.java')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/IndexPageCache.java | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/IndexPageCache.java b/src/java/com/healthmarketscience/jackcess/IndexPageCache.java index 1e94f86..d0a0909 100644 --- a/src/java/com/healthmarketscience/jackcess/IndexPageCache.java +++ b/src/java/com/healthmarketscience/jackcess/IndexPageCache.java @@ -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); } |