From: James Ahlborn Date: Wed, 4 Mar 2015 03:31:01 +0000 (+0000) Subject: add some convenience methods for new TableIterableBuilder; add change notes for linke... X-Git-Tag: jackcess-2.0.9~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=babfdb1947d35dc0fa98bd5dc15f2330e956c1f4;p=jackcess.git add some convenience methods for new TableIterableBuilder; add change notes for linked table updates git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@918 f203690c-595d-4dc9-a70b-905162fa7fd2 --- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 37b679b..78bf4ea 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -12,6 +12,15 @@ Handle input String boolean values. + + Added Database.isLinkedTable method to identify if the given Table is + linked to the database. + + + Added TableIterableBuilder for advanced Table iteration. This allows + selectively including different table types when iterating the tables + in a Database. + diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java index 414b43b..bb3bfac 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java @@ -620,8 +620,8 @@ public class DatabaseImpl implements Database return _tableFinder.isLinkedTable(table); } - boolean matchesLinkedTable(Table table, String linkedTableName, - String linkedDbName) { + private boolean matchesLinkedTable(Table table, String linkedTableName, + String linkedDbName) { return (table.getName().equalsIgnoreCase(linkedTableName) && (_linkedDbs != null) && (_linkedDbs.get(linkedDbName) == table.getDatabase())); diff --git a/src/main/java/com/healthmarketscience/jackcess/util/TableIterableBuilder.java b/src/main/java/com/healthmarketscience/jackcess/util/TableIterableBuilder.java index 0390ed0..9563ced 100644 --- a/src/main/java/com/healthmarketscience/jackcess/util/TableIterableBuilder.java +++ b/src/main/java/com/healthmarketscience/jackcess/util/TableIterableBuilder.java @@ -70,6 +70,25 @@ public class TableIterableBuilder implements Iterable _includeLinkedTables = includeLinkedTables; return this; } + + /** + * Convenience method to set the flags to include only non-linked (local) + * user tables. + */ + public TableIterableBuilder withLocalUserTablesOnly() { + setIncludeNormalTables(true); + setIncludeSystemTables(false); + return setIncludeLinkedTables(false); + } + + /** + * Convenience method to set the flags to include only system tables. + */ + public TableIterableBuilder withSystemTablesOnly() { + setIncludeNormalTables(false); + setIncludeSystemTables(true); + return setIncludeLinkedTables(false); + } public Iterator
iterator() { return ((DatabaseImpl)_db).iterator(this); diff --git a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java index e2751cb..e8cc98c 100644 --- a/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/src/test/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -1463,16 +1463,14 @@ public class DatabaseTest extends TestCase assertTrue(tables.contains(t3)); assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); - tables = getTables(db.newIterable().setIncludeLinkedTables(false)); + tables = getTables(db.newIterable().withLocalUserTablesOnly()); assertEquals(1, tables.size()); assertTrue(tables.contains(t1)); assertFalse(tables.contains(t2)); assertFalse(tables.contains(t3)); assertFalse(tables.contains(((DatabaseImpl)db).getSystemCatalog())); - tables = getTables(db.newIterable().setIncludeLinkedTables(false) - .setIncludeNormalTables(false) - .setIncludeSystemTables(true)); + tables = getTables(db.newIterable().withSystemTablesOnly()); assertTrue(tables.size() > 5); assertFalse(tables.contains(t1)); assertFalse(tables.contains(t2));