Skip to content

Commit

Permalink
Added support for more fully defining table details in XML
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Feb 9, 2011
1 parent f71f060 commit 0c42b58
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 36 deletions.
55 changes: 27 additions & 28 deletions src/net/sourceforge/schemaspy/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -1090,11 +1090,6 @@ public void update(TableMeta tableMeta) {
for (TableColumnMeta colMeta : tableMeta.getColumns()) {
TableColumn col = getColumn(colMeta.getName());
if (col == null) {
if (tableMeta.getRemoteSchema() == null) {
logger.warning("Unrecognized column '" + colMeta.getName() + "' for table '" + getName() + '\'');
continue;
}

col = addColumn(colMeta);
}

Expand All @@ -1115,32 +1110,36 @@ public void connect(TableMeta tableMeta, Map<String, Table> tables, Map<String,
for (TableColumnMeta colMeta : tableMeta.getColumns()) {
TableColumn col = getColumn(colMeta.getName());

// 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(db.getRemoteTableKey(null, fk.getRemoteSchema(), fk.getTableName()));
if (parent != null) {
TableColumn parentColumn = parent.getColumn(fk.getColumnName());

if (parentColumn == null) {
logger.warning(parent.getName() + '.' + fk.getColumnName() + " doesn't exist");
if (col != null) {
// 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(db.getRemoteTableKey(null, fk.getRemoteSchema(), fk.getTableName()));
if (parent != null) {
TableColumn parentColumn = parent.getColumn(fk.getColumnName());

if (parentColumn == null) {
logger.warning(parent.getName() + '.' + fk.getColumnName() + " doesn't exist");
} else {
/**
* Merely instantiating a foreign key constraint ties it
* into its parent and child columns (& therefore their tables)
*/
@SuppressWarnings("unused")
ForeignKeyConstraint unused =
new ForeignKeyConstraint(parentColumn, col) {
@Override
public String getName() {
return "Defined in XML";
}
};
}
} else {
/**
* Merely instantiating a foreign key constraint ties it
* into its parent and child columns (& therefore their tables)
*/
@SuppressWarnings("unused")
ForeignKeyConstraint unused =
new ForeignKeyConstraint(parentColumn, col) {
@Override
public String getName() {
return "Defined in XML";
}
};
logger.warning("Undefined table '" + fk.getTableName() + "' referenced by '" + getName() + '.' + col.getName() + "' in XML metadata");
}
} else {
logger.warning("Undefined table '" + fk.getTableName() + "' referenced by '" + getName() + '.' + col.getName() + '\'');
}
} else {
logger.warning("Undefined column '" + getName() + "." + colMeta.getName() + "' in XML metadata");
}
}
}
Expand Down
22 changes: 14 additions & 8 deletions src/net/sourceforge/schemaspy/model/TableColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,20 @@ public class TableColumn {
public TableColumn(Table table, TableColumnMeta colMeta) {
this.table = table;
name = colMeta.getName();
id = null;
type = "Unknown";
length = 0;
decimalDigits = 0;
detailedSize = "";
isNullable = false;
isAutoUpdated = false;
defaultValue = null;
id = colMeta.getId();
type = colMeta.getType();
length = colMeta.getSize();
decimalDigits = colMeta.getDigits();
StringBuilder buf = new StringBuilder();
buf.append(length);
if (decimalDigits > 0) {
buf.append(',');
buf.append(decimalDigits);
}
detailedSize = buf.toString();
isNullable = colMeta.isNullable();
isAutoUpdated = colMeta.isAutoUpdated();
defaultValue = colMeta.getDefaultValue();
comments = colMeta.getComments();
}

Expand Down

0 comments on commit 0c42b58

Please sign in to comment.