summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Rollo <bhamail@users.sf.net>2010-04-07 02:14:41 +0000
committerDan Rollo <bhamail@users.sf.net>2010-04-07 02:14:41 +0000
commit2c646fd415e0ec611407dc5e2aac79cac5af70c8 (patch)
treefc79d6f8065e877d3d7b87a4baee361e92772ba8
parentb288c8bae282f0023f3b257d36b0c6f82782fed4 (diff)
downloadjackcess-2c646fd415e0ec611407dc5e2aac79cac5af70c8.tar.gz
jackcess-2c646fd415e0ec611407dc5e2aac79cac5af70c8.zip
Detect unsupported Jet and File formats and throw specific exceptions early.newformats
Remove old @todo comments and sys.outs. git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/newformats@456 f203690c-595d-4dc9-a70b-905162fa7fd2
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java15
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java33
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java1
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java7
4 files changed, 42 insertions, 14 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index 5044de7..00ac78f 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -170,7 +170,12 @@ public class Database
private static final String CAT_COL_FLAGS = "Flags";
/** System catalog column name of the properties column */
private static final String CAT_COL_PROPS = "LvProp";
-
+
+ /** Error message prefix for unsupported file format. */
+ static final String MSG_PREFIX_CREATE_UNSUPPORTED_FILE_FORMAT = "Unsupported file format: ";
+ /** Error message prefix for unsupported file format. */
+ static final String MSG_PREFIX_OPEN_UNSUPPORTED_JET_FORMAT = "Unsupported Jet format: ";
+
public static enum FileFormat {
V1997(null, JetFormat.VERSION_3), // v97 is not supported, so no empty template is provided
@@ -439,6 +444,10 @@ public class Database
boolean autoSync)
throws IOException
{
+ if (JetFormat.VERSION_3.equals(fileFormat.getJetFormat())) {
+ throw new IllegalArgumentException(MSG_PREFIX_CREATE_UNSUPPORTED_FILE_FORMAT + fileFormat);
+ }
+
FileChannel channel = openChannel(mdbFile, false);
channel.truncate(0);
channel.transferFrom(Channels.newChannel(
@@ -478,6 +487,10 @@ public class Database
throws IOException
{
_format = JetFormat.getFormat(channel);
+ if (JetFormat.VERSION_3.equals(_format)) {
+ channel.close();
+ throw new IllegalArgumentException(MSG_PREFIX_OPEN_UNSUPPORTED_JET_FORMAT + _format);
+ }
_fileFormat = fileFormat;
_pageChannel = new PageChannel(channel, _format, autoSync);
// note, it's slighly sketchy to pass ourselves along partially
diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
index 828f76d..63c0add 100644
--- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
@@ -101,6 +101,27 @@ public class DatabaseTest extends TestCase {
}
+ public void testUnsupportedCreate() throws Exception {
+ try {
+ create(JetFormatTest.UNSUPPORTED_TEST_V1997.getExpectedFileFormat());
+ fail("Create unsupported JetFormat should fail.");
+ } catch (IllegalArgumentException e) {
+ assertEquals(Database.MSG_PREFIX_CREATE_UNSUPPORTED_FILE_FORMAT + FileFormat.V1997, e.getMessage());
+ }
+ }
+
+ public void testUnsupportedOpen() throws Exception {
+ try {
+ open(JetFormatTest.UNSUPPORTED_TEST_V1997);
+ fail("Open unsupported JetFormat should fail.");
+ } catch (IllegalArgumentException e) {
+ assertEquals(
+ MSG_PREFIX_OPEN_UNSUPPORTED_JET_FORMAT + UNSUPPORTED_TEST_V1997.getExpectedFormat(),
+ e.getMessage());
+ }
+ }
+
+
public void testInvalidTableDefs() throws Exception {
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
@@ -783,15 +804,9 @@ public class DatabaseTest extends TestCase {
String lval = createString(255); // "--255 chars long text--";
- if (FileFormat.V2007.equals(testDB.getExpectedFileFormat())) {
- // @todo Field order differs with V2007
- System.err.println("\n*** TODO: " + getName()
- + "(): Is OK that " + testDB.getExpectedFileFormat().name() + " field order differs? ***");
- }
-
for(int i = 0; i < 1000; ++i) {
if (FileFormat.V2007.equals(testDB.getExpectedFileFormat())) {
- // @todo Field order differs with V2007
+ // Field order differs with V2007
t.addRow(i, 13, 57, lval, lval, lval, lval, lval, lval, 47.0d);
} else {
t.addRow(i, 13, 57, 47.0d, lval, lval, lval, lval, lval, lval);
@@ -986,9 +1001,7 @@ public class DatabaseTest extends TestCase {
&& !FileFormat.V2007.equals(fileFormat)) {
assertNotNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects"));
} else {
- // @todo Does is matter that v2003, v2007 template files have no "MSysAccessObjects" table?
- System.err.println("\n*** TODO: " + getName()
- + "(): Is OK that " + fileFormat.name() + " template file has no \"MSysAccessObjects\" table? ***");
+ // v2003, v2007 template files have no "MSysAccessObjects" table
assertNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects"));
}
diff --git a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
index 96365e4..a51e865 100644
--- a/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
@@ -50,7 +50,6 @@ public final class JetFormatTest extends TestCase {
Database.FileFormat.V2000,
Database.FileFormat.V2003,
Database.FileFormat.V2007,
- // @todo Uncomment these elements to run test other formats
};
/**
diff --git a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java
index 85b0630..4d55449 100644
--- a/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java
+++ b/test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java
@@ -5,6 +5,7 @@ import junit.framework.TestCase;
import java.io.File;
import java.io.IOException;
+import static com.healthmarketscience.jackcess.Database.MSG_PREFIX_OPEN_UNSUPPORTED_JET_FORMAT;
import static com.healthmarketscience.jackcess.JetFormatTest.*;
/**
@@ -18,8 +19,10 @@ public final class UsageMapTest extends TestCase {
try {
Database.open(UNSUPPORTED_TEST_V1997.getFile());
fail("mdb v97 usage map unsupported");
- } catch (IOException e) {
- assertEquals(UsageMap.MSG_PREFIX_UNRECOGNIZED_MAP + 2, e.getMessage());
+ } catch (IllegalArgumentException e) {
+ assertEquals(
+ MSG_PREFIX_OPEN_UNSUPPORTED_JET_FORMAT + UNSUPPORTED_TEST_V1997.getExpectedFormat(),
+ e.getMessage());
}
for (final TestDB testDB : SUPPORTED_DBS_TEST) {
Jackcess now requires Java 8+ as of the 3.0.0 release. All third party dependencies have been updated to the latest versions. Jackcess now supports Java 8+ data types like <code>LocalDateTime</code> and <code>Path</code>. Databases can now optionally return <code>Date</code> values (legacy, backwards compatible) or <code>LocalDateTime</code> values. See <a href="apidocs/com/healthmarketscience/jackcess/DateTimeType.html">DateTimeType</a> and the <a href="jackcess-3.html">Upgrade Guide</a> for more details </p> </subsection> <subsection name="Expression Evaluation (2018-09-08)"> <p> Have you ever wished that Jackcess could handle field "default values" (or other expressions)? Wish no longer! Expression evaluation is now enabled by default as of the 3.5.0 release. See the <a href="apidocs/com/healthmarketscience/jackcess/expr/package-summary.html#package_description">expression package</a> javadocs for more details. </p> </subsection> <subsection name="Brand New License! (2015-04-16)"> <p> Due to the generosity of Health Market Science and the efforts of the <a href="https://tika.apache.org/">Apache Tika project</a>, the OpenHMS projects have been relicensed under the <b>Apache License, Version 2.0</b> (Jackcess versions 2.1.0 and higher). </p> </subsection> </section> <section name="Sample code"> <p> Here are a few snippets of code to whet your appetite. For more extensive examples, checkout the <a href="cookbook.html">cookbook</a>. And, since Jackcess is heavily unit tested, you can find even more example code in the <a href="xref-test/index.html">unit tests</a>. </p> <ul> <li>Iterating through the rows of a table: <source>Table table = DatabaseBuilder.open(new File("my.mdb")).getTable("MyTable"); for(Row row : table) { System.out.println("Column 'a' has value: " + row.get("a")); } </source> </li> <li>Searching for a row with a specific column value: <source>Row row = CursorBuilder.findRow(table, Collections.singletonMap("a", "foo")); if(row != null) { System.out.println("Found row where 'a' == 'foo': " + row); } else { System.out.println("Could not find row where 'a' == 'foo'"); } </source> </li> <li>Creating a new table and writing data into it: <source>Database db = DatabaseBuilder.create(Database.FileFormat.V2000, new File("new.mdb")); Table newTable = new TableBuilder("NewTable") .addColumn(new ColumnBuilder("a", DataType.LONG)) .addColumn(new ColumnBuilder("b", DataType.TEXT)) .toTable(db); newTable.addRow(1, "foo"); </source> </li> <li>Copying the contents of a JDBC ResultSet (e.g. from an external database) into a new table: <source>Database db = DatabaseBuilder.open(new File("my.mdb")); new ImportUtil.Builder(db, "Imported").importResultSet(resultSet); db.close();</source> </li> <li>Copying the contents of a CSV file into a new table: <source>Database db = DatabaseBuilder.open(new File("my.mdb")); new ImportUtil.Builder(db, "Imported2").setDelimiter(",").importFile(new File("my.csv")); db.close();</source> </li> </ul> </section> <section name="Other Resources"> <p> Some other jackcess related projects: </p> <ul> <li> <a href="https://github.com/brianb/mdbtools">mdbtools</a> - Open Source project for reading Access files, written in C. </li> <li> <a href="https://jackcessencrypt.sourceforge.io/">Jackcess Encrypt</a> - Extension library for Jackcess which implements support for some forms of Microsoft Access and Microsoft Money encryption. </li> <li> <a href="http://ucanaccess.sourceforge.net/site.html">UCanAccess</a> - Open Source pure Java JDBC Driver implementation. </li> </ul> </section> </body> </document>