Skip to content

Commit

Permalink
Added catalog/schema details to relationships in generated XML
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Apr 14, 2011
1 parent 9800740 commit cc284ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/main/java/net/sourceforge/schemaspy/util/DOMUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ public static void printDOM(Node node, LineWriter out) throws TransformerExcepti
* @param value String
*/
public static void appendAttribute(Node node, String name, String value) {
Node attribute = node.getOwnerDocument().createAttribute(name);
attribute.setNodeValue(value);
node.getAttributes().setNamedItem(attribute);
if (value != null) {
Node attribute = node.getOwnerDocument().createAttribute(name);
attribute.setNodeValue(value);
node.getAttributes().setNamedItem(attribute);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ private void appendTable(Element tablesNode, Table table) {
tablesNode.appendChild(tableNode);
if (table.getId() != null)
DOMUtil.appendAttribute(tableNode, "id", String.valueOf(table.getId()));
if (table.getCatalog() != null)
DOMUtil.appendAttribute(tableNode, "catalog", table.getCatalog());
if (table.getSchema() != null)
DOMUtil.appendAttribute(tableNode, "schema", table.getSchema());
DOMUtil.appendAttribute(tableNode, "catalog", table.getCatalog());
DOMUtil.appendAttribute(tableNode, "schema", table.getSchema());
DOMUtil.appendAttribute(tableNode, "name", table.getName());
if (table.getNumRows() >= 0)
DOMUtil.appendAttribute(tableNode, "numRows", String.valueOf(table.getNumRows()));
Expand Down Expand Up @@ -155,21 +153,27 @@ private Node appendColumn(Node tableNode, TableColumn column) {

for (TableColumn childColumn : column.getChildren()) {
Node childNode = document.createElement("child");
Table table = childColumn.getTable();
columnNode.appendChild(childNode);
ForeignKeyConstraint constraint = column.getChildConstraint(childColumn);
DOMUtil.appendAttribute(childNode, "foreignKey", constraint.getName());
DOMUtil.appendAttribute(childNode, "table", childColumn.getTable().getName());
DOMUtil.appendAttribute(childNode, "catalog", table.getCatalog());
DOMUtil.appendAttribute(childNode, "schema", table.getSchema());
DOMUtil.appendAttribute(childNode, "table", table.getName());
DOMUtil.appendAttribute(childNode, "column", childColumn.getName());
DOMUtil.appendAttribute(childNode, "implied", String.valueOf(constraint.isImplied()));
DOMUtil.appendAttribute(childNode, "onDeleteCascade", String.valueOf(constraint.isCascadeOnDelete()));
}

for (TableColumn parentColumn : column.getParents()) {
Node parentNode = document.createElement("parent");
Table table = parentColumn.getTable();
columnNode.appendChild(parentNode);
ForeignKeyConstraint constraint = column.getParentConstraint(parentColumn);
DOMUtil.appendAttribute(parentNode, "foreignKey", constraint.getName());
DOMUtil.appendAttribute(parentNode, "table", parentColumn.getTable().getName());
DOMUtil.appendAttribute(parentNode, "catalog", table.getCatalog());
DOMUtil.appendAttribute(parentNode, "schema", table.getSchema());
DOMUtil.appendAttribute(parentNode, "table", table.getName());
DOMUtil.appendAttribute(parentNode, "column", parentColumn.getName());
DOMUtil.appendAttribute(parentNode, "implied", String.valueOf(constraint.isImplied()));
DOMUtil.appendAttribute(parentNode, "onDeleteCascade", String.valueOf(constraint.isCascadeOnDelete()));
Expand Down

0 comments on commit cc284ef

Please sign in to comment.