Skip to content

Commit

Permalink
If more than half of the tables have the same primary key then it's m…
Browse files Browse the repository at this point in the history
…ost likely a database where primary key names aren't unique
  • Loading branch information
johncurrier committed May 21, 2005
1 parent 9a04f85 commit 6d06ca4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/net/sourceforge/schemaspy/DBAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ public int compare(Object object1, Object object2) {
}
});

int duplicatePrimaries = 0;

// gather all the primary key columns and columns without parents
for (Iterator iter = tables.iterator(); iter.hasNext(); ) {
Table table = (Table)iter.next();
List tablePrimaries = table.getPrimaryColumns();
if (tablePrimaries.size() == 1) { // can't match up multiples...yet...
for (Iterator primariesIter = tablePrimaries.iterator(); primariesIter.hasNext(); ) {
allPrimaries.put(primariesIter.next(), table);
if (allPrimaries.put(primariesIter.next(), table) != null)
++duplicatePrimaries;
}
}

Expand All @@ -48,6 +51,12 @@ public int compare(Object object1, Object object2) {
}
}

// if more than half of the tables have the same primary key then
// it's most likey a database where primary key names aren't unique
// (e.g. they all have a primary key named 'ID')
if (duplicatePrimaries > allPrimaries.size())
return new ArrayList();

sortColumnsByTable(columnsWithoutParents);

List impliedConstraints = new ArrayList();
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/schemaspy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ else if (maxThreads == 0)
StyleSheet.write(out);
out.close();
out = new LineWriter(new FileWriter(new File(outputDir, "schemaSpy.js")));
new JavaScriptFormatter().write(out);
JavaScriptFormatter.write(out);
out.close();

startSummarizing = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package net.sourceforge.schemaspy.model;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.io.*;
import java.sql.*;

public class ImpliedForeignKeyConstraint extends ForeignKeyConstraint implements Serializable {
public ImpliedForeignKeyConstraint(TableColumn parentColumn, TableColumn childColumn) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net.sourceforge.schemaspy.util.LineWriter;

public class JavaScriptFormatter {
public void write(LineWriter out) throws IOException {
public static void write(LineWriter out) throws IOException {
out.writeln("function toggle(styleIndex) {");
out.writeln(" var rules = document.styleSheets[0].cssRules;");
out.writeln(" if (rules == null) rules = document.styleSheets[0].rules;");
Expand Down

0 comments on commit 6d06ca4

Please sign in to comment.