From 4a3fcb78f11e4b1a29bb790e4c9c13e104505cfe Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 10 Apr 2008 15:04:40 +0000 Subject: [PATCH] add code to dump page cache to string git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@321 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/BigIndex.java | 5 +++ .../jackcess/IndexPageCache.java | 33 ++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/java/com/healthmarketscience/jackcess/BigIndex.java b/src/java/com/healthmarketscience/jackcess/BigIndex.java index c4bc60d..20310e6 100755 --- a/src/java/com/healthmarketscience/jackcess/BigIndex.java +++ b/src/java/com/healthmarketscience/jackcess/BigIndex.java @@ -70,5 +70,10 @@ public class BigIndex extends Index { { return _pageCache.getCacheDataPage(pageNumber); } + + @Override + public String toString() { + return super.toString() + "\n" + _pageCache.toString(); + } } diff --git a/src/java/com/healthmarketscience/jackcess/IndexPageCache.java b/src/java/com/healthmarketscience/jackcess/IndexPageCache.java index e7ada2e..e5faa5c 100644 --- a/src/java/com/healthmarketscience/jackcess/IndexPageCache.java +++ b/src/java/com/healthmarketscience/jackcess/IndexPageCache.java @@ -517,8 +517,10 @@ public class IndexPageCache DataPageMain parentMain = origMain.getParentPage(); boolean origWasTail = origMain.isTail(); + boolean newIsTail = (origWasTail || + ((int)origMain._nextPageNumber == INVALID_INDEX_PAGE_NUMBER)); CacheDataPage newDataPage = allocateNewCacheDataPage( - parentMain._pageNumber, origMain._leaf, origWasTail); + parentMain._pageNumber, origMain._leaf, newIsTail); DataPageMain newMain = newDataPage._main; DataPageExtra newExtra = newDataPage._extra; @@ -796,7 +798,36 @@ public class IndexPageCache return prefix; } + + private void dumpPage(StringBuilder rtn, DataPageMain dpMain) { + try { + CacheDataPage cacheDataPage = new CacheDataPage(dpMain); + rtn.append(cacheDataPage).append("\n"); + if(!dpMain._leaf) { + for(Entry e : cacheDataPage._extra._entries) { + DataPageMain childMain = dpMain.getChildPage(e); + dumpPage(rtn, childMain); + } + DataPageMain childTailMain = dpMain.getChildTailPage(); + if(childTailMain != null) { + dumpPage(rtn, childTailMain); + } + } + } catch(IOException e) { + rtn.append("Page[" + dpMain._pageNumber + "]: " + e); + } + } + @Override + public String toString() { + if(_rootPage == null) { + return "Cache: (uninitialized)"; + } + + StringBuilder rtn = new StringBuilder("Cache: \n"); + dumpPage(rtn, _rootPage); + return rtn.toString(); + } private class DataPageMain implements Comparable { -- 2.39.5