aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2011-07-29 04:07:11 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2011-07-29 04:07:11 +0000
commit322d32d4be01471ad9d41fc05e0c5a11c8ec7de0 (patch)
tree527aba56908f911c4ef7918837a4466e088edbeb
parent599d2da23e2d88632133ab178ad3e23cdc204753 (diff)
downloadjackcess-322d32d4be01471ad9d41fc05e0c5a11c8ec7de0.tar.gz
jackcess-322d32d4be01471ad9d41fc05e0c5a11c8ec7de0.zip
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
-rw-r--r--src/changes/changes.xml4
-rw-r--r--src/java/com/healthmarketscience/jackcess/Database.java23
-rw-r--r--test/src/java/com/healthmarketscience/jackcess/DatabaseTest.java31
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 @@
<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">
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,13 +980,26 @@ 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
* operations, the actual exception will be contained within
@@ -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);
}
}
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<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();
}
}