From f93db2f03d994904ea5829d84308c372abe3da9c Mon Sep 17 00:00:00 2001 From: johncurrier Date: Sat, 23 Aug 2008 05:26:41 +0000 Subject: [PATCH] Removed ordering requirements in XML metadata. Tables can be listed in any order now. --- .../sourceforge/schemaspy/SchemaAnalyzer.java | 2 ++ .../sourceforge/schemaspy/model/Database.java | 36 ++++++++++++++----- .../sourceforge/schemaspy/model/Table.java | 16 ++++++--- .../sourceforge/schemaspy/view/DotNode.java | 2 +- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/net/sourceforge/schemaspy/SchemaAnalyzer.java b/src/net/sourceforge/schemaspy/SchemaAnalyzer.java index 490956c..32c3882 100644 --- a/src/net/sourceforge/schemaspy/SchemaAnalyzer.java +++ b/src/net/sourceforge/schemaspy/SchemaAnalyzer.java @@ -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 tables = new ArrayList
(db.getTables()); tables.addAll(db.getViews()); diff --git a/src/net/sourceforge/schemaspy/model/Database.java b/src/net/sourceforge/schemaspy/model/Database.java index 0c63100..7eb943a 100755 --- a/src/net/sourceforge/schemaspy/model/Database.java +++ b/src/net/sourceforge/schemaspy/model/Database.java @@ -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); } } } diff --git a/src/net/sourceforge/schemaspy/model/Table.java b/src/net/sourceforge/schemaspy/model/Table.java index 05ac4a2..46607c1 100755 --- a/src/net/sourceforge/schemaspy/model/Table.java +++ b/src/net/sourceforge/schemaspy/model/Table.java @@ -708,10 +708,7 @@ protected int fetchNumRows(Database db, String clause, boolean forceQuotes) thro } } - /** - * @param tableMeta - */ - public void update(TableMeta tableMeta, Map tables, Map remoteTables) { + public void update(TableMeta tableMeta) { String newComments = tableMeta.getComments(); if (newComments != null) { comments = newComments; @@ -731,8 +728,17 @@ public void update(TableMeta tableMeta, Map tables, Map tables, Map 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()); diff --git a/src/net/sourceforge/schemaspy/view/DotNode.java b/src/net/sourceforge/schemaspy/view/DotNode.java index 8ff9e9c..5971009 100755 --- a/src/net/sourceforge/schemaspy/view/DotNode.java +++ b/src/net/sourceforge/schemaspy/view/DotNode.java @@ -149,7 +149,7 @@ else if (indexColumns.contains(column)) buf.append("" + lineSeparator); buf.append("
>" + 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(" ];");