]> source.dussan.org Git - jackcess.git/commitdiff
add more jet3 tests, disable index lookups for jet3
authorJames Ahlborn <jtahlborn@yahoo.com>
Sat, 31 Jul 2010 17:33:36 +0000 (17:33 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Sat, 31 Jul 2010 17:33:36 +0000 (17:33 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@476 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/Cursor.java
src/java/com/healthmarketscience/jackcess/JetFormat.java
test/data/V1997/indexTestV1997.mdb [new file with mode: 0755]
test/src/java/com/healthmarketscience/jackcess/IndexTest.java
test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java

index f05c68938ad5cc4dc07ca7c108899d7174230c26..ed081609ba24dad0bad9d826247d634c19c8533b 100644 (file)
@@ -176,6 +176,11 @@ public abstract class Cursor implements Iterable<Map<String, Object>>
       throw new IllegalArgumentException(
           "Given index is not for given table: " + index + ", " + table);
     }
+    if(!table.getFormat().INDEXES_SUPPORTED) {
+      throw new IllegalArgumentException(
+          "JetFormat " + table.getFormat() + 
+          " does not currently support index lookups");
+    }
     return new IndexCursor(table, index,
                            index.cursor(startRow, startInclusive,
                                         endRow, endInclusive));
@@ -1163,6 +1168,8 @@ public abstract class Cursor implements Iterable<Map<String, Object>>
       super(new Id(table, index), table,
             new IndexPosition(entryCursor.getFirstEntry()),
             new IndexPosition(entryCursor.getLastEntry()));
+
+      index.initialize();
       _entryCursor = entryCursor;
     }
 
index 8265d774c363ce0f3ae3dfb78c69bb6494f79f3e..8041dbb06efe5f02798e973d11212c346de34ce1 100644 (file)
@@ -95,6 +95,9 @@ public abstract class JetFormat {
   /** the read/write mode of this format */
   public final boolean READ_ONLY;
   
+  /** whether or not we can use indexes in this format */
+  public final boolean INDEXES_SUPPORTED;
+  
   /** Database page size in bytes */
   public final int PAGE_SIZE;
   public final long MAX_DATABASE_SIZE;
@@ -210,6 +213,7 @@ public abstract class JetFormat {
     _name = name;
     
     READ_ONLY = defineReadOnly();
+    INDEXES_SUPPORTED = defineIndexesSupported();
     
     PAGE_SIZE = definePageSize();
     MAX_DATABASE_SIZE = defineMaxDatabaseSize();
@@ -294,6 +298,7 @@ public abstract class JetFormat {
   }
   
   protected abstract boolean defineReadOnly();
+  protected abstract boolean defineIndexesSupported();
   
   protected abstract int definePageSize();
   protected abstract long defineMaxDatabaseSize();
@@ -392,6 +397,9 @@ public abstract class JetFormat {
     @Override
     protected boolean defineReadOnly() { return true; }
            
+    @Override
+    protected boolean defineIndexesSupported() { return false; }
+           
     @Override
     protected int definePageSize() { return 2048; }
            
@@ -565,6 +573,9 @@ public abstract class JetFormat {
     @Override
     protected boolean defineReadOnly() { return false; }
     
+    @Override
+    protected boolean defineIndexesSupported() { return true; }
+           
     @Override
     protected int definePageSize() { return 4096; }
     
diff --git a/test/data/V1997/indexTestV1997.mdb b/test/data/V1997/indexTestV1997.mdb
new file mode 100755 (executable)
index 0000000..3441d23
Binary files /dev/null and b/test/data/V1997/indexTestV1997.mdb differ
index 504a3b822ab3b22485db524cbcbce41057bcf85d..1738b07ac841acbc78047ca96494070ec24bf0d6 100644 (file)
@@ -112,8 +112,10 @@ public class IndexTest extends TestCase {
       checkIndexColumns(table,
                         "id", "id",
                         "PrimaryKey", "id",
-                        "Table2Table1", "otherfk1",
-                        "Table3Table1", "otherfk2");
+                        getRelationshipName(testDB.getExpectedFormat(), 
+                                            "Table2Table1"), "otherfk1",
+                        getRelationshipName(testDB.getExpectedFormat(), 
+                                            "Table3Table1"), "otherfk2");
 
       table = mdb.getTable("Table2");
       for(Index idx : table.getIndexes()) {
@@ -417,5 +419,17 @@ public class IndexTest extends TestCase {
       }
     }
   }
-  
+
+  static String getRelationshipName(JetFormat format, String name)
+  {
+    if(format == JetFormat.VERSION_3) {
+      if(name.equals("Table2Table1")) {
+        return "{150B6687-5C64-4DC0-B934-A8CF92FF73FF}";
+      }
+      if(name.equals("Table3Table1")) {
+        return "{D039E343-97A1-471F-B2E3-8DFCF1EEC597}";
+      }
+    }
+    return name;
+  }
 }
index 0311088eda5b9abc7e0cac3a4e25c0cbba93aba8..81c1fb033d8a6befcddfc0e3f9dbfe2117cf8100 100644 (file)
@@ -54,7 +54,9 @@ public class RelationshipTest extends TestCase {
       List<Relationship> rels = db.getRelationships(t1, t2);
       assertEquals(1, rels.size());
       Relationship rel = rels.get(0);
-      assertEquals("Table2Table1", rel.getName());
+      assertEquals(IndexTest.getRelationshipName(testDB.getExpectedFormat(),
+                                                 "Table2Table1"),
+                   rel.getName());
       assertEquals(t2, rel.getFromTable());
       assertEquals(Arrays.asList(t2.getColumn("id")),
                    rel.getFromColumns());
@@ -72,7 +74,9 @@ public class RelationshipTest extends TestCase {
       rels = db.getRelationships(t1, t3);
       assertEquals(1, rels.size());
       rel = rels.get(0);
-      assertEquals("Table3Table1", rel.getName());
+      assertEquals(IndexTest.getRelationshipName(testDB.getExpectedFormat(),
+                                                 "Table3Table1"),
+                   rel.getName());
       assertEquals(t3, rel.getFromTable());
       assertEquals(Arrays.asList(t3.getColumn("id")),
                    rel.getFromColumns());