diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2008-04-07 01:37:25 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2008-04-07 01:37:25 +0000 |
commit | d52cf53037e13c7a40a8e284d9e6690826a7936b (patch) | |
tree | 7254e91dcd7ee98b5f14a4cdfbb55d915f98b2de | |
parent | 095e6cc5493ee363840fd54d20eb0e3977e1ba9d (diff) | |
download | jackcess-d52cf53037e13c7a40a8e284d9e6690826a7936b.tar.gz jackcess-d52cf53037e13c7a40a8e284d9e6690826a7936b.zip |
move index pagetypes to the public type; some minor cleanup
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@314 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Index.java | 33 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/PageTypes.java | 12 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java index 7f80d18..4dc822f 100644 --- a/src/java/com/healthmarketscience/jackcess/Index.java +++ b/src/java/com/healthmarketscience/jackcess/Index.java @@ -71,9 +71,6 @@ public abstract class Index implements Comparable<Index> { private static final short COLUMN_UNUSED = -1; - private static final byte INDEX_NODE_PAGE_TYPE = (byte)0x03; - private static final byte INDEX_LEAF_PAGE_TYPE = (byte)0x04; - private static final byte ASCENDING_COLUMN_FLAG = (byte)0x01; private static final byte UNIQUE_INDEX_FLAG = (byte)0x01; @@ -176,13 +173,7 @@ public abstract class Index implements Comparable<Index> { _table = table; _uniqueEntryCount = uniqueEntryCount; _uniqueEntryCountOffset = uniqueEntryCountOffset; - // the max data we can fit on a page is the min of the space on the page - // vs the number of bytes which can be encoded in the entry mask - _maxPageEntrySize = Math.min( - (getFormat().PAGE_SIZE - - (getFormat().OFFSET_INDEX_ENTRY_MASK + - getFormat().SIZE_INDEX_ENTRY_MASK)), - (getFormat().SIZE_INDEX_ENTRY_MASK * 8)); + _maxPageEntrySize = calcMaxPageEntrySize(_table.getFormat()); } public Table getTable() { @@ -746,8 +737,8 @@ public abstract class Index implements Comparable<Index> { ByteBuffer buffer = _indexBufferH.getPageBuffer(getPageChannel()); buffer.put(dataPage.isLeaf() ? - INDEX_LEAF_PAGE_TYPE : - INDEX_NODE_PAGE_TYPE ); //Page type + PageTypes.INDEX_LEAF : + PageTypes.INDEX_NODE ); //Page type buffer.put((byte) 0x01); //Unknown buffer.putShort((short) 0); //Free space buffer.putInt(getTable().getTableDefPageNumber()); @@ -909,9 +900,9 @@ public abstract class Index implements Comparable<Index> { throws IOException { byte pageType = buffer.get(0); - if(pageType == INDEX_LEAF_PAGE_TYPE) { + if(pageType == PageTypes.INDEX_LEAF) { return true; - } else if(pageType == INDEX_NODE_PAGE_TYPE) { + } else if(pageType == PageTypes.INDEX_NODE) { return false; } throw new IOException("Unexpected page type " + pageType); @@ -1222,6 +1213,20 @@ public abstract class Index implements Comparable<Index> { throw new IllegalArgumentException("Values was null for valid entry"); } + /** + * Returns the maximum amount of entry data which can be encoded on any + * index page. + */ + private static int calcMaxPageEntrySize(JetFormat format) + { + // the max data we can fit on a page is the min of the space on the page + // vs the number of bytes which can be encoded in the entry mask + int pageDataSize = (format.PAGE_SIZE - + (format.OFFSET_INDEX_ENTRY_MASK + + format.SIZE_INDEX_ENTRY_MASK)); + int entryMaskSize = (format.SIZE_INDEX_ENTRY_MASK * 8); + return Math.min(pageDataSize, entryMaskSize); + } /** * Information about the columns in an index. Also encodes new index diff --git a/src/java/com/healthmarketscience/jackcess/PageTypes.java b/src/java/com/healthmarketscience/jackcess/PageTypes.java index 1d0fc94..91eab9d 100644 --- a/src/java/com/healthmarketscience/jackcess/PageTypes.java +++ b/src/java/com/healthmarketscience/jackcess/PageTypes.java @@ -33,11 +33,17 @@ package com.healthmarketscience.jackcess; */ public interface PageTypes { + /** invalid page type */ + public static final byte INVALID = (byte)0x00; /** Data page */ - public static final byte DATA = 0x1; + public static final byte DATA = (byte)0x01; /** Table definition page */ - public static final byte TABLE_DEF = 0x2; + public static final byte TABLE_DEF = (byte)0x02; + /** intermediate index page pointing to other index pages */ + public static final byte INDEX_NODE = (byte)0x03; + /** leaf index page containing actual entries */ + public static final byte INDEX_LEAF = (byte)0x04; /** Table usage map page */ - public static final byte USAGE_MAP = 0x5; + public static final byte USAGE_MAP = (byte)0x05; } |