]> source.dussan.org Git - jackcess.git/commitdiff
Detect unsupported Jet and File formats and throw specific exceptions early. newformats
authorDan Rollo <bhamail@users.sf.net>
Wed, 7 Apr 2010 02:14:41 +0000 (02:14 +0000)
committerDan Rollo <bhamail@users.sf.net>
Wed, 7 Apr 2010 02:14:41 +0000 (02:14 +0000)
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

src/java/com/healthmarketscience/jackcess/Database.java
test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java
test/src/java/com/healthmarketscience/jackcess/JetFormatTest.java
test/src/java/com/healthmarketscience/jackcess/UsageMapTest.java

index 5044de72bce625f6ccf0c5423ec146173f852a38..00ac78fe10be26af4b40cc91c98845d409f61ad3 100644 (file)
@@ -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
index 828f76d7bf5b72d43334aa82e6f1b0937fb80821..63c0add51599c06754d534eb15bd6c8349c4fd85 100644 (file)
@@ -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"));
       }
 
index 96365e4a353a3ebcc41b59adcb1177bf0c653cf7..a51e865dd5108af650898a18684f5b3faf0ae3f4 100644 (file)
@@ -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
     };
 
     /**
index 85b063057ef24d3abf38c484bd1bd7003f5aa78f..4d5544952f799bb21a5f9b724e661b338513e1c7 100644 (file)
@@ -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) {