diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2007-07-10 21:48:33 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2007-07-10 21:48:33 +0000 |
commit | a05f660f7b0d93d8e4e739686cec112650ca84d2 (patch) | |
tree | 1e2ee13f5f04b14384a5a0921dc2e3a467c81f6a /src/java/com | |
parent | a97ce25f570f8867e93ff2e244b9dc5a8fe4b2bc (diff) | |
download | jackcess-a05f660f7b0d93d8e4e739686cec112650ca84d2.tar.gz jackcess-a05f660f7b0d93d8e4e739686cec112650ca84d2.zip |
add flush method to Database; add unit test for new usage map functionality
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@157 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com')
3 files changed, 19 insertions, 7 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index 0a94e0a..7c68f21 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -28,9 +28,11 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess; import java.io.BufferedReader; +import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; +import java.io.Flushable; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; @@ -39,7 +41,6 @@ import java.nio.channels.FileChannel; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; -import java.sql.Types; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -63,7 +64,7 @@ import org.apache.commons.logging.LogFactory; * @author Tim McCune */ public class Database - implements Iterable<Table> + implements Iterable<Table>, Closeable, Flushable { private static final Log LOG = LogFactory.getLog(Database.class); @@ -824,6 +825,13 @@ public class Database throw (IOException)new IOException(e.getMessage()).initCause(e); } } + + /** + * Flushes any current changes to the database file to disk. + */ + public void flush() throws IOException { + _pageChannel.flush(); + } /** * Close the database file diff --git a/src/java/com/healthmarketscience/jackcess/PageChannel.java b/src/java/com/healthmarketscience/jackcess/PageChannel.java index ca824db..9f394f0 100644 --- a/src/java/com/healthmarketscience/jackcess/PageChannel.java +++ b/src/java/com/healthmarketscience/jackcess/PageChannel.java @@ -27,11 +27,13 @@ King of Prussia, PA 19406 package com.healthmarketscience.jackcess; +import java.io.Flushable; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.Channel; import java.nio.channels.FileChannel; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -39,7 +41,7 @@ import org.apache.commons.logging.LogFactory; * Reads and writes individual pages in a database file * @author Tim McCune */ -public class PageChannel implements Channel { +public class PageChannel implements Channel, Flushable { private static final Log LOG = LogFactory.getLog(PageChannel.class); @@ -125,7 +127,7 @@ public class PageChannel implements Channel { _channel.write(page, (((long) pageNumber * (long) _format.PAGE_SIZE) + (long) pageOffset)); if(_autoSync) { - _channel.force(true); + flush(); } } @@ -165,9 +167,13 @@ public class PageChannel implements Channel { rtn.order(ByteOrder.LITTLE_ENDIAN); return rtn; } + + public void flush() throws IOException { + _channel.force(true); + } public void close() throws IOException { - _channel.force(true); + flush(); _channel.close(); } diff --git a/src/java/com/healthmarketscience/jackcess/UsageMap.java b/src/java/com/healthmarketscience/jackcess/UsageMap.java index 55c2015..1ba9a6f 100644 --- a/src/java/com/healthmarketscience/jackcess/UsageMap.java +++ b/src/java/com/healthmarketscience/jackcess/UsageMap.java @@ -29,9 +29,7 @@ package com.healthmarketscience.jackcess; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.BitSet; -import java.util.List; import java.util.logging.Handler; import org.apache.commons.logging.Log; |