From 84fb7e38ad46d8071d2699a1f141ccb4e97079e0 Mon Sep 17 00:00:00 2001 From: johncurrier Date: Tue, 29 Jul 2008 20:24:24 +0000 Subject: [PATCH] Better support for remote table row counts --- src/net/sourceforge/schemaspy/model/Database.java | 12 ++++++------ src/net/sourceforge/schemaspy/model/RemoteTable.java | 11 ++++++----- src/net/sourceforge/schemaspy/model/Table.java | 12 ++++++------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/net/sourceforge/schemaspy/model/Database.java b/src/net/sourceforge/schemaspy/model/Database.java index 825922d..70ea03b 100755 --- a/src/net/sourceforge/schemaspy/model/Database.java +++ b/src/net/sourceforge/schemaspy/model/Database.java @@ -28,7 +28,7 @@ public Database(Connection connection, DatabaseMetaData meta, String name, Strin this.description = description; initTables(schema, meta, properties, include, maxThreads); initViews(schema, meta, properties, include); - connectTables(); + connectTables(properties); } public String getName() { @@ -342,12 +342,12 @@ public PreparedStatement prepareStatement(String sql, String tableName) throws S return stmt; } - public Table addRemoteTable(String remoteSchema, String remoteTableName, String baseSchema) throws SQLException { + public Table addRemoteTable(String remoteSchema, String remoteTableName, String baseSchema, Properties properties) throws SQLException { String fullName = remoteSchema + "." + remoteTableName; Table remoteTable = (Table)remoteTables.get(fullName); if (remoteTable == null) { - remoteTable = new RemoteTable(this, remoteSchema, remoteTableName, baseSchema); - remoteTable.connectForeignKeys(tables, this); + remoteTable = new RemoteTable(this, remoteSchema, remoteTableName, baseSchema, properties); + remoteTable.connectForeignKeys(tables, this, properties); remoteTables.put(fullName, remoteTable); } @@ -545,11 +545,11 @@ private void initViews(String schema, DatabaseMetaData metadata, Properties prop } } - private void connectTables() throws SQLException { + private void connectTables(Properties properties) throws SQLException { Iterator iter = tables.values().iterator(); while (iter.hasNext()) { Table table = (Table)iter.next(); - table.connectForeignKeys(tables, this); + table.connectForeignKeys(tables, this, properties); } } diff --git a/src/net/sourceforge/schemaspy/model/RemoteTable.java b/src/net/sourceforge/schemaspy/model/RemoteTable.java index a62a79e..e836659 100644 --- a/src/net/sourceforge/schemaspy/model/RemoteTable.java +++ b/src/net/sourceforge/schemaspy/model/RemoteTable.java @@ -2,7 +2,8 @@ import java.sql.ResultSet; import java.sql.SQLException; -import net.sourceforge.schemaspy.util.*; +import java.util.Map; +import java.util.Properties; /** * A table that's outside of the default schema but is referenced @@ -13,8 +14,8 @@ public class RemoteTable extends Table { private final String baseSchema; - public RemoteTable(Database db, String schema, String name, String baseSchema) throws SQLException { - super(db, schema, name, null, null); + public RemoteTable(Database db, String schema, String name, String baseSchema, Properties properties) throws SQLException { + super(db, schema, name, null, properties); this.baseSchema = baseSchema; } @@ -23,7 +24,7 @@ public RemoteTable(Database db, String schema, String name, String baseSchema) t * @param db * @param tables */ - public void connectForeignKeys(CaseInsensitiveMap tables, Database db) throws SQLException { + public void connectForeignKeys(Map tables, Database db, Properties properties) throws SQLException { ResultSet rs = null; try { @@ -32,7 +33,7 @@ public void connectForeignKeys(CaseInsensitiveMap tables, Database db) throws SQ while (rs.next()) { String otherSchema = rs.getString("PKTABLE_SCHEM"); if (otherSchema != null && otherSchema.equals(baseSchema)) - addForeignKey(rs, tables, db); + addForeignKey(rs, tables, db, properties); } } finally { if (rs != null) diff --git a/src/net/sourceforge/schemaspy/model/Table.java b/src/net/sourceforge/schemaspy/model/Table.java index cafe9e5..fd543b0 100755 --- a/src/net/sourceforge/schemaspy/model/Table.java +++ b/src/net/sourceforge/schemaspy/model/Table.java @@ -29,20 +29,20 @@ public Table(Database db, String schema, String name, String comments, Propertie numRows = Config.getInstance().isNumRowsEnabled() ? fetchNumRows(db, properties) : -1; } - public void connectForeignKeys(Map tables, Database db) throws SQLException { + public void connectForeignKeys(Map tables, Database db, Properties properties) throws SQLException { ResultSet rs = null; try { rs = db.getMetaData().getImportedKeys(null, getSchema(), getName()); while (rs.next()) - addForeignKey(rs, tables, db); + addForeignKey(rs, tables, db, properties); } finally { if (rs != null) rs.close(); } - // if we're one of multples then also find all of the 'remote' tables in other + // if we're one of multiples then also find all of the 'remote' tables in other // schemas that point to our primary keys (not necessary in the normal case // as we infer this from the opposite direction) if (getSchema() != null && Config.getInstance().isOneOfMultipleSchemas()) { @@ -52,7 +52,7 @@ public void connectForeignKeys(Map tables, Database db) throws SQLException { while (rs.next()) { String otherSchema = rs.getString("FKTABLE_SCHEM"); if (!getSchema().equals(otherSchema)) - db.addRemoteTable(otherSchema, rs.getString("FKTABLE_NAME"), getSchema()); + db.addRemoteTable(otherSchema, rs.getString("FKTABLE_NAME"), getSchema(), properties); } } finally { if (rs != null) @@ -80,7 +80,7 @@ public void addCheckConstraint(String name, String text) { * @param db * @throws SQLException */ - protected void addForeignKey(ResultSet rs, Map tables, Database db) throws SQLException { + protected void addForeignKey(ResultSet rs, Map tables, Database db, Properties properties) throws SQLException { String name = rs.getString("FK_NAME"); if (name == null) @@ -101,7 +101,7 @@ protected void addForeignKey(ResultSet rs, Map tables, Database db) throws SQLEx if (parentTable == null) { String otherSchema = rs.getString("PKTABLE_SCHEM"); if (otherSchema != null && !otherSchema.equals(getSchema()) && Config.getInstance().isOneOfMultipleSchemas()) { - parentTable = db.addRemoteTable(otherSchema, rs.getString("PKTABLE_NAME"), getSchema()); + parentTable = db.addRemoteTable(otherSchema, rs.getString("PKTABLE_NAME"), getSchema(), properties); } }