From 339c27868eb524dda6a36092c8e7e317a0243a69 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 13 Feb 2015 23:40:19 +0000 Subject: [PATCH] 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 --- .../healthmarketscience/jackcess/Database.java | 8 ++++++++ .../jackcess/impl/DatabaseImpl.java | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) 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; } -- 2.39.5