Access expects a row to be at least big enough to hold all fixed
values, even if they are null.
</action>
+ <action dev="jahlborn" type="update">
+ Add Index.getReferencedIndex for retrieving the referenced Index for a
+ foreign key index.
+ </action>
</release>
<release version="1.2.3" date="2011-03-05">
<action dev="jahlborn" type="fix" issue="3181334">
return getTable(name, false, useBigIndex);
}
+ /**
+ * @param tableDefPageNumber the page number of a table definition
+ * @return The table, or null if it doesn't exist
+ */
+ protected Table getTable(int tableDefPageNumber) throws IOException {
+
+ // first, check for existing table
+ Table table = _tableCache.get(tableDefPageNumber);
+ if(table != null) {
+ return table;
+ }
+
+ // lookup table info from system catalog
+ Map<String,Object> objectRow = _tableFinder.getObjectRow(
+ tableDefPageNumber, SYSTEM_CATALOG_COLUMNS);
+ if(objectRow == null) {
+ return null;
+ }
+
+ String name = (String)objectRow.get(CAT_COL_NAME);
+ int flags = (Integer)objectRow.get(CAT_COL_FLAGS);
+
+ return readTable(name, tableDefPageNumber, flags, defaultUseBigIndex());
+ }
+
/**
* @param name Table name
* @param includeSystemTables whether to consider returning a system table
return _reference;
}
+ /**
+ * @return the Index referenced by this Index's ForeignKeyReference (if it
+ * has one), otherwise {@code null}.
+ */
+ public Index getReferencedIndex() throws IOException {
+
+ if(_reference == null) {
+ return null;
+ }
+
+ Table refTable = getTable().getDatabase().getTable(
+ _reference.getOtherTablePageNumber());
+
+ if(refTable == null) {
+ throw new IOException("Reference to missing table " +
+ _reference.getOtherTablePageNumber());
+ }
+
+ Index refIndex = null;
+ int idxNumber = _reference.getOtherIndexNumber();
+ for(Index idx : refTable.getIndexes()) {
+ if(idx.getIndexNumber() == idxNumber) {
+ refIndex = idx;
+ break;
+ }
+ }
+
+ if(refIndex == null) {
+ throw new IOException("Reference to missing index " + idxNumber +
+ " on table " + refTable.getName());
+ }
+
+ // finally verify that we found the expected index (should reference this
+ // index)
+ ForeignKeyReference otherRef = refIndex.getReference();
+ if((otherRef == null) ||
+ (otherRef.getOtherTablePageNumber() !=
+ getTable().getTableDefPageNumber()) ||
+ (otherRef.getOtherIndexNumber() != _indexNumber)) {
+ throw new IOException("Found unexpected index " + refIndex.getName() +
+ " on table " + refTable.getName() +
+ " with reference " + otherRef);
+ }
+
+ return refIndex;
+ }
+
/**
* Whether or not {@code null} values are actually recorded in the index.
*/
}
}
+ public void testGetForeignKeyIndex() throws Exception
+ {
+ for (final TestDB testDB : TestDB.getSupportedForBasename(Basename.INDEX, true)) {
+ Database db = open(testDB);
+ Table t1 = db.getTable("Table1");
+ Table t2 = db.getTable("Table2");
+ Table t3 = db.getTable("Table3");
+
+ Index t2t1 = t1.getIndex(IndexTest.getRelationshipName(
+ db.getFormat(), "Table2Table1"));
+ Index t3t1 = t1.getIndex(IndexTest.getRelationshipName(
+ db.getFormat(), "Table3Table1"));
+
+
+ assertTrue(t2t1.isForeignKey());
+ assertNotNull(t2t1.getReference());
+ assertFalse(t2t1.getReference().isPrimaryTable());
+ doCheckForeignKeyIndex(t1, t2t1, t2);
+
+ assertTrue(t3t1.isForeignKey());
+ assertNotNull(t3t1.getReference());
+ assertFalse(t3t1.getReference().isPrimaryTable());
+ doCheckForeignKeyIndex(t1, t3t1, t3);
+
+ Index t1pk = t1.getIndex(IndexBuilder.PRIMARY_KEY_NAME);
+ assertNotNull(t1pk);
+ assertNull(t1pk.getReference());
+ assertNull(t1pk.getReferencedIndex());
+ }
+ }
+
+ private void doCheckForeignKeyIndex(Table ta, Index ia, Table tb)
+ throws Exception
+ {
+ Index ib = ia.getReferencedIndex();
+ assertNotNull(ib);
+ assertSame(tb, ib.getTable());
+
+ assertNotNull(ib.getReference());
+ assertSame(ia, ib.getReferencedIndex());
+ }
+
private void checkIndexColumns(Table table, String... idxInfo)
throws Exception
{