Skip to content

Commit

Permalink
Added ability to exclude tables from analysis to help simplify output
Browse files Browse the repository at this point in the history
  • Loading branch information
johncurrier committed Oct 28, 2005
1 parent 763892e commit f6970ab
Show file tree
Hide file tree
Showing 10 changed files with 374 additions and 119 deletions.
37 changes: 31 additions & 6 deletions src/net/sourceforge/schemaspy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.*;
import java.util.*;
import java.util.jar.*;
import java.util.regex.*;
//import javax.xml.parsers.*;
//import org.w3c.dom.*;
import net.sourceforge.schemaspy.model.*;
Expand Down Expand Up @@ -84,6 +85,14 @@ public static void main(String[] argv) {
System.setProperty("sourceforgelogo", "true");
}

Pattern exclusions;
String exclude = getParam(args, "-i", false, false);
if (exclude != null) {
exclusions = Pattern.compile(exclude);
} else {
exclusions = Pattern.compile("[^.]"); // match nothing
}

ConnectionURLBuilder urlBuilder = null;
try {
urlBuilder = new ConnectionURLBuilder(dbType, args, properties);
Expand Down Expand Up @@ -155,14 +164,17 @@ public static void main(String[] argv) {
File graphsDir = new File(outputDir, "graphs/summary");
String dotBaseFilespec = "relationships";
out = new LineWriter(new FileWriter(new File(graphsDir, dotBaseFilespec + ".real.compact.dot")));
WriteStats stats = DotFormatter.getInstance().writeRealRelationships(tables, true, out);
WriteStats stats = new WriteStats(exclusions, includeImpliedConstraints);
DotFormatter.getInstance().writeRealRelationships(tables, true, stats, out);
boolean hasRelationships = stats.getNumTablesWritten() > 0 || stats.getNumViewsWritten() > 0;
stats = new WriteStats(stats);
out.close();

if (hasRelationships) {
System.out.print(".");
out = new LineWriter(new FileWriter(new File(graphsDir, dotBaseFilespec + ".real.large.dot")));
DotFormatter.getInstance().writeRealRelationships(tables, false, out);
DotFormatter.getInstance().writeRealRelationships(tables, false, stats, out);
stats = new WriteStats(stats);
out.close();
}

Expand All @@ -182,48 +194,58 @@ public static void main(String[] argv) {

File impliedDotFile = new File(graphsDir, dotBaseFilespec + ".implied.compact.dot");
out = new LineWriter(new FileWriter(impliedDotFile));
boolean hasImplied = DotFormatter.getInstance().writeAllRelationships(tables, true, out).wroteImplied();
stats = new WriteStats(exclusions, includeImpliedConstraints);
DotFormatter.getInstance().writeAllRelationships(tables, true, stats, out);
boolean hasImplied = stats.wroteImplied();
Set excludedColumns = stats.getExcludedColumns();
stats = new WriteStats(stats);
out.close();
if (hasImplied) {
impliedDotFile = new File(graphsDir, dotBaseFilespec + ".implied.large.dot");
out = new LineWriter(new FileWriter(impliedDotFile));
DotFormatter.getInstance().writeAllRelationships(tables, false, out);
DotFormatter.getInstance().writeAllRelationships(tables, false, stats, out);
stats = new WriteStats(stats);
out.close();
} else {
impliedDotFile.delete();
}

out = new LineWriter(new FileWriter(new File(outputDir, dotBaseFilespec + ".html")));
hasRelationships = HtmlGraphFormatter.getInstance().write(db, graphsDir, dotBaseFilespec, hasOrphans, hasImplied, out);
hasRelationships = HtmlGraphFormatter.getInstance().write(db, graphsDir, dotBaseFilespec, hasOrphans, hasImplied, excludedColumns, out);
out.close();
}

System.out.print(".");
dotBaseFilespec = "utilities";
out = new LineWriter(new FileWriter(new File(outputDir, dotBaseFilespec + ".html")));
HtmlGraphFormatter.getInstance().writeOrphans(db, orphans, hasRelationships, graphsDir, out);
stats = new WriteStats(stats);
out.close();

System.out.print(".");
out = new LineWriter(new FileWriter(new File(outputDir, "index.html")), 64 * 1024);
HtmlMainIndexFormatter.getInstance().write(db, tables, hasRelationships, hasOrphans, out);
stats = new WriteStats(stats);
out.close();

System.out.print(".");
List constraints = DBAnalyzer.getForeignKeyConstraints(tables);
out = new LineWriter(new FileWriter(new File(outputDir, "constraints.html")), 256 * 1024);
HtmlConstraintIndexFormatter constraintIndexFormatter = HtmlConstraintIndexFormatter.getInstance();
constraintIndexFormatter.write(db, constraints, tables, hasRelationships, hasOrphans, out);
stats = new WriteStats(stats);
out.close();

System.out.print(".");
out = new LineWriter(new FileWriter(new File(outputDir, "anomalies.html")), 16 * 1024);
HtmlAnomaliesFormatter.getInstance().write(db, tables, impliedConstraints, hasRelationships, hasOrphans, out);
stats = new WriteStats(stats);
out.close();

System.out.print(".");
out = new LineWriter(new FileWriter(new File(outputDir, "columns.html")), 16 * 1024);
HtmlColumnsFormatter.getInstance().write(db, tables, hasRelationships, hasOrphans, out);
stats = new WriteStats(stats);
out.close();


Expand All @@ -236,7 +258,8 @@ public static void main(String[] argv) {
System.out.print('.');
Table table = (Table)iter.next();
out = new LineWriter(new FileWriter(new File(outputDir, "tables/" + table.getName() + ".html")), 24 * 1024);
tableFormatter.write(db, table, hasRelationships, hasOrphans, outputDir, out);
tableFormatter.write(db, table, hasRelationships, hasOrphans, outputDir, stats, out);
stats = new WriteStats(stats);
out.close();

// XmlTableFormatter.getInstance().appendTable(schemaNode, table, outputDir);
Expand Down Expand Up @@ -533,6 +556,8 @@ private static void dumpUsage(String errorMessage, boolean detailed, boolean det
System.out.println(" -dbthreads max concurrent threads when accessing metadata");
System.out.println(" defaults to -1 (no limit)");
System.out.println(" use 1 if you get 'already closed' type errors");
System.out.println(" -i columnNamesRegex ignore matching columns during analysis");
System.out.println(" e.g.: -i \"(book.isbn)|(borrower.address)\"");
System.out.println(" -nohtml defaults to generate html");
System.out.println(" -noimplied defaults to generate implied relationships");
System.out.println(" -nologo don't put SourceForge logo on generated pages");
Expand Down
7 changes: 6 additions & 1 deletion src/net/sourceforge/schemaspy/model/Table.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.sql.*;
import java.util.*;

public class Table {
public class Table implements Comparable {
private final String schema;
private final String name;
private final Map columns = new HashMap();
Expand Down Expand Up @@ -579,6 +579,11 @@ public boolean isOrphan(boolean withImpliedRelationships) {
return true;
}

public int compareTo(Object o) {
Table table = (Table)o;
return getName().compareTo(table.getName());
}

private static class ByIndexColumnComparator implements Comparator {
public int compare(Object object1, Object object2) {
TableColumn column1 = (TableColumn)object1;
Expand Down
5 changes: 5 additions & 0 deletions src/net/sourceforge/schemaspy/model/TableColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.*;
import java.util.*;
import java.util.regex.*;

public class TableColumn {
private final Table table;
Expand Down Expand Up @@ -195,6 +196,10 @@ public void setIsAutoUpdated(boolean isAutoUpdated) {
this.isAutoUpdated = isAutoUpdated;
}

public boolean matches(Pattern regex) {
return regex.matcher(getTable().getName() + "." + getName()).matches();
}

public String toString() {
return getName();
}
Expand Down
74 changes: 39 additions & 35 deletions src/net/sourceforge/schemaspy/view/DotConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
* @author John Currier
*/
public class DotConnector implements Comparable {
private TableColumn parentColumn;
private Table parentTable;
private TableColumn childColumn;
private Table childTable;
private final TableColumn parentColumn;
private final Table parentTable;
private final TableColumn childColumn;
private final Table childTable;
private boolean implied;
private boolean bottomJustify;
private String parentPort;
private String childPort;
private boolean blurred;

/**
* Create an edge that logically connects a child column to a parent column.
Expand Down Expand Up @@ -68,27 +69,23 @@ public void connectToChildTitle() {
public String toString() {
StringBuffer edge = new StringBuffer();
edge.append(" \"");
if (childTable != null) {
edge.append(childTable.getName());
edge.append("\":\"");
edge.append(childPort);
}
edge.append(childTable.getName());
edge.append("\":\"");
edge.append(childPort);
edge.append("\":");
if (bottomJustify)
edge.append("s");
edge.append("w -> \"");
if (parentTable != null) {
edge.append(parentTable.getName());
edge.append("\":\"");
edge.append(parentPort);
}
edge.append(parentTable.getName());
edge.append("\":\"");
edge.append(parentPort);
edge.append("\":");
if (bottomJustify)
edge.append("s");
edge.append("e ");

edge.append("[arrowtail=");
if (childPort.endsWith(".heading")) {
if (blurred || childPort.endsWith(".heading")) {
edge.append("none");
} else {
if (!childColumn.isUnique())
Expand All @@ -101,30 +98,23 @@ public String toString() {
edge.append(" arrowhead=none");
if (implied)
edge.append(" style=dashed");
if (blurred)
edge.append(" color=\"" + StyleSheet.getInstance().getOutlierBackgroundColor() + "\"");
edge.append("];");
return edge.toString();
}

public int compareTo(Object o) {
DotConnector other = (DotConnector)o;
int rc = childTable == null ? -1 : (other.childTable == null ? 1 : 0);
if (rc == 0)
rc = childTable.getName().compareTo(other.childTable.getName());
int rc = childTable.getName().compareTo(other.childTable.getName());
if (rc == 0)
rc = childColumn.getName().compareTo(other.childColumn.getName());
if (rc == 0)
rc = parentTable == null ? -1 : (other.parentTable == null ? 1 : 0);
if (rc == 0)
rc = parentTable.getName().compareTo(other.parentTable.getName());
if (rc == 0)
rc = parentColumn.getName().compareTo(other.parentColumn.getName());
if (rc == 0 && implied != other.implied)
rc = implied ? 1 : -1;
// if (rc == 0)
// rc = parentPort.compareTo(other.parentPort);
// if (rc == 0)
// rc = childPort.compareTo(other.childPort);

return rc;
}

Expand All @@ -140,23 +130,37 @@ public int hashCode() {
return (p << 16) & c;
}

/**
* stubMissingTables
*
* @param tablesWritten Set
*/
public void stubMissingTables(Set tables) {
if (!tables.contains(parentTable))
parentTable = null;
if (!tables.contains(childTable))
childTable = null;
public TableColumn getParentColumn() {
return parentColumn;
}

public Table getParentTable() {
return parentTable;
}

public TableColumn getChildColumn() {
return childColumn;
}

public Table getChildTable() {
return childTable;
}

/**
* setBlurred
*
* @param blurred boolean
*/
public void setBlurred(boolean blurred) {
this.blurred = blurred;
}

// this doesn't belong here, but not sure where...TableColumn shouldn't be dealing with this
static boolean isExcluded(TableColumn column, WriteStats stats) {
if (column.matches(stats.getExclusionPattern())) {
stats.addExcludedColumn(column);
return true;
}
return false;
}
}
Loading

0 comments on commit f6970ab

Please sign in to comment.