diff options
author | Dan Rollo <bhamail@users.sf.net> | 2010-03-12 07:52:15 +0000 |
---|---|---|
committer | Dan Rollo <bhamail@users.sf.net> | 2010-03-12 07:52:15 +0000 |
commit | eb399960c514529c2e26a8e09e17edf4242fafaf (patch) | |
tree | 61ad71d5ab9caee3f29ff80efc972c02911ec5df /src/java/com/healthmarketscience | |
parent | 8e306bc27b795188c11be761f5371dc2478f4350 (diff) | |
download | jackcess-eb399960c514529c2e26a8e09e17edf4242fafaf.tar.gz jackcess-eb399960c514529c2e26a8e09e17edf4242fafaf.zip |
huge commit: changes all tests that use a db file to execute against all supported db file formats. The list of formats to test is easily changed via JetFormatTest.SUPPORTED_FILEFORMATS.
All tests pass with v2000.
One test fails with v2003.
A half dozen fail with v2007 (but many are the same read error).
includes re-org of test db files for easier support of multiple file formats.
(this is a partial commit to avoid sf errors - will do db test data files next).
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/newformats@441 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java/com/healthmarketscience')
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Database.java | 49 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/PageChannel.java | 4 |
2 files changed, 47 insertions, 6 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index e31cc7d..f1c10ff 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -169,8 +169,30 @@ public class Database /** System catalog column name of the flags column */ private static final String CAT_COL_FLAGS = "Flags"; - /** Empty database template for creating new databases */ - private static final String EMPTY_MDB = "com/healthmarketscience/jackcess/empty.mdb"; + public static enum FileFormat { + + V1997(null, JetFormat.VERSION_3), // v97 is not supported, so no empty template is provided + V2000("com/healthmarketscience/jackcess/empty.mdb", JetFormat.VERSION_4), + V2003("com/healthmarketscience/jackcess/empty2003.mdb", JetFormat.VERSION_4), + V2007("com/healthmarketscience/jackcess/empty2007.accdb", JetFormat.VERSION_5); + + private final String emptyFile; + private final JetFormat format; + + /** + * @param emptyDBFile Empty database template for creating new databases. + * @param jetFormat JetFormat of the template. + */ + FileFormat(final String emptyDBFile, final JetFormat jetFormat) { + emptyFile = emptyDBFile; + format = jetFormat; + } + + public JetFormat getJetFormat() { return format; } + + public String toString() { return name() + ", jetFormat: " + format; } + } + /** Prefix for column or table names that are reserved words */ private static final String ESCAPE_PREFIX = "x"; /** Prefix that flags system tables */ @@ -362,12 +384,31 @@ public class Database */ public static Database create(File mdbFile, boolean autoSync) throws IOException - { + { + return create(FileFormat.V2000, mdbFile, autoSync); + } + /** + * Create a new Database + * @param fileFormat version of new database. + * @param mdbFile Location to write the new database to. <b>If this file + * already exists, it will be overwritten.</b> + * @param autoSync whether or not to enable auto-syncing on write. if + * {@code true}, writes will be immediately flushed to disk. + * This leaves the database in a (fairly) consistent state + * on each write, but can be very inefficient for many + * updates. if {@code false}, flushing to disk happens at + * the jvm's leisure, which can be much faster, but may + * leave the database in an inconsistent state if failures + * are encountered during writing. + */ + public static Database create(FileFormat fileFormat, File mdbFile, boolean autoSync) + throws IOException + { FileChannel channel = openChannel(mdbFile, false); channel.truncate(0); channel.transferFrom(Channels.newChannel( Thread.currentThread().getContextClassLoader().getResourceAsStream( - EMPTY_MDB)), 0, Integer.MAX_VALUE); + fileFormat.emptyFile)), 0, Integer.MAX_VALUE); return new Database(channel, autoSync); } diff --git a/src/java/com/healthmarketscience/jackcess/PageChannel.java b/src/java/com/healthmarketscience/jackcess/PageChannel.java index 8adf74b..e72bcd7 100644 --- a/src/java/com/healthmarketscience/jackcess/PageChannel.java +++ b/src/java/com/healthmarketscience/jackcess/PageChannel.java @@ -56,9 +56,9 @@ public class PageChannel implements Channel, Flushable { new byte[]{PageTypes.INVALID, (byte)0, (byte)0, (byte)0}; /** Global usage map always lives on page 1 */ - private static final int PAGE_GLOBAL_USAGE_MAP = 1; + static final int PAGE_GLOBAL_USAGE_MAP = 1; /** Global usage map always lives at row 0 */ - private static final int ROW_GLOBAL_USAGE_MAP = 0; + static final int ROW_GLOBAL_USAGE_MAP = 0; /** Channel containing the database */ private final FileChannel _channel; |