Skip to content

Commit

Permalink
Removed ordering requirements in XML metadata. Tables can be listed i…
Browse files Browse the repository at this point in the history
…n any order now.
  • Loading branch information
johncurrier committed Aug 23, 2008
1 parent f7ce357 commit f93db2f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/net/sourceforge/schemaspy/SchemaAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ public int analyze(Config config) throws Exception {
SchemaSpy spy = new SchemaSpy(connection, meta, dbName, schema, config.getDescription(), properties, config.getTableInclusions(), config.getMaxDbThreads(), schemaMeta);
Database db = spy.getDatabase();

schemaMeta = null; // done with it so let GC reclaim it

LineWriter out;
Collection<Table> tables = new ArrayList<Table>(db.getTables());
tables.addAll(db.getViews());
Expand Down
36 changes: 27 additions & 9 deletions src/net/sourceforge/schemaspy/model/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -589,29 +589,47 @@ private void initViews(@SuppressWarnings("hiding")String schema, DatabaseMetaDat
private void updateFromXmlMetadata(SchemaMeta schemaMeta) throws SQLException {
if (schemaMeta != null) {
final Pattern excludeNone = Pattern.compile("[^.]");
final Properties noProps = new Properties();

comments = schemaMeta.getComments();

// add the newly defined remote tables first
// done in three passes:
// 1: create any new tables
// 2: add/mod columns
// 3: connect

// add the newly defined tables and columns first
for (TableMeta tableMeta : schemaMeta.getTables()) {
Table table;

if (tableMeta.getRemoteSchema() != null) {
Table table = remoteTables.get(tableMeta.getName());
table = remoteTables.get(tableMeta.getRemoteSchema() + '.' + tableMeta.getName());
if (table == null) {
table = addRemoteTable(tableMeta.getRemoteSchema(), tableMeta.getName(), getSchema(), null, excludeNone);
}

table.update(tableMeta, tables, remoteTables);
} else {
table = tables.get(tableMeta.getName());

if (table == null) {
table = new Table(Database.this, getSchema(), tableMeta.getName(), null, noProps, excludeNone);
tables.put(table.getName(), table);
}
}

table.update(tableMeta);
}

// then tie the tables together
for (TableMeta tableMeta : schemaMeta.getTables()) {
if (tableMeta.getRemoteSchema() == null) {
Table table = tables.get(tableMeta.getName());
if (table != null) {
table.update(tableMeta, tables, remoteTables);
}
Table table;

if (tableMeta.getRemoteSchema() != null) {
table = remoteTables.get(tableMeta.getRemoteSchema() + '.' + tableMeta.getName());
} else {
table = tables.get(tableMeta.getName());
}

table.connect(tableMeta, tables, remoteTables);
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions src/net/sourceforge/schemaspy/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -708,10 +708,7 @@ protected int fetchNumRows(Database db, String clause, boolean forceQuotes) thro
}
}

/**
* @param tableMeta
*/
public void update(TableMeta tableMeta, Map<String, Table> tables, Map<String, Table> remoteTables) {
public void update(TableMeta tableMeta) {
String newComments = tableMeta.getComments();
if (newComments != null) {
comments = newComments;
Expand All @@ -731,8 +728,17 @@ public void update(TableMeta tableMeta, Map<String, Table> tables, Map<String, T

// update the column with the changes
col.update(colMeta);
}
}

/**
* @param tableMeta
*/
public void connect(TableMeta tableMeta, Map<String, Table> tables, Map<String, Table> remoteTables) {
for (TableColumnMeta colMeta : tableMeta.getColumns()) {
TableColumn col = getColumn(colMeta.getName());

// go thru the new foreign key defs and associate them with our columns
// go thru the new foreign key defs and associate them with our columns
for (ForeignKeyMeta fk : colMeta.getForeignKeys()) {
Table parent = fk.getRemoteSchema() == null ? tables.get(fk.getTableName())
: remoteTables.get(fk.getRemoteSchema() + '.' + fk.getTableName());
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/schemaspy/view/DotNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ else if (indexColumns.contains(column))
buf.append("</TD></TR>" + lineSeparator);

buf.append(" </TABLE>>" + lineSeparator);
buf.append(" URL=\"" + path + toNCR(tableName) + ".html" + ((path.length() == 0 && !config.showColumnDetails) || table.isRemote() ? "#diagram" : "#") + "\"" + lineSeparator);
buf.append(" URL=\"" + path + toNCR(tableName) + ".html\"" + lineSeparator);
buf.append(" tooltip=\"" + toNCR(tableName) + "\"" + lineSeparator);
buf.append(" ];");

Expand Down

0 comments on commit f93db2f

Please sign in to comment.