From: James Ahlborn Date: Fri, 13 Feb 2015 23:40:19 +0000 (+0000) Subject: add method to simplify testing whether or not a Table is linked to a Database, featur... X-Git-Tag: jackcess-2.0.9~12 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=339c27868eb524dda6a36092c8e7e317a0243a69;p=jackcess.git add method to simplify testing whether or not a Table is linked to a Database, feature #28 git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@914 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/main/java/com/healthmarketscience/jackcess/Database.java b/src/main/java/com/healthmarketscience/jackcess/Database.java index 24d291d..808dac7 100644 --- a/src/main/java/com/healthmarketscience/jackcess/Database.java +++ b/src/main/java/com/healthmarketscience/jackcess/Database.java @@ -329,6 +329,14 @@ public interface Database extends Iterable, Closeable, Flushable */ public Map getLinkedDatabases(); + + /** + * Returns {@code true} if this Database links to the given Table, {@code + * false} otherwise. + * @usage _general_method_ + */ + public boolean isLinkedTable(Table table) throws IOException; + /** * Gets currently configured TimeZone (always non-{@code null}). * @usage _intermediate_method_ diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java index 2afd394..aa75896 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java @@ -599,6 +599,22 @@ public class DatabaseImpl implements Database Collections.unmodifiableMap(_linkedDbs)); } + 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; + } + + TableInfo tableInfo = lookupTable(table.getName()); + + return((tableInfo != null) && + tableInfo.isLinked() && + (_linkedDbs != null) && + (_linkedDbs.get(((LinkedTableInfo)tableInfo).linkedDbName) == + table.getDatabase())); + } + public TimeZone getTimeZone() { return _timeZone; }