aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/healthmarketscience
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2015-02-23 04:08:54 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2015-02-23 04:08:54 +0000
commit4ffcf30a2a07d0ff79e68e40210f850110694eee (patch)
tree7719742a859c21ad8332fca7e2d6778855924912 /src/main/java/com/healthmarketscience
parent54713bcd6c5f1def3e926a93caf1afba5a91f1f9 (diff)
downloadjackcess-4ffcf30a2a07d0ff79e68e40210f850110694eee.tar.gz
jackcess-4ffcf30a2a07d0ff79e68e40210f850110694eee.zip
fix linked table test; add unit tests for new table iteration methods
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@917 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java43
1 files changed, 35 insertions, 8 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
index 969f93d..414b43b 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
@@ -601,20 +601,31 @@ public class DatabaseImpl implements Database
}
public boolean isLinkedTable(Table table) throws IOException {
-
+
if((table == null) || (this == table.getDatabase())) {
// if the table is null or this db owns the table, not linked
return false;
}
+ // common case, local table name == remote table name
TableInfo tableInfo = lookupTable(table.getName());
-
- return((tableInfo != null) &&
- tableInfo.isLinked() &&
- (_linkedDbs != null) &&
- (_linkedDbs.get(((LinkedTableInfo)tableInfo).linkedDbName) ==
- table.getDatabase()));
+ if((tableInfo != null) && tableInfo.isLinked() &&
+ matchesLinkedTable(table, ((LinkedTableInfo)tableInfo).linkedTableName,
+ ((LinkedTableInfo)tableInfo).linkedDbName)) {
+ return true;
+ }
+
+ // but, the local table name may not match the remote table name, so we
+ // need to do a search if the common case fails
+ return _tableFinder.isLinkedTable(table);
}
+
+ boolean matchesLinkedTable(Table table, String linkedTableName,
+ String linkedDbName) {
+ return (table.getName().equalsIgnoreCase(linkedTableName) &&
+ (_linkedDbs != null) &&
+ (_linkedDbs.get(linkedDbName) == table.getDatabase()));
+ }
public TimeZone getTimeZone() {
return _timeZone;
@@ -1873,7 +1884,7 @@ public class DatabaseImpl implements Database
throw new NoSuchElementException();
}
try {
- return getTable(_tableNameIter.next());
+ return getTable(_tableNameIter.next(), true);
} catch(IOException e) {
throw new RuntimeIOException(e);
}
@@ -1944,6 +1955,22 @@ public class DatabaseImpl implements Database
}
}
+ public boolean isLinkedTable(Table table) throws IOException
+ {
+ for(Row row : getTableNamesCursor().newIterable().setColumnNames(
+ SYSTEM_CATALOG_COLUMNS)) {
+ Short type = row.getShort(CAT_COL_TYPE);
+ String linkedDbName = row.getString(CAT_COL_DATABASE);
+ String linkedTableName = row.getString(CAT_COL_FOREIGN_NAME);
+
+ if(TYPE_LINKED_TABLE.equals(type) &&
+ matchesLinkedTable(table, linkedTableName, linkedDbName)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected abstract Cursor findRow(Integer parentId, String name)
throws IOException;