diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2006-10-02 15:57:57 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2006-10-02 15:57:57 +0000 |
commit | b9378914c86f118caa452a2cdb83f21527172320 (patch) | |
tree | d7ea89a9ff52981cba6fb2e665a6140e3327a9b6 /src/java/com/healthmarketscience/jackcess/PageChannel.java | |
parent | 584802a0b811edc57fc5f423dc07f258cdede362 (diff) | |
download | jackcess-b9378914c86f118caa452a2cdb83f21527172320.tar.gz jackcess-b9378914c86f118caa452a2cdb83f21527172320.zip |
implement multi-page long value writing
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@127 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience/jackcess/PageChannel.java')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/PageChannel.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/PageChannel.java b/src/java/com/healthmarketscience/jackcess/PageChannel.java index 0acaad8..3865394 100644 --- a/src/java/com/healthmarketscience/jackcess/PageChannel.java +++ b/src/java/com/healthmarketscience/jackcess/PageChannel.java @@ -44,6 +44,9 @@ public class PageChannel implements Channel { private static final Log LOG = LogFactory.getLog(PageChannel.class); static final int INVALID_PAGE_NUMBER = -1; + + /** dummy buffer used when allocating new pages */ + private static final ByteBuffer FORCE_BYTES = ByteBuffer.allocate(1); /** Global usage map always lives on page 1 */ private static final int PAGE_GLOBAL_USAGE_MAP = 1; @@ -113,6 +116,21 @@ public class PageChannel implements Channel { _globalUsageMap.removePageNumber(pageNumber); //force is done here return pageNumber; } + + /** + * Allocates a new page in the database. Data in the page is undefined + * until it is written in a call to {@link #writePage}. + */ + public int allocateNewPage() throws IOException { + long size = _channel.size(); + FORCE_BYTES.rewind(); + long offset = size + _format.PAGE_SIZE - FORCE_BYTES.remaining(); + // this will force the file to be extended with mostly undefined bytes + _channel.write(FORCE_BYTES, offset); + int pageNumber = (int) (size / _format.PAGE_SIZE); + _globalUsageMap.removePageNumber(pageNumber); //force is done here + return pageNumber; + } /** * @return Number of pages in the database |