summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/changes/changes.xml3
-rw-r--r--src/java/com/healthmarketscience/jackcess/IndexData.java7
-rw-r--r--src/java/com/healthmarketscience/jackcess/Table.java23
-rw-r--r--src/java/com/healthmarketscience/jackcess/UsageMap.java4
4 files changed, 37 insertions, 0 deletions
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 @@
<action dev="jahlborn" type="update">
Enable basic handling of unsupported data types as binary content.
</action>
+ <action dev="jahlborn" type="update">
+ Add methods to approximate table size.
+ </action>
</release>
<release version="1.2.4" date="2011-05-14">
<action dev="jahlborn" type="update">
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 <i>approximate</i> number of database pages owned by this
+ * table and all related indexes (this number does <i>not</i> take into
+ * account pages used for large OLE/MEMO fields).
+ * <p>
+ * To calculate the approximate number of bytes owned by a table:
+ * <code>
+ * int approxTableBytes = (table.getApproximateOwnedPageCount() *
+ * table.getFormat().PAGE_SIZE);
+ * </code>
+ */
+ 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;
}