summaryrefslogtreecommitdiffstats
path: root/src/java
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2011-04-18 01:52:57 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2011-04-18 01:52:57 +0000
commitbb4ce1424cf8e4ef6c62e969e68884a6a0096024 (patch)
treec38086890e5e1c0b7d092cacd84d736c46c9f4ed /src/java
parent7f8126d41f3ef11c528ee533e87830d702f2d602 (diff)
downloadjackcess-bb4ce1424cf8e4ef6c62e969e68884a6a0096024.tar.gz
jackcess-bb4ce1424cf8e4ef6c62e969e68884a6a0096024.zip
add Index.getReferencedIndex for retrieving the referenced index of a foreign key index
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@555 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/java')
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java25
-rw-r--r--src/java/com/healthmarketscience/jackcess/Index.java47
2 files changed, 72 insertions, 0 deletions
diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java
index 3691e22..3029881 100644
--- a/src/java/com/healthmarketscience/jackcess/Database.java
+++ b/src/java/com/healthmarketscience/jackcess/Database.java
@@ -1018,6 +1018,31 @@ public class Database
}
/**
+ * @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
* @param useBigIndex whether or not "big index support" should be enabled
diff --git a/src/java/com/healthmarketscience/jackcess/Index.java b/src/java/com/healthmarketscience/jackcess/Index.java
index c9c2bf4..532b4e1 100644
--- a/src/java/com/healthmarketscience/jackcess/Index.java
+++ b/src/java/com/healthmarketscience/jackcess/Index.java
@@ -165,6 +165,53 @@ public class Index implements Comparable<Index> {
}
/**
+ * @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 boolean shouldIgnoreNulls() {