git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@476 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-1.2.1
@@ -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; | |||
} | |||
@@ -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; } | |||
@@ -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; | |||
} | |||
} |
@@ -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()); |