From 599d2da23e2d88632133ab178ad3e23cdc204753 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sat, 16 Jul 2011 02:39:50 +0000 Subject: [PATCH] add some methods to approximate table size git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@569 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 3 +++ .../jackcess/IndexData.java | 7 ++++++ .../healthmarketscience/jackcess/Table.java | 23 +++++++++++++++++++ .../jackcess/UsageMap.java | 4 ++++ 4 files changed, 37 insertions(+) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 3f86887..564cee4 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -15,6 +15,9 @@ Enable basic handling of unsupported data types as binary content. + + Add methods to approximate table size. + diff --git a/src/java/com/healthmarketscience/jackcess/IndexData.java b/src/java/com/healthmarketscience/jackcess/IndexData.java index 93f4ad5..11b7b0a 100644 --- a/src/java/com/healthmarketscience/jackcess/IndexData.java +++ b/src/java/com/healthmarketscience/jackcess/IndexData.java @@ -330,6 +330,13 @@ public abstract class IndexData { return _maxPageEntrySize; } + /** + * Returns the number of database pages owned by this index data. + */ + public int getOwnedPageCount() { + return _ownedPages.getPageCount(); + } + void addOwnedPage(int pageNumber) throws IOException { _ownedPages.addPageNumber(pageNumber); } diff --git a/src/java/com/healthmarketscience/jackcess/Table.java b/src/java/com/healthmarketscience/jackcess/Table.java index 34b3c27..b007753 100644 --- a/src/java/com/healthmarketscience/jackcess/Table.java +++ b/src/java/com/healthmarketscience/jackcess/Table.java @@ -289,6 +289,29 @@ public class Table protected UsageMap.PageCursor getOwnedPagesCursor() { return _ownedPages.cursor(); } + + /** + * Returns the approximate number of database pages owned by this + * table and all related indexes (this number does not take into + * account pages used for large OLE/MEMO fields). + *

+ * To calculate the approximate number of bytes owned by a table: + * + * int approxTableBytes = (table.getApproximateOwnedPageCount() * + * table.getFormat().PAGE_SIZE); + * + */ + public int getApproximateOwnedPageCount() { + // add a page for the table def (although that might actually be more than + // one page) + int count = _ownedPages.getPageCount() + 1; + // note, we count owned pages from _physical_ indexes, not logical indexes + // (otherwise we could double count pages) + for(IndexData indexData : _indexDatas) { + count += indexData.getOwnedPageCount(); + } + return count; + } protected TempPageHolder getLongValueBuffer() { return _longValueBufferH; diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java index d60141e..931891e 100644 --- a/src/java/com/healthmarketscience/jackcess/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java @@ -150,6 +150,10 @@ public class UsageMap return new PageCursor(); } + public int getPageCount() { + return _pageNumbers.cardinality(); + } + protected short getRowStart() { return _rowStart; } -- 2.39.5