diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2016-02-16 00:13:01 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2016-02-16 00:13:01 +0000 |
commit | 4e5fe7ec04eff9ea4e64a8c6d1e3f7fd51257e06 (patch) | |
tree | d858366ec674ddc1e8dadaca27d8451a39e4385b /src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java | |
parent | afdc6f96fe5d662e76567ee2230a3a5d5a859169 (diff) | |
download | jackcess-4e5fe7ec04eff9ea4e64a8c6d1e3f7fd51257e06.tar.gz jackcess-4e5fe7ec04eff9ea4e64a8c6d1e3f7fd51257e06.zip |
Add Database.getTableMetaData method to enable getting basic info about a Table (by name) without actually loading it. fixes feature request #33
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@979 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java')
-rw-r--r-- | src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java index 490e75f..99500dd 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java @@ -60,6 +60,7 @@ import com.healthmarketscience.jackcess.Relationship; import com.healthmarketscience.jackcess.Row; import com.healthmarketscience.jackcess.RuntimeIOException; import com.healthmarketscience.jackcess.Table; +import com.healthmarketscience.jackcess.TableMetaData; import com.healthmarketscience.jackcess.impl.query.QueryImpl; import com.healthmarketscience.jackcess.query.Query; import com.healthmarketscience.jackcess.util.CaseInsensitiveColumnMatcher; @@ -928,6 +929,10 @@ public class DatabaseImpl implements Database return getTable(name, false); } + public TableMetaData getTableMetaData(String name) throws IOException { + return getTableInfo(name, true); + } + /** * @param tableDefPageNumber the page number of a table definition * @return The table, or null if it doesn't exist @@ -962,15 +967,29 @@ public class DatabaseImpl implements Database private TableImpl getTable(String name, boolean includeSystemTables) throws IOException { + TableInfo tableInfo = getTableInfo(name, includeSystemTables); + return ((tableInfo != null) ? + getTable(tableInfo, includeSystemTables) : null); + } + + private TableInfo getTableInfo(String name, boolean includeSystemTables) + throws IOException + { TableInfo tableInfo = lookupTable(name); if ((tableInfo == null) || (tableInfo.pageNumber == null)) { return null; } - if(!includeSystemTables && isSystemObject(tableInfo.flags)) { + if(!includeSystemTables && tableInfo.isSystem()) { return null; } + return tableInfo; + } + + private TableImpl getTable(TableInfo tableInfo, boolean includeSystemTables) + throws IOException + { if(tableInfo.isLinked()) { if(_linkedDbs == null) { @@ -1884,7 +1903,7 @@ public class DatabaseImpl implements Database /** * Utility class for storing table page number and actual name. */ - private static class TableInfo + private static class TableInfo implements TableMetaData { public final Integer pageNumber; public final String tableName; @@ -1896,9 +1915,44 @@ public class DatabaseImpl implements Database flags = newFlags; } + public String getName() { + return tableName; + } + public boolean isLinked() { return false; } + + public boolean isSystem() { + return isSystemObject(flags); + } + + public String getLinkedTableName() { + return null; + } + + public String getLinkedDbName() { + return null; + } + + public Table open(Database db) throws IOException { + return ((DatabaseImpl)db).getTable(this, true); + } + + @Override + public String toString() { + ToStringBuilder sb = CustomToStringStyle.valueBuilder("TableMetaData") + .append("name", getName()); + if(isSystem()) { + sb.append("isSystem", isSystem()); + } + if(isLinked()) { + sb.append("isLinked", isLinked()) + .append("linkedTableName", getLinkedTableName()) + .append("linkedDbName", getLinkedDbName()); + } + return sb.toString(); + } } /** @@ -1921,6 +1975,16 @@ public class DatabaseImpl implements Database public boolean isLinked() { return true; } + + @Override + public String getLinkedTableName() { + return linkedTableName; + } + + @Override + public String getLinkedDbName() { + return linkedDbName; + } } /** |