From 412b7e2b2c629a15a0dc60c11aec3f25a189196a Mon Sep 17 00:00:00 2001 From: johncurrier Date: Tue, 19 Aug 2008 20:22:44 +0000 Subject: [PATCH] Allow explicitly defined tables (in XML) to attempt to populate their relationships from the database's metadata. --- .../sourceforge/schemaspy/model/Database.java | 8 +++++-- .../schemaspy/model/ExplicitRemoteTable.java | 24 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/net/sourceforge/schemaspy/model/ExplicitRemoteTable.java diff --git a/src/net/sourceforge/schemaspy/model/Database.java b/src/net/sourceforge/schemaspy/model/Database.java index 1c4c676..f14edf4 100755 --- a/src/net/sourceforge/schemaspy/model/Database.java +++ b/src/net/sourceforge/schemaspy/model/Database.java @@ -368,7 +368,11 @@ public Table addRemoteTable(String remoteSchema, String remoteTableName, String String fullName = remoteSchema + "." + remoteTableName; Table remoteTable = remoteTables.get(fullName); if (remoteTable == null) { - remoteTable = new RemoteTable(this, remoteSchema, remoteTableName, baseSchema, properties); + if (properties != null) + remoteTable = new RemoteTable(this, remoteSchema, remoteTableName, baseSchema, properties); + else + remoteTable = new ExplicitRemoteTable(this, remoteSchema, remoteTableName, baseSchema); + remoteTable.connectForeignKeys(tables, this, properties); remoteTables.put(fullName, remoteTable); } @@ -574,7 +578,7 @@ private void updateFromXmlMetadata(SchemaMeta schemaMeta) throws SQLException { if (tableMeta.getRemoteSchema() != null) { Table table = remoteTables.get(tableMeta.getName()); if (table == null) { - table = addRemoteTable(tableMeta. getRemoteSchema(), tableMeta.getName(), getSchema(), null); + table = addRemoteTable(tableMeta.getRemoteSchema(), tableMeta.getName(), getSchema(), null); } table.update(tableMeta, tables, remoteTables); diff --git a/src/net/sourceforge/schemaspy/model/ExplicitRemoteTable.java b/src/net/sourceforge/schemaspy/model/ExplicitRemoteTable.java new file mode 100644 index 0000000..d62ec1e --- /dev/null +++ b/src/net/sourceforge/schemaspy/model/ExplicitRemoteTable.java @@ -0,0 +1,24 @@ +package net.sourceforge.schemaspy.model; + +import java.sql.SQLException; +import java.util.Map; +import java.util.Properties; + +/** + * A remote table (exists in another schema) that was explicitly created via XML metadata. + * + * @author John Currier + */ +public class ExplicitRemoteTable extends RemoteTable { + public ExplicitRemoteTable(Database db, String schema, String name, String baseSchema) throws SQLException { + super(db, schema, name, baseSchema, null); + } + + @Override + public void connectForeignKeys(Map tables, Database db, Properties properties) throws SQLException { + // this probably won't work, so ignore any failures...but try anyways just in case + try { + super.connectForeignKeys(tables, db, properties); + } catch (SQLException ignore) {} + } +} \ No newline at end of file