From 322d32d4be01471ad9d41fc05e0c5a11c8ec7de0 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 29 Jul 2011 04:07:11 +0000 Subject: [PATCH] add Database.getSystemTableNames to enable retrieving the list of system/hidden tables git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@570 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/changes/changes.xml | 4 +++ .../jackcess/Database.java | 23 +++++++++++--- .../jackcess/DatabaseTest.java | 31 +++++++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 564cee4..2b86a16 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -18,6 +18,10 @@ Add methods to approximate table size. + + Add Database.getSystemTableNames to enable retrieving the list of + system/hidden tables. + diff --git a/src/java/com/healthmarketscience/jackcess/Database.java b/src/java/com/healthmarketscience/jackcess/Database.java index a856b02..7326d69 100644 --- a/src/java/com/healthmarketscience/jackcess/Database.java +++ b/src/java/com/healthmarketscience/jackcess/Database.java @@ -980,12 +980,25 @@ public class Database if(_tableNames == null) { Set tableNames = new TreeSet(String.CASE_INSENSITIVE_ORDER); - _tableFinder.getTableNames(tableNames); + _tableFinder.getTableNames(tableNames, false); _tableNames = tableNames; } return _tableNames; } + /** + * @return The names of all of the system tables (String). Note, in order + * to read these tables, you must use {@link #getSystemTable}. + * Extreme care should be taken if modifying these tables + * directly!. + */ + public Set getSystemTableNames() throws IOException { + Set sysTableNames = + new TreeSet(String.CASE_INSENSITIVE_ORDER); + _tableFinder.getTableNames(sysTableNames, true); + return sysTableNames; + } + /** * @return an unmodifiable Iterator of the user Tables in this Database. * @throws IllegalStateException if an IOException is thrown by one of the @@ -2015,8 +2028,10 @@ public class Database return ((cur != null) ? cur.getCurrentRow(columns) : null); } - public void getTableNames(Set tableNames) throws IOException { - + public void getTableNames(Set tableNames, + boolean systemTables) + throws IOException + { for(Map row : getTableNamesCursor().iterable( SYSTEM_CATALOG_TABLE_NAME_COLUMNS)) { @@ -2026,7 +2041,7 @@ public class Database int parentId = (Integer)row.get(CAT_COL_PARENT_ID); if((parentId == _tableParentId) && TYPE_TABLE.equals(type) && - !isSystemObject(flags)) { + (isSystemObject(flags) == systemTables)) { tableNames.add(tableName); } } diff --git a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java index 26c35ff..3b08370 100644 --- a/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java +++ b/test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java @@ -51,12 +51,12 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.TreeSet; import java.util.UUID; -import junit.framework.TestCase; - import static com.healthmarketscience.jackcess.Database.*; import static com.healthmarketscience.jackcess.JetFormatTest.*; +import junit.framework.TestCase; /** * @author Tim McCune @@ -997,13 +997,39 @@ public class DatabaseTest extends TestCase { for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) { Database db = create(fileFormat); + Set sysTables = new TreeSet( + String.CASE_INSENSITIVE_ORDER); + sysTables.addAll( + Arrays.asList("MSysObjects", "MSysQueries", "MSysACES", + "MSysRelationships")); + if (fileFormat.ordinal() < FileFormat.V2003.ordinal()) { assertNotNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects")); + sysTables.add("MSysAccessObjects"); } else { // v2003+ template files have no "MSysAccessObjects" table assertNull("file format: " + fileFormat, db.getSystemTable("MSysAccessObjects")); + sysTables.addAll( + Arrays.asList("MSysNavPaneGroupCategories", + "MSysNavPaneGroups", "MSysNavPaneGroupToObjects", + "MSysNavPaneObjectIDs", "MSysAccessStorage")); + if(fileFormat.ordinal() >= FileFormat.V2007.ordinal()) { + sysTables.addAll( + Arrays.asList( + "MSysComplexColumns", "MSysComplexType_Attachment", + "MSysComplexType_Decimal", "MSysComplexType_GUID", + "MSysComplexType_IEEEDouble", "MSysComplexType_IEEESingle", + "MSysComplexType_Long", "MSysComplexType_Short", + "MSysComplexType_Text", "MSysComplexType_UnsignedByte")); + } + if(fileFormat.ordinal() >= FileFormat.V2010.ordinal()) { + sysTables.add("f_12D7448B56564D8AAE333BCC9B3718E5_Data"); + sysTables.add("MSysResources"); + } } + assertEquals(sysTables, db.getSystemTableNames()); + assertNotNull(db.getSystemTable("MSysObjects")); assertNotNull(db.getSystemTable("MSysQueries")); assertNotNull(db.getSystemTable("MSysACES")); @@ -1011,6 +1037,7 @@ public class DatabaseTest extends TestCase { assertNull(db.getSystemTable("MSysBogus")); + db.close(); } } -- 2.39.5