diff options
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/Cursor.java | 7 | ||||
-rw-r--r-- | src/java/com/healthmarketscience/jackcess/JetFormat.java | 11 | ||||
-rwxr-xr-x | test/data/V1997/indexTestV1997.mdb | bin | 0 -> 112640 bytes | |||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/IndexTest.java | 20 | ||||
-rw-r--r-- | test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java | 8 |
5 files changed, 41 insertions, 5 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Cursor.java b/src/java/com/healthmarketscience/jackcess/Cursor.java index f05c689..ed08160 100644 --- a/src/java/com/healthmarketscience/jackcess/Cursor.java +++ b/src/java/com/healthmarketscience/jackcess/Cursor.java @@ -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; } diff --git a/src/java/com/healthmarketscience/jackcess/JetFormat.java b/src/java/com/healthmarketscience/jackcess/JetFormat.java index 8265d77..8041dbb 100644 --- a/src/java/com/healthmarketscience/jackcess/JetFormat.java +++ b/src/java/com/healthmarketscience/jackcess/JetFormat.java @@ -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(); @@ -393,6 +398,9 @@ public abstract class JetFormat { protected boolean defineReadOnly() { return true; } @Override + protected boolean defineIndexesSupported() { return false; } + + @Override protected int definePageSize() { return 2048; } @Override @@ -566,6 +574,9 @@ public abstract class JetFormat { protected boolean defineReadOnly() { return false; } @Override + protected boolean defineIndexesSupported() { return true; } + + @Override protected int definePageSize() { return 4096; } @Override diff --git a/test/data/V1997/indexTestV1997.mdb b/test/data/V1997/indexTestV1997.mdb Binary files differnew file mode 100755 index 0000000..3441d23 --- /dev/null +++ b/test/data/V1997/indexTestV1997.mdb diff --git a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java index 504a3b8..1738b07 100644 --- a/test/src/java/com/healthmarketscience/jackcess/IndexTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/IndexTest.java @@ -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; + } } diff --git a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java index 0311088..81c1fb0 100644 --- a/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/RelationshipTest.java @@ -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()); |