From 2ed7637abe4353fed8764d8936196ac9f9c5e3bd Mon Sep 17 00:00:00 2001 From: johncurrier Date: Tue, 12 Dec 2006 00:19:45 +0000 Subject: [PATCH] Consistency between DB and Db --- src/net/sourceforge/schemaspy/Config.java | 5 +- src/net/sourceforge/schemaspy/DBAnalyzer.java | 648 +++++++++--------- .../schemaspy/MultipleSchemaAnalyzer.java | 2 +- .../sourceforge/schemaspy/SchemaAnalyzer.java | 47 +- .../schemaspy/view/HtmlAnomaliesPage.java | 10 +- .../schemaspy/view/HtmlConstraintsPage.java | 2 +- 6 files changed, 358 insertions(+), 356 deletions(-) mode change 100755 => 100644 src/net/sourceforge/schemaspy/DBAnalyzer.java diff --git a/src/net/sourceforge/schemaspy/Config.java b/src/net/sourceforge/schemaspy/Config.java index 906ba2a..027447d 100644 --- a/src/net/sourceforge/schemaspy/Config.java +++ b/src/net/sourceforge/schemaspy/Config.java @@ -87,6 +87,9 @@ public Config(String[] argv) } public static Config getInstance() { + if (instance == null) + instance = new Config(); + return instance; } @@ -871,7 +874,7 @@ protected void dumpUsage(String errorMessage, boolean detailedDb) { Set datatypes = getBuiltInDatabaseTypes(getLoadedFromJar()); for (Iterator iter = datatypes.iterator(); iter.hasNext(); ) { String dbType = iter.next().toString(); - new ConnectionURLBuilder(dbType).dumpUsage(); + new DbSpecificConfig(dbType).dumpUsage(); } System.out.println(); } diff --git a/src/net/sourceforge/schemaspy/DBAnalyzer.java b/src/net/sourceforge/schemaspy/DBAnalyzer.java old mode 100755 new mode 100644 index 50b07d1..3c31a8f --- a/src/net/sourceforge/schemaspy/DBAnalyzer.java +++ b/src/net/sourceforge/schemaspy/DBAnalyzer.java @@ -1,324 +1,324 @@ -package net.sourceforge.schemaspy; - -import java.sql.*; -import java.util.*; -import java.util.regex.*; -import net.sourceforge.schemaspy.model.*; - -public class DBAnalyzer { - public static List getImpliedConstraints(Collection tables) throws SQLException { - List columnsWithoutParents = new ArrayList(); - Map allPrimaries = new TreeMap(new Comparator() { - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; - int rc = column1.getName().compareTo(column2.getName()); - if (rc == 0) - rc = column1.getType().compareTo(column2.getType()); - if (rc == 0) - rc = column1.getLength() - column2.getLength(); - return rc; - } - }); - - 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(); ) { - if (allPrimaries.put(primariesIter.next(), table) != null) - ++duplicatePrimaries; - } - } - - for (Iterator columnIter = table.getColumns().iterator(); columnIter.hasNext(); ) { - TableColumn column = (TableColumn)columnIter.next(); - if (column.getParents().isEmpty()) - columnsWithoutParents.add(column); - } - } - - // 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()) // bizarre logic, but it does approximately what we need - return new ArrayList(); - - sortColumnsByTable(columnsWithoutParents); - - List impliedConstraints = new ArrayList(); - for (Iterator iter = columnsWithoutParents.iterator(); iter.hasNext(); ) { - TableColumn childColumn = (TableColumn)iter.next(); - Table primaryTable = (Table)allPrimaries.get(childColumn); - if (primaryTable != null && primaryTable != childColumn.getTable()) { - TableColumn parentColumn = primaryTable.getColumn(childColumn.getName()); - // make sure the potential child->parent relationships isn't already a - // parent->child relationship - if (parentColumn.getParentConstraint(childColumn) == null) { - // ok, we've found a potential relationship with a column matches a primary - // key column in another table and isn't already related to that column - impliedConstraints.add(new ImpliedForeignKeyConstraint(parentColumn, childColumn)); - } - } - } - - return impliedConstraints; - } - - /** - * Returns a List of all of the ForeignKeyConstraints - * used by the specified tables. - * - * @param tables Collection - * @return List - */ - public static List getForeignKeyConstraints(Collection tables) { - List constraints = new ArrayList(); - Iterator iter = tables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); - constraints.addAll(table.getForeignKeys()); - } - - return constraints; - } - - public static List getOrphans(Collection tables) { - List orphans = new ArrayList(); - - Iterator iter = tables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); - if (table.isOrphan(false)) { - orphans.add(table); - } - } - - return sortTablesByName(orphans); - } - - /** - * Return a list of TableColumns that are both nullable - * and have an index that specifies that they must be unique (a rather strange combo). - */ - public static List getMustBeUniqueNullableColumns(Collection tables) { - List uniqueNullables = new ArrayList(); - - for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { - Table table = (Table)tablesIter.next(); - for (Iterator indexesIter = table.getIndexes().iterator(); indexesIter.hasNext(); ) { - TableIndex index = (TableIndex)indexesIter.next(); - if (index.isUniqueNullable()) { - uniqueNullables.addAll(index.getColumns()); - } - } - } - - return sortColumnsByTable(uniqueNullables); - } - - /** - * Return a list of Tables that have neither an index nor a primary key. - */ - public static List getTablesWithoutIndexes(Collection tables) { - List withoutIndexes = new ArrayList(); - - for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { - Table table = (Table)tablesIter.next(); - if (!table.isView() && table.getIndexes().size() == 0) - withoutIndexes.add(table); - } - - return sortTablesByName(withoutIndexes); - } - - public static List getTablesWithIncrementingColumnNames(Collection tables) { - List denormalizedTables = new ArrayList(); - - Iterator tableIter = tables.iterator(); - while (tableIter.hasNext()) { - Table table = (Table)tableIter.next(); - Map columnPrefixes = new HashMap(); - - Iterator columnIter = table.getColumns().iterator(); - while (columnIter.hasNext()) { - // search for columns that start with the same prefix - // and end in an incrementing number - TableColumn column = (TableColumn)columnIter.next(); - - String columnName = column.getName(); - String numbers = null; - for (int i = columnName.length() - 1; i > 0; --i) { - if (Character.isDigit(columnName.charAt(i))) { - numbers = String.valueOf(columnName.charAt(i)) + (numbers == null ? "" : numbers); - } else { - break; - } - } - - // attempt to detect where they had an existing column - // and added a "column2" type of column (we'll call this one "1") - if (numbers == null) { - numbers = "1"; - columnName = columnName + numbers; - } - - // see if we've already found a column with the same prefix - // that had a numeric suffix +/- 1. - String prefix = columnName.substring(0, columnName.length() - numbers.length()); - long numeric = Long.parseLong(numbers); - Long existing = (Long)columnPrefixes.get(prefix); - if (existing != null && Math.abs(existing.longValue() - numeric) == 1) { - // found one so add it to our list and stop evaluating this table - denormalizedTables.add(table); - break; - } - columnPrefixes.put(prefix, new Long(numeric)); - } - } - - return sortTablesByName(denormalizedTables); - } - - public static List getTablesWithOneColumn(Collection tables) { - List singleColumnTables = new ArrayList(); - - Iterator iter = tables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); - if (table.getColumns().size() == 1) - singleColumnTables.add(table); - } - - return sortTablesByName(singleColumnTables); - } - - public static List sortTablesByName(List tables) { - Collections.sort(tables, new Comparator() { - public int compare(Object object1, Object object2) { - return ((Table)object1).getName().compareTo(((Table)object2).getName()); - } - }); - - return tables; - } - - public static List sortColumnsByTable(List columns) { - Collections.sort(columns, new Comparator() { - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; - int rc = column1.getTable().getName().compareTo(column2.getTable().getName()); - if (rc == 0) - rc = column1.getName().compareTo(column2.getName()); - return rc; - } - }); - - return columns; - } - - /** - * Returns a list of columns that have the word "NULL" or "null" as their default value - * instead of the likely candidate value null. - * - * @param tables Collection - * @return List - */ - public static List getDefaultNullStringColumns(Collection tables) { - List defaultNullStringColumns = new ArrayList(); - - for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { - Table table = (Table)tablesIter.next(); - for (Iterator columnsIter = table.getColumns().iterator(); columnsIter.hasNext(); ) { - TableColumn column = (TableColumn)columnsIter.next(); - Object defaultValue = column.getDefaultValue(); - if (defaultValue != null && defaultValue instanceof String) { - String defaultString = defaultValue.toString(); - if (defaultString.trim().equalsIgnoreCase("null")) { - defaultNullStringColumns.add(column); - } - } - } - } - - return sortColumnsByTable(defaultNullStringColumns); - } - - /** - * getSchemas - returns a List of schema names (Strings) - * - * @param meta DatabaseMetaData - */ - public static List getSchemas(DatabaseMetaData meta) throws SQLException { - List schemas = new ArrayList(); - - ResultSet rs = meta.getSchemas(); - while (rs.next()) { - schemas.add(rs.getString("TABLE_SCHEM")); - } - rs.close(); - - return schemas; - } - - /** - * getSchemas - returns a List of schema names (Strings) that contain tables - * - * @param meta DatabaseMetaData - */ - public static List getPopulatedSchemas(DatabaseMetaData meta) throws SQLException { - return getPopulatedSchemas(meta, ".*"); - } - - /** - * getSchemas - returns a List of schema names (Strings) that contain tables and - * match the schemaSpec regular expression - * - * @param meta DatabaseMetaData - */ - public static List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec) throws SQLException { - Set schemas = new TreeSet(); // alpha sorted - Pattern schemaRegex = Pattern.compile(schemaSpec); - - Iterator iter = getSchemas(meta).iterator(); - while (iter.hasNext()) { - String schema = iter.next().toString(); - if (schemaRegex.matcher(schema).matches()) { - ResultSet rs = null; - try { - rs = meta.getTables(null, schema, "%", null); - if (rs.next()) - schemas.add(schema); - } catch (SQLException ignore) { - } finally { - if (rs != null) - rs.close(); - } - } - } - - return new ArrayList(schemas); - } - - /** - * For debugging/analyzing result sets - * @param rs ResultSet - * @throws SQLException - */ - public static void dumpResultSetRow(ResultSet rs, String description) throws SQLException { - ResultSetMetaData meta = rs.getMetaData(); - int numColumns = meta.getColumnCount(); - System.out.println(numColumns + " columns of " + description + ":"); - for (int i = 1; i <= numColumns; ++i) { - System.out.print(meta.getColumnLabel(i)); - System.out.print(": "); - System.out.print(String.valueOf(rs.getString(i))); - System.out.print("\t"); - } - System.out.println(); - } -} +package net.sourceforge.schemaspy; + +import java.sql.*; +import java.util.*; +import java.util.regex.*; +import net.sourceforge.schemaspy.model.*; + +public class DbAnalyzer { + public static List getImpliedConstraints(Collection tables) throws SQLException { + List columnsWithoutParents = new ArrayList(); + Map allPrimaries = new TreeMap(new Comparator() { + public int compare(Object object1, Object object2) { + TableColumn column1 = (TableColumn)object1; + TableColumn column2 = (TableColumn)object2; + int rc = column1.getName().compareTo(column2.getName()); + if (rc == 0) + rc = column1.getType().compareTo(column2.getType()); + if (rc == 0) + rc = column1.getLength() - column2.getLength(); + return rc; + } + }); + + 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(); ) { + if (allPrimaries.put(primariesIter.next(), table) != null) + ++duplicatePrimaries; + } + } + + for (Iterator columnIter = table.getColumns().iterator(); columnIter.hasNext(); ) { + TableColumn column = (TableColumn)columnIter.next(); + if (column.getParents().isEmpty()) + columnsWithoutParents.add(column); + } + } + + // 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()) // bizarre logic, but it does approximately what we need + return new ArrayList(); + + sortColumnsByTable(columnsWithoutParents); + + List impliedConstraints = new ArrayList(); + for (Iterator iter = columnsWithoutParents.iterator(); iter.hasNext(); ) { + TableColumn childColumn = (TableColumn)iter.next(); + Table primaryTable = (Table)allPrimaries.get(childColumn); + if (primaryTable != null && primaryTable != childColumn.getTable()) { + TableColumn parentColumn = primaryTable.getColumn(childColumn.getName()); + // make sure the potential child->parent relationships isn't already a + // parent->child relationship + if (parentColumn.getParentConstraint(childColumn) == null) { + // ok, we've found a potential relationship with a column matches a primary + // key column in another table and isn't already related to that column + impliedConstraints.add(new ImpliedForeignKeyConstraint(parentColumn, childColumn)); + } + } + } + + return impliedConstraints; + } + + /** + * Returns a List of all of the ForeignKeyConstraints + * used by the specified tables. + * + * @param tables Collection + * @return List + */ + public static List getForeignKeyConstraints(Collection tables) { + List constraints = new ArrayList(); + Iterator iter = tables.iterator(); + while (iter.hasNext()) { + Table table = (Table)iter.next(); + constraints.addAll(table.getForeignKeys()); + } + + return constraints; + } + + public static List getOrphans(Collection tables) { + List orphans = new ArrayList(); + + Iterator iter = tables.iterator(); + while (iter.hasNext()) { + Table table = (Table)iter.next(); + if (table.isOrphan(false)) { + orphans.add(table); + } + } + + return sortTablesByName(orphans); + } + + /** + * Return a list of TableColumns that are both nullable + * and have an index that specifies that they must be unique (a rather strange combo). + */ + public static List getMustBeUniqueNullableColumns(Collection tables) { + List uniqueNullables = new ArrayList(); + + for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { + Table table = (Table)tablesIter.next(); + for (Iterator indexesIter = table.getIndexes().iterator(); indexesIter.hasNext(); ) { + TableIndex index = (TableIndex)indexesIter.next(); + if (index.isUniqueNullable()) { + uniqueNullables.addAll(index.getColumns()); + } + } + } + + return sortColumnsByTable(uniqueNullables); + } + + /** + * Return a list of Tables that have neither an index nor a primary key. + */ + public static List getTablesWithoutIndexes(Collection tables) { + List withoutIndexes = new ArrayList(); + + for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { + Table table = (Table)tablesIter.next(); + if (!table.isView() && table.getIndexes().size() == 0) + withoutIndexes.add(table); + } + + return sortTablesByName(withoutIndexes); + } + + public static List getTablesWithIncrementingColumnNames(Collection tables) { + List denormalizedTables = new ArrayList(); + + Iterator tableIter = tables.iterator(); + while (tableIter.hasNext()) { + Table table = (Table)tableIter.next(); + Map columnPrefixes = new HashMap(); + + Iterator columnIter = table.getColumns().iterator(); + while (columnIter.hasNext()) { + // search for columns that start with the same prefix + // and end in an incrementing number + TableColumn column = (TableColumn)columnIter.next(); + + String columnName = column.getName(); + String numbers = null; + for (int i = columnName.length() - 1; i > 0; --i) { + if (Character.isDigit(columnName.charAt(i))) { + numbers = String.valueOf(columnName.charAt(i)) + (numbers == null ? "" : numbers); + } else { + break; + } + } + + // attempt to detect where they had an existing column + // and added a "column2" type of column (we'll call this one "1") + if (numbers == null) { + numbers = "1"; + columnName = columnName + numbers; + } + + // see if we've already found a column with the same prefix + // that had a numeric suffix +/- 1. + String prefix = columnName.substring(0, columnName.length() - numbers.length()); + long numeric = Long.parseLong(numbers); + Long existing = (Long)columnPrefixes.get(prefix); + if (existing != null && Math.abs(existing.longValue() - numeric) == 1) { + // found one so add it to our list and stop evaluating this table + denormalizedTables.add(table); + break; + } + columnPrefixes.put(prefix, new Long(numeric)); + } + } + + return sortTablesByName(denormalizedTables); + } + + public static List getTablesWithOneColumn(Collection tables) { + List singleColumnTables = new ArrayList(); + + Iterator iter = tables.iterator(); + while (iter.hasNext()) { + Table table = (Table)iter.next(); + if (table.getColumns().size() == 1) + singleColumnTables.add(table); + } + + return sortTablesByName(singleColumnTables); + } + + public static List sortTablesByName(List tables) { + Collections.sort(tables, new Comparator() { + public int compare(Object object1, Object object2) { + return ((Table)object1).getName().compareTo(((Table)object2).getName()); + } + }); + + return tables; + } + + public static List sortColumnsByTable(List columns) { + Collections.sort(columns, new Comparator() { + public int compare(Object object1, Object object2) { + TableColumn column1 = (TableColumn)object1; + TableColumn column2 = (TableColumn)object2; + int rc = column1.getTable().getName().compareTo(column2.getTable().getName()); + if (rc == 0) + rc = column1.getName().compareTo(column2.getName()); + return rc; + } + }); + + return columns; + } + + /** + * Returns a list of columns that have the word "NULL" or "null" as their default value + * instead of the likely candidate value null. + * + * @param tables Collection + * @return List + */ + public static List getDefaultNullStringColumns(Collection tables) { + List defaultNullStringColumns = new ArrayList(); + + for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { + Table table = (Table)tablesIter.next(); + for (Iterator columnsIter = table.getColumns().iterator(); columnsIter.hasNext(); ) { + TableColumn column = (TableColumn)columnsIter.next(); + Object defaultValue = column.getDefaultValue(); + if (defaultValue != null && defaultValue instanceof String) { + String defaultString = defaultValue.toString(); + if (defaultString.trim().equalsIgnoreCase("null")) { + defaultNullStringColumns.add(column); + } + } + } + } + + return sortColumnsByTable(defaultNullStringColumns); + } + + /** + * getSchemas - returns a List of schema names (Strings) + * + * @param meta DatabaseMetaData + */ + public static List getSchemas(DatabaseMetaData meta) throws SQLException { + List schemas = new ArrayList(); + + ResultSet rs = meta.getSchemas(); + while (rs.next()) { + schemas.add(rs.getString("TABLE_SCHEM")); + } + rs.close(); + + return schemas; + } + + /** + * getSchemas - returns a List of schema names (Strings) that contain tables + * + * @param meta DatabaseMetaData + */ + public static List getPopulatedSchemas(DatabaseMetaData meta) throws SQLException { + return getPopulatedSchemas(meta, ".*"); + } + + /** + * getSchemas - returns a List of schema names (Strings) that contain tables and + * match the schemaSpec regular expression + * + * @param meta DatabaseMetaData + */ + public static List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec) throws SQLException { + Set schemas = new TreeSet(); // alpha sorted + Pattern schemaRegex = Pattern.compile(schemaSpec); + + Iterator iter = getSchemas(meta).iterator(); + while (iter.hasNext()) { + String schema = iter.next().toString(); + if (schemaRegex.matcher(schema).matches()) { + ResultSet rs = null; + try { + rs = meta.getTables(null, schema, "%", null); + if (rs.next()) + schemas.add(schema); + } catch (SQLException ignore) { + } finally { + if (rs != null) + rs.close(); + } + } + } + + return new ArrayList(schemas); + } + + /** + * For debugging/analyzing result sets + * @param rs ResultSet + * @throws SQLException + */ + public static void dumpResultSetRow(ResultSet rs, String description) throws SQLException { + ResultSetMetaData meta = rs.getMetaData(); + int numColumns = meta.getColumnCount(); + System.out.println(numColumns + " columns of " + description + ":"); + for (int i = 1; i <= numColumns; ++i) { + System.out.print(meta.getColumnLabel(i)); + System.out.print(": "); + System.out.print(String.valueOf(rs.getString(i))); + System.out.print("\t"); + } + System.out.println(); + } +} diff --git a/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java b/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java index 6e8f6b5..8a1ee31 100755 --- a/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java +++ b/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java @@ -99,7 +99,7 @@ private List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec, Strin if (meta.supportsSchemasInTableDefinitions()) { Pattern schemaRegex = Pattern.compile(schemaSpec); - populatedSchemas = DBAnalyzer.getPopulatedSchemas(meta, schemaSpec); + populatedSchemas = DbAnalyzer.getPopulatedSchemas(meta, schemaSpec); Iterator iter = populatedSchemas.iterator(); while (iter.hasNext()) { String schema = iter.next().toString(); diff --git a/src/net/sourceforge/schemaspy/SchemaAnalyzer.java b/src/net/sourceforge/schemaspy/SchemaAnalyzer.java index ff36550..e531ec1 100644 --- a/src/net/sourceforge/schemaspy/SchemaAnalyzer.java +++ b/src/net/sourceforge/schemaspy/SchemaAnalyzer.java @@ -7,7 +7,6 @@ import javax.xml.parsers.*; import net.sourceforge.schemaspy.model.*; import net.sourceforge.schemaspy.util.*; -import net.sourceforge.schemaspy.util.ConnectionURLBuilder.*; import net.sourceforge.schemaspy.view.*; import org.w3c.dom.*; @@ -15,8 +14,8 @@ * @author John Currier */ public class SchemaAnalyzer { - public int analyze(Config config) throws Exception { - try { + public int analyze(Config config) throws Exception { + try { if (config.isHelpRequired()) { config.dumpUsage(null, false); return 1; @@ -51,7 +50,7 @@ public int analyze(Config config) throws Exception { Connection connection = getConnection(config, urlBuilder.getConnectionURL(), driverClass, driverPath); if (connection == null) - return 3; + return 3; DatabaseMetaData meta = connection.getMetaData(); String dbName = config.getDb(); @@ -62,10 +61,10 @@ public int analyze(Config config) throws Exception { List args = config.asList(); Iterator iter = urlBuilder.getOptions().iterator(); while (iter.hasNext()) { - DbOption option = (DbOption)iter.next(); - if (!args.contains("-" + option.name)) { - args.add("-" + option.name); - args.add(option.value); + DbSpecificOption option = (DbSpecificOption)iter.next(); + if (!args.contains("-" + option.getName())) { + args.add("-" + option.getName()); + args.add(option.getValue()); } } @@ -151,11 +150,11 @@ public int analyze(Config config) throws Exception { // here unless they want that behavior List impliedConstraints = null; if (includeImpliedConstraints) - impliedConstraints = DBAnalyzer.getImpliedConstraints(tables); + impliedConstraints = DbAnalyzer.getImpliedConstraints(tables); else impliedConstraints = new ArrayList(); - List orphans = DBAnalyzer.getOrphans(tables); + List orphans = DbAnalyzer.getOrphans(tables); boolean hasOrphans = !orphans.isEmpty() && Dot.getInstance().isValid(); System.out.print("."); @@ -196,7 +195,7 @@ public int analyze(Config config) throws Exception { out.close(); System.out.print("."); - List constraints = DBAnalyzer.getForeignKeyConstraints(tables); + List constraints = DbAnalyzer.getForeignKeyConstraints(tables); out = new LineWriter(new FileWriter(new File(outputDir, "constraints.html")), 256 * 1024); HtmlConstraintsPage constraintIndexFormatter = HtmlConstraintsPage.getInstance(); constraintIndexFormatter.write(db, constraints, tables, hasOrphans, out); @@ -313,7 +312,7 @@ public int analyze(Config config) throws Exception { config.dumpUsage(missingParam.getMessage(), missingParam.isDbTypeSpecific()); return 1; } - } + } /** * dumpNoDataMessage @@ -326,7 +325,7 @@ private static void dumpNoTablesMessage(String schema, String user, DatabaseMeta System.out.println(); System.out.println(); System.out.println("No tables or views were found in schema '" + schema + "'."); - List schemas = DBAnalyzer.getSchemas(meta); + List schemas = DbAnalyzer.getSchemas(meta); if (schema == null || schemas.contains(schema)) { System.out.println("The schema exists in the database, but the user you specified (" + user + ')'); System.out.println(" might not have rights to read its contents."); @@ -353,7 +352,7 @@ private static void dumpNoTablesMessage(String schema, String user, DatabaseMeta System.out.println(); System.out.println("These schemas contain tables/views that user '" + user + "' can see:"); System.out.println(); - iter = DBAnalyzer.getPopulatedSchemas(meta).iterator(); + iter = DbAnalyzer.getPopulatedSchemas(meta).iterator(); while (iter.hasNext()) { System.out.print(iter.next() + " "); } @@ -365,14 +364,14 @@ private static Connection getConnection(Config config, String connectionURL, System.out.println(" " + config.getDbPropertiesLoadedFrom()); List classpath = new ArrayList(); - List invalidClasspathEntries = new ArrayList(); + List invalidClasspathEntries = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(driverPath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { File pathElement = new File(tokenizer.nextToken()); if (pathElement.exists()) classpath.add(pathElement.toURL()); else - invalidClasspathEntries.add(pathElement); + invalidClasspathEntries.add(pathElement); } URLClassLoader loader = new URLClassLoader((URL[])classpath.toArray(new URL[0])); @@ -386,13 +385,13 @@ private static Connection getConnection(Config config, String connectionURL, System.err.println(exc); // people don't want to see a stack trace... System.err.println(); System.err.println("Failed to load driver '" + driverClass + "' from: " + classpath); - if (!invalidClasspathEntries.isEmpty()) { - if (invalidClasspathEntries.size() == 1) - System.err.print("This entry doesn't point to a valid file/directory: "); - else - System.err.print("These entries don't point to valid files/directories: "); - System.err.println(invalidClasspathEntries); - } + if (!invalidClasspathEntries.isEmpty()) { + if (invalidClasspathEntries.size() == 1) + System.err.print("This entry doesn't point to a valid file/directory: "); + else + System.err.print("These entries don't point to valid files/directories: "); + System.err.println(invalidClasspathEntries); + } System.err.println(); System.err.println("Use -t [databaseType] to specify what drivers to use or modify"); System.err.println("one of the .properties from the jar, put it on your file"); @@ -400,7 +399,7 @@ private static Connection getConnection(Config config, String connectionURL, System.err.println(); System.err.println("For many people it's easiest to use the -cp option to directly specify"); System.err.println("where the database drivers exist (usually in a .jar or .zip/.Z)."); - System.err.println("Note that the -cp option must be specified AFTER " + Config.getLoadedFromJar()); + System.err.println("Note that the -cp option must be specified AFTER " + Config.getLoadedFromJar()); System.err.println(); return null; } diff --git a/src/net/sourceforge/schemaspy/view/HtmlAnomaliesPage.java b/src/net/sourceforge/schemaspy/view/HtmlAnomaliesPage.java index b9b776e..adb09cd 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlAnomaliesPage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlAnomaliesPage.java @@ -23,11 +23,11 @@ public static HtmlAnomaliesPage getInstance() { public void write(Database database, Collection tables, List impliedConstraints, boolean hasOrphans, LineWriter out) throws IOException { writeHeader(database, hasOrphans, out); writeImpliedConstraints(impliedConstraints, out); - writeTablesWithoutIndexes(DBAnalyzer.getTablesWithoutIndexes(new HashSet(tables)), out); - writeUniqueNullables(DBAnalyzer.getMustBeUniqueNullableColumns(new HashSet(tables)), out); - writeTablesWithOneColumn(DBAnalyzer.getTablesWithOneColumn(tables), out); - writeTablesWithIncrementingColumnNames(DBAnalyzer.getTablesWithIncrementingColumnNames(tables), out); - writeDefaultNullStrings(DBAnalyzer.getDefaultNullStringColumns(new HashSet(tables)), out); + writeTablesWithoutIndexes(DbAnalyzer.getTablesWithoutIndexes(new HashSet(tables)), out); + writeUniqueNullables(DbAnalyzer.getMustBeUniqueNullableColumns(new HashSet(tables)), out); + writeTablesWithOneColumn(DbAnalyzer.getTablesWithOneColumn(tables), out); + writeTablesWithIncrementingColumnNames(DbAnalyzer.getTablesWithIncrementingColumnNames(tables), out); + writeDefaultNullStrings(DbAnalyzer.getDefaultNullStringColumns(new HashSet(tables)), out); writeFooter(out); } diff --git a/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java b/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java index 69cfa18..a72296e 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java @@ -154,7 +154,7 @@ public void writeCheckConstraints(Collection tables, LineWriter html) throws IOE html.writeln(""); html.writeln(""); - List tablesByName = DBAnalyzer.sortTablesByName(new ArrayList(tables)); + List tablesByName = DbAnalyzer.sortTablesByName(new ArrayList(tables)); int constraintsWritten = 0;