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));
super(new Id(table, index), table,
new IndexPosition(entryCursor.getFirstEntry()),
new IndexPosition(entryCursor.getLastEntry()));
+
+ index.initialize();
_entryCursor = entryCursor;
}
/** 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;
_name = name;
READ_ONLY = defineReadOnly();
+ INDEXES_SUPPORTED = defineIndexesSupported();
PAGE_SIZE = definePageSize();
MAX_DATABASE_SIZE = defineMaxDatabaseSize();
}
protected abstract boolean defineReadOnly();
+ protected abstract boolean defineIndexesSupported();
protected abstract int definePageSize();
protected abstract long defineMaxDatabaseSize();
@Override
protected boolean defineReadOnly() { return true; }
+ @Override
+ protected boolean defineIndexesSupported() { return false; }
+
@Override
protected int definePageSize() { return 2048; }
@Override
protected boolean defineReadOnly() { return false; }
+ @Override
+ protected boolean defineIndexesSupported() { return true; }
+
@Override
protected int definePageSize() { return 4096; }
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()) {
}
}
}
-
+
+ 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;
+ }
}
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());
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());