Skip to content

Commit

Permalink
Added a summary of remote tables to the tables tab to quickly identif…
Browse files Browse the repository at this point in the history
…y remote relationships
  • Loading branch information
johncurrier committed Feb 12, 2011
1 parent 4ad8e6d commit fabb9bc
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 52 deletions.
4 changes: 4 additions & 0 deletions dist/releaseNotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ <h3><a href='http://schemaspy.sourceforge.net'>SchemaSpy</a> Release Notes</h3>

<li class='release'>x.x.x - xx/xx/xxxx - Subversion revision 596
<ul>
<li>Added a summary of remote tables to the tables tab to quickly
identify remote relationships.<br>
rev 628
</li>
<li>It's now possible to supplement your real database metadata with logical
tables and relationships.
One possible use is with systems that store some of their data
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/schemaspy/SchemaAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public Database analyze(Config config) throws Exception {
System.out.print(".");

out = new LineWriter(new File(outputDir, "index.html"), 64 * 1024, config.getCharset());
HtmlMainIndexPage.getInstance().write(db, tables, hasOrphans, out);
HtmlMainIndexPage.getInstance().write(db, tables, db.getRemoteTables(), hasOrphans, out);
out.close();

if (!fineEnabled)
Expand Down
15 changes: 1 addition & 14 deletions src/net/sourceforge/schemaspy/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -1220,20 +1220,7 @@ public int compareTo(Table other) {
if (other == this) // fast way out
return 0;

int rc = getName().compareToIgnoreCase(other.getName());
if (rc == 0) {
// should only get here if we're dealing with cross-schema references (rare)
String ours = getContainer();
String theirs = other.getContainer();
if (ours != null && theirs != null)
rc = ours.compareToIgnoreCase(theirs);
else if (ours == null)
rc = -1;
else
rc = 1;
}

return rc;
return getFullName().compareToIgnoreCase(other.getFullName());
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/net/sourceforge/schemaspy/view/HtmlFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
import net.sourceforge.schemaspy.util.LineWriter;

public class HtmlFormatter {
protected final boolean encodeComments = Config.getInstance().isEncodeCommentsEnabled();
protected final boolean displayNumRows = Config.getInstance().isNumRowsEnabled();
private final boolean isMetered = Config.getInstance().isMeterEnabled();
protected final boolean encodeComments = Config.getInstance().isEncodeCommentsEnabled();
private final boolean isMetered = Config.getInstance().isMeterEnabled();
protected final boolean displayNumRows = Config.getInstance().isNumRowsEnabled();

protected HtmlFormatter() {
}
Expand Down
134 changes: 100 additions & 34 deletions src/net/sourceforge/schemaspy/view/HtmlMainIndexPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import net.sourceforge.schemaspy.Config;
import net.sourceforge.schemaspy.model.Database;
import net.sourceforge.schemaspy.model.Table;
import net.sourceforge.schemaspy.util.HtmlEncoder;
Expand Down Expand Up @@ -55,32 +55,39 @@ public static HtmlMainIndexPage getInstance() {
return instance;
}

public void write(Database database, Collection<Table> tables, boolean showOrphansDiagram, LineWriter html) throws IOException {
Set<Table> byName = new TreeSet<Table>(new Comparator<Table>() {
public void write(Database database, Collection<Table> tables, Collection<Table> remotes, boolean showOrphansDiagram, LineWriter html) throws IOException {
Comparator<Table> sorter = new Comparator<Table>() {
public int compare(Table table1, Table table2) {
return table1.compareTo(table2);
}
});
byName.addAll(tables);
};
// sort tables and remotes by name
Collection<Table> tmp = new TreeSet<Table>(sorter);
tmp.addAll(tables);
tables = tmp;
tmp = new TreeSet<Table>(sorter);
tmp.addAll(remotes);
remotes = tmp;
tmp = null;

boolean showIds = false;
int numViews = 0;
boolean comments = false;
boolean hasComments = false;

for (Table table : byName) {
for (Table table : tables) {
if (table.isView())
++numViews;
showIds |= table.getId() != null;
if (table.getComments() != null)
comments = true;
hasComments = true;
}

writeHeader(database, byName.size() - numViews, numViews, showIds, showOrphansDiagram, comments, html);
writeLocalsHeader(database, tables.size() - numViews, numViews, showIds, showOrphansDiagram, hasComments, html);

int numTableCols = 0;
int numViewCols = 0;
long numRows = 0;
for (Table table : byName) {
for (Table table : tables) {
writeLineItem(table, showIds, html);

if (!table.isView())
Expand All @@ -90,10 +97,22 @@ public int compare(Table table1, Table table2) {
numRows += table.getNumRows() > 0 ? table.getNumRows() : 0;
}

writeFooter(byName.size() - numViews, numTableCols, numViews, numViewCols, numRows, html);
writeLocalsFooter(tables.size() - numViews, numTableCols, numViews, numViewCols, numRows, html);

if (!remotes.isEmpty()) {
writeRemotesHeader(database, showIds, hasComments, html);

for (Table table : remotes) {
writeLineItem(table, showIds, html);
}

writeRemotesFooter(html);
}

writeFooter(html);
}

private void writeHeader(Database db, int numberOfTables, int numberOfViews, boolean showIds, boolean hasOrphans, boolean hasComments, LineWriter html) throws IOException {
private void writeLocalsHeader(Database db, int numberOfTables, int numberOfViews, boolean showIds, boolean hasOrphans, boolean hasComments, LineWriter html) throws IOException {
List<String> javascript = new ArrayList<String>();

// we can't use the hard-coded even odd technique that we use
Expand Down Expand Up @@ -141,7 +160,6 @@ private void writeHeader(Database db, int numberOfTables, int numberOfViews, boo
html.write("<br><a href='" + xmlName + ".xml' title='XML Representation'>XML Representation</a>");
html.write("<br><a href='insertionOrder.txt' title='Useful for loading data into a database'>Insertion Order</a>&nbsp;");
html.write("<a href='deletionOrder.txt' title='Useful for purging data from a database'>Deletion Order</a>");
html.write("&nbsp;(for database loading/purging scripts)");
html.writeln("</td>");
html.writeln(" </tr>");
html.writeln("</table>");
Expand Down Expand Up @@ -189,13 +207,55 @@ else if (numberOfTables == 0)
html.writeln("<tbody>");
}

private void writeRemotesHeader(Database db, boolean showIds, boolean hasComments, LineWriter html) throws IOException {
html.writeln("<p><br><b>Related tables in other schemas</b>");
html.writeln("<table class='dataTable' border='1' rules='groups'>");
int numGroups = 3 + (showIds ? 1 : 0);
for (int i = 0; i < numGroups; ++i)
html.writeln("<colgroup>");
html.writeln("<colgroup class='comment'>");
html.writeln("<thead align='left'>");
html.writeln("<tr>");
html.writeln(" <th rowspan='2'>Table</th>");
if (showIds)
html.writeln(" <th align='center' valign='bottom' rowspan='2'>ID</th>");
html.writeln(" <th valign='bottom' colspan='2' style='text-align: center;'>In this schema</th>");
html.writeln(" <th class='comment' align='left' valign='bottom' rowspan='2'>Comments</th>");
html.writeln("</tr>");
html.writeln("<tr>");
html.writeln(" <th align='right' valign='bottom'>Children</th>");
html.writeln(" <th align='right' valign='bottom'>Parents</th>");
html.writeln("</tr>");
html.writeln("</thead>");
html.writeln("<tbody>");
}

private void writeLineItem(Table table, boolean showIds, LineWriter html) throws IOException {
html.write(" <tr class='" + (table.isView() ? "view" : "tbl") + "' valign='top'>");
html.write(" <td class='detail'><a href='tables/");
html.write(urlEncode(table.getName()));
html.write(".html'>");
html.write(table.getName());
html.writeln("</a></td>");
html.write(" <td class='detail'>");

String tableName = table.getName();

if (table.isRemote() && !Config.getInstance().isOneOfMultipleSchemas()) {
html.write(table.getContainer());
html.write('.');
html.write(tableName);
} else {
html.write("<a href='tables/");
if (table.isRemote()) {
html.write("../../" + table.getContainer() + "/tables/");
}
html.write(urlEncode(tableName));
html.write(".html'>");
if (table.isRemote()) {
html.write(table.getContainer());
html.write('.');
}
html.write(tableName);
html.write("</a>");
}

html.writeln("</td>");

if (showIds) {
html.write(" <td class='detail' align='right'>");
Expand All @@ -218,21 +278,24 @@ private void writeLineItem(Table table, boolean showIds, LineWriter html) throws
html.write(String.valueOf(integerFormatter.format(numRelatives)));
html.writeln("</td>");

html.write(" <td class='detail' align='right'>");
html.write(String.valueOf(integerFormatter.format(table.getColumns().size())));
html.writeln("</td>");

if (displayNumRows) {
if (!table.isRemote()) {
html.write(" <td class='detail' align='right'>");
if (!table.isView()) {
if (table.getNumRows() >= 0)
html.write(String.valueOf(integerFormatter.format(table.getNumRows())));
else
html.write("<span title='Row count not available'>&nbsp;</span>");
} else
html.write("<span title='Views contain no real rows'>view</span>");
html.write(String.valueOf(integerFormatter.format(table.getColumns().size())));
html.writeln("</td>");

if (displayNumRows) {
html.write(" <td class='detail' align='right'>");
if (!table.isView()) {
if (table.getNumRows() >= 0)
html.write(String.valueOf(integerFormatter.format(table.getNumRows())));
else
html.write("<span title='Row count not available'>&nbsp;</span>");
} else
html.write("<span title='Views contain no real rows'>view</span>");
html.writeln("</td>");
}
}

html.write(" <td class='comment detail'>");
String comments = table.getComments();
if (comments != null) {
Expand All @@ -246,7 +309,7 @@ private void writeLineItem(Table table, boolean showIds, LineWriter html) throws
html.writeln(" </tr>");
}

protected void writeFooter(int numTables, int numTableCols, int numViews, int numViewCols, long numRows, LineWriter html) throws IOException {
protected void writeLocalsFooter(int numTables, int numTableCols, int numViews, int numViewCols, long numRows, LineWriter html) throws IOException {
html.writeln(" <tr>");
html.writeln(" <td class='detail'>&nbsp;</td>");
html.writeln(" <td class='detail'>&nbsp;</td>");
Expand Down Expand Up @@ -278,10 +341,13 @@ protected void writeFooter(int numTables, int numTableCols, int numViews, int nu
html.writeln(" </tr>");
html.writeln("</tbody>");
html.writeln("</table>");

super.writeFooter(html);
}


protected void writeRemotesFooter(LineWriter html) throws IOException {
html.writeln("</tbody>");
html.writeln("</table>");
}

@Override
protected boolean isMainIndex() {
return true;
Expand Down

0 comments on commit fabb9bc

Please sign in to comment.