Skip to content

Commit

Permalink
Better support for remote table row counts
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Jul 29, 2008
1 parent 44f604d commit 84fb7e3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
12 changes: 6 additions & 6 deletions src/net/sourceforge/schemaspy/model/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
11 changes: 6 additions & 5 deletions src/net/sourceforge/schemaspy/model/RemoteTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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 {
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/net/sourceforge/schemaspy/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 84fb7e3

Please sign in to comment.