]> source.dussan.org Git - jackcess.git/commitdiff
add Database.getSystemTableNames to enable retrieving the list of system/hidden tables
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 29 Jul 2011 04:07:11 +0000 (04:07 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 29 Jul 2011 04:07:11 +0000 (04:07 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@570 f203690c-595d-4dc9-a70b-905162fa7fd2

src/changes/changes.xml
src/java/com/healthmarketscience/jackcess/Database.java
test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java

index 564cee42f0126f379f630ca4060ec96b555b9e4f..2b86a16ffef297887bf23b81c7021cfce535985f 100644 (file)
       <action dev="jahlborn" type="update">
         Add methods to approximate table size.
       </action>
+      <action dev="jahlborn" type="update">
+        Add Database.getSystemTableNames to enable retrieving the list of
+        system/hidden tables.
+      </action>
     </release>
     <release version="1.2.4" date="2011-05-14">
       <action dev="jahlborn" type="update">
index a856b02e8d57e39c7a84fcae7128b73885cfb44b..7326d690ebd8d6a06fa53efe6693a142c65f79ae 100644 (file)
@@ -980,12 +980,25 @@ public class Database
     if(_tableNames == null) {
       Set<String> tableNames =
         new TreeSet<String>(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}.
+   *         <i>Extreme care should be taken if modifying these tables
+   *         directly!</i>.
+   */
+  public Set<String> getSystemTableNames() throws IOException {
+    Set<String> sysTableNames =
+      new TreeSet<String>(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<String> tableNames) throws IOException {
-
+    public void getTableNames(Set<String> tableNames,
+                              boolean systemTables)
+      throws IOException
+    {
       for(Map<String,Object> 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);
         }
       }
index 26c35ff896b419e84cb6d28c36b007ec8ee97394..3b0837090aba60c981422f3026c56559fbfc0d12 100644 (file)
@@ -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<String> sysTables = new TreeSet<String>(
+          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();
     }
   }