diff --git a/src/net/sourceforge/schemaspy/Config.java b/src/net/sourceforge/schemaspy/Config.java index 5e69540..701d4f8 100644 --- a/src/net/sourceforge/schemaspy/Config.java +++ b/src/net/sourceforge/schemaspy/Config.java @@ -16,9 +16,9 @@ public class Config { private static Config instance; - private List options; - private Map dbSpecificOptions; - private Map originalDbSpecificOptions; + private List options; + private Map dbSpecificOptions; + private Map originalDbSpecificOptions; private boolean helpRequired; private boolean dbHelpRequired; private File outputDir; @@ -66,7 +66,7 @@ public Config() { if (instance == null) setInstance(this); - options = new ArrayList(); + options = new ArrayList(); } /** @@ -733,7 +733,7 @@ protected String getDbPropertiesLoadedFrom() throws IOException { return dbPropertiesLoadedFrom; } - public List getRemainingParameters() + public List getRemainingParameters() { try { populate(); @@ -748,14 +748,14 @@ public List getRemainingParameters() * * @param dbSpecificOptions */ - public void setDbSpecificOptions(Map dbSpecificOptions) { + public void setDbSpecificOptions(Map dbSpecificOptions) { this.dbSpecificOptions = dbSpecificOptions; - this.originalDbSpecificOptions = new HashMap(dbSpecificOptions); + this.originalDbSpecificOptions = new HashMap(dbSpecificOptions); } - public Map getDbSpecificOptions() { + public Map getDbSpecificOptions() { if (dbSpecificOptions == null) - dbSpecificOptions = new HashMap(); + dbSpecificOptions = new HashMap(); return dbSpecificOptions; } @@ -830,11 +830,10 @@ public boolean isDbTypeSpecific() { * List * @return List */ - protected List fixupArgs(List args) { - List expandedArgs = new ArrayList(); + protected List fixupArgs(List args) { + List expandedArgs = new ArrayList(); - for (Iterator iter = args.iterator(); iter.hasNext(); ) { - String arg = iter.next().toString(); + for (String arg : args) { int indexOfEquals = arg.indexOf('='); if (indexOfEquals != -1 && indexOfEquals -1 != arg.indexOf("\\=")) { expandedArgs.add(arg.substring(0, indexOfEquals)); @@ -847,10 +846,9 @@ protected List fixupArgs(List args) { // some OSes/JVMs do filename expansion with runtime.exec() and some don't, // so MultipleSchemaAnalyzer has to surround params with double quotes... // strip them here for the OSes/JVMs that don't do anything with the params - List unquotedArgs = new ArrayList(); + List unquotedArgs = new ArrayList(); - for (Iterator iter = expandedArgs.iterator(); iter.hasNext(); ) { - String arg = iter.next().toString(); + for (String arg : expandedArgs) { if (arg.startsWith("\"") && arg.endsWith("\"")) // ".*" becomes .* arg = arg.substring(1, arg.length() - 1); unquotedArgs.add(arg); @@ -876,15 +874,15 @@ private void populate() throws IllegalArgumentException, IllegalAccessException, for (int i = 0; i < props.length; ++i) { Method readMethod = props[i].getReadMethod(); if (readMethod != null) - readMethod.invoke(this, null); + readMethod.invoke(this, (Object[])null); } populating = false; } } - public static Set getBuiltInDatabaseTypes(String loadedFromJar) { - Set databaseTypes = new TreeSet(); + public static Set getBuiltInDatabaseTypes(String loadedFromJar) { + Set databaseTypes = new TreeSet(); JarInputStream jar = null; try { @@ -970,7 +968,7 @@ public String getParam(String paramName) { for (int i = 0; i < props.length; ++i) { PropertyDescriptor prop = props[i]; if (prop.getName().equalsIgnoreCase(paramName)) { - Object result = prop.getReadMethod().invoke(this, null); + Object result = prop.getReadMethod().invoke(this, (Object[])null); return result == null ? null : result.toString(); } } @@ -988,8 +986,8 @@ public String getParam(String paramName) { * @return * @throws IOException */ - public List asList() throws IOException { - List list = new ArrayList(); + public List asList() throws IOException { + List list = new ArrayList(); if (originalDbSpecificOptions != null) { Iterator iter = originalDbSpecificOptions.keySet().iterator(); @@ -1088,7 +1086,7 @@ public List asList() throws IOException { list.add("-maxdet"); list.add(String.valueOf(getMaxDetailedTables())); list.add("-o"); - list.add(getOutputDir()); + list.add(getOutputDir().toString()); return list; } diff --git a/src/net/sourceforge/schemaspy/DbAnalyzer.java b/src/net/sourceforge/schemaspy/DbAnalyzer.java index 169ba0f..1cf385c 100644 --- a/src/net/sourceforge/schemaspy/DbAnalyzer.java +++ b/src/net/sourceforge/schemaspy/DbAnalyzer.java @@ -6,12 +6,10 @@ 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; + public static List getImpliedConstraints(Collection tables) throws SQLException { + List columnsWithoutParents = new ArrayList(); + Map allPrimaries = new TreeMap(new Comparator() { + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getName().compareTo(column2.getName()); if (rc == 0) rc = column1.getType().compareTo(column2.getType()); @@ -24,12 +22,11 @@ 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(); + for (Table table : tables) { + 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) + for (TableColumn primary : tablePrimaries) { + if (allPrimaries.put(primary, table) != null) ++duplicatePrimaries; } } @@ -45,14 +42,14 @@ public int compare(Object object1, Object object2) { // 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(); + return new ArrayList(); sortColumnsByTable(columnsWithoutParents); - List impliedConstraints = new ArrayList(); + List impliedConstraints = new ArrayList(); for (Iterator iter = columnsWithoutParents.iterator(); iter.hasNext(); ) { TableColumn childColumn = (TableColumn)iter.next(); - Table primaryTable = (Table)allPrimaries.get(childColumn); + Table primaryTable = 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 @@ -75,23 +72,20 @@ public int compare(Object object1, Object object2) { * @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(); + public static List getForeignKeyConstraints(Collection
tables) { + List constraints = new ArrayList(); + + for (Table table : tables) { constraints.addAll(table.getForeignKeys()); } return constraints; } - public static List getOrphans(Collection tables) { - List orphans = new ArrayList(); + public static List
getOrphans(Collection
tables) { + List
orphans = new ArrayList
(); - Iterator iter = tables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + for (Table table : tables) { if (table.isOrphan(false)) { orphans.add(table); } @@ -104,13 +98,11 @@ public static List getOrphans(Collection tables) { * 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(); + 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(); + for (Table table : tables) { + for (TableIndex index : table.getIndexes()) { if (index.isUniqueNullable()) { uniqueNullables.addAll(index.getColumns()); } @@ -123,11 +115,10 @@ public static List getMustBeUniqueNullableColumns(Collection tables) { /** * Return a list of Tables that have neither an index nor a primary key. */ - public static List getTablesWithoutIndexes(Collection tables) { - List withoutIndexes = new ArrayList(); + public static List
getTablesWithoutIndexes(Collection
tables) { + List
withoutIndexes = new ArrayList
(); - for (Iterator tablesIter = tables.iterator(); tablesIter.hasNext(); ) { - Table table = (Table)tablesIter.next(); + for (Table table : tables) { if (!table.isView() && table.getIndexes().size() == 0) withoutIndexes.add(table); } @@ -135,19 +126,15 @@ public static List getTablesWithoutIndexes(Collection tables) { return sortTablesByName(withoutIndexes); } - public static List getTablesWithIncrementingColumnNames(Collection tables) { - List denormalizedTables = new ArrayList(); + 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(); + for (Table table : tables) { + Map columnPrefixes = new HashMap(); - Iterator columnIter = table.getColumns().iterator(); - while (columnIter.hasNext()) { + for (TableColumn column : table.getColumns()) { // 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; @@ -170,7 +157,7 @@ public static List getTablesWithIncrementingColumnNames(Collection tables) { // 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); + Long existing = 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); @@ -183,12 +170,10 @@ public static List getTablesWithIncrementingColumnNames(Collection tables) { return sortTablesByName(denormalizedTables); } - public static List getTablesWithOneColumn(Collection tables) { - List singleColumnTables = new ArrayList(); + public static List
getTablesWithOneColumn(Collection
tables) { + List
singleColumnTables = new ArrayList
(); - Iterator iter = tables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + for (Table table : tables) { if (table.getColumns().size() == 1) singleColumnTables.add(table); } @@ -196,21 +181,19 @@ public static List getTablesWithOneColumn(Collection tables) { 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()); + public static List
sortTablesByName(List
tables) { + Collections.sort(tables, new Comparator
() { + public int compare(Table table1, Table table2) { + return table1.getName().compareTo(table2.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; + public static List sortColumnsByTable(List columns) { + Collections.sort(columns, new Comparator() { + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getTable().getName().compareTo(column2.getTable().getName()); if (rc == 0) rc = column1.getName().compareTo(column2.getName()); @@ -228,13 +211,11 @@ public int compare(Object object1, Object object2) { * @param tables Collection * @return List */ - public static List getDefaultNullStringColumns(Collection tables) { - List defaultNullStringColumns = new ArrayList(); + 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(); + for (Table table : tables) { + for (TableColumn column : table.getColumns()) { Object defaultValue = column.getDefaultValue(); if (defaultValue != null && defaultValue instanceof String) { String defaultString = defaultValue.toString(); @@ -253,8 +234,8 @@ public static List getDefaultNullStringColumns(Collection tables) { * * @param meta DatabaseMetaData */ - public static List getSchemas(DatabaseMetaData meta) throws SQLException { - List schemas = new ArrayList(); + public static List getSchemas(DatabaseMetaData meta) throws SQLException { + List schemas = new ArrayList(); ResultSet rs = meta.getSchemas(); while (rs.next()) { @@ -280,11 +261,11 @@ public static List getPopulatedSchemas(DatabaseMetaData meta) throws SQLExceptio * * @param meta DatabaseMetaData */ - public static List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec) throws SQLException { - Set schemas = new TreeSet(); // alpha sorted + 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(); + Iterator iter = getSchemas(meta).iterator(); while (iter.hasNext()) { String schema = iter.next().toString(); if (schemaRegex.matcher(schema).matches()) { @@ -301,7 +282,7 @@ public static List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec) } } - return new ArrayList(schemas); + return new ArrayList(schemas); } /** diff --git a/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java b/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java index 5e3a005..3c91705 100755 --- a/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java +++ b/src/net/sourceforge/schemaspy/MultipleSchemaAnalyzer.java @@ -22,7 +22,7 @@ public static MultipleSchemaAnalyzer getInstance() { public int analyze(String dbName, DatabaseMetaData meta, String schemaSpec, List args, String user, File outputDir, String charset, String loadedFrom) throws SQLException, IOException { long start = System.currentTimeMillis(); - List genericCommand = new ArrayList(); + List genericCommand = new ArrayList(); genericCommand.add("java"); genericCommand.add("-Doneofmultipleschemas=true"); if (new File(loadedFrom).isDirectory()) { @@ -53,14 +53,14 @@ public int analyze(String dbName, DatabaseMetaData meta, String schemaSpec, List for (Iterator iter = populatedSchemas.iterator(); iter.hasNext(); ) { String schema = iter.next().toString(); - List command = new ArrayList(genericCommand); + List command = new ArrayList(genericCommand); command.add("-s"); command.add(schema); command.add("-o"); command.add(new File(outputDir, schema).toString()); System.out.println("Analyzing " + schema); System.out.flush(); - Process java = Runtime.getRuntime().exec((String[])command.toArray(new String[]{})); + Process java = Runtime.getRuntime().exec(command.toArray(new String[]{})); new ProcessOutputReader(java.getInputStream(), System.out).start(); new ProcessOutputReader(java.getErrorStream(), System.err).start(); @@ -93,8 +93,8 @@ private void writeIndexPage(String dbName, List populatedSchemas, DatabaseMetaDa } } - private List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec, String user) throws SQLException { - List populatedSchemas; + private List getPopulatedSchemas(DatabaseMetaData meta, String schemaSpec, String user) throws SQLException { + List populatedSchemas; if (meta.supportsSchemasInTableDefinitions()) { Pattern schemaRegex = Pattern.compile(schemaSpec); diff --git a/src/net/sourceforge/schemaspy/SchemaAnalyzer.java b/src/net/sourceforge/schemaspy/SchemaAnalyzer.java index b25acb5..4d3afd7 100644 --- a/src/net/sourceforge/schemaspy/SchemaAnalyzer.java +++ b/src/net/sourceforge/schemaspy/SchemaAnalyzer.java @@ -63,13 +63,11 @@ public int analyze(Config config) throws Exception { } if (config.isEvaluateAllEnabled()) { - List args = config.asList(); - Iterator iter = urlBuilder.getOptions().iterator(); - while (iter.hasNext()) { - DbSpecificOption option = (DbSpecificOption)iter.next(); + List args = config.asList(); + for (DbSpecificOption option : urlBuilder.getOptions()) { if (!args.contains("-" + option.getName())) { args.add("-" + option.getName()); - args.add(option.getValue()); + args.add(option.getValue().toString()); } } @@ -105,7 +103,7 @@ public int analyze(Config config) throws Exception { Database db = spy.getDatabase(); LineWriter out; - Collection tables = new ArrayList(db.getTables()); + Collection
tables = new ArrayList
(db.getTables()); tables.addAll(db.getViews()); if (tables.isEmpty()) { @@ -154,13 +152,13 @@ public int analyze(Config config) throws Exception { // getting implied constraints has a side-effect of associating the parent/child tables, so don't do it // here unless they want that behavior - List impliedConstraints = null; + List impliedConstraints = null; if (includeImpliedConstraints) impliedConstraints = DbAnalyzer.getImpliedConstraints(tables); else - impliedConstraints = new ArrayList(); + impliedConstraints = new ArrayList(); - List orphans = DbAnalyzer.getOrphans(tables); + List
orphans = DbAnalyzer.getOrphans(tables); boolean hasOrphans = !orphans.isEmpty() && Dot.getInstance().isValid(); System.out.print("."); @@ -201,7 +199,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 File(outputDir, "constraints.html"), 256 * 1024, config.getCharset()); HtmlConstraintsPage constraintIndexFormatter = HtmlConstraintsPage.getInstance(); constraintIndexFormatter.write(db, constraints, tables, hasOrphans, out); @@ -271,11 +269,11 @@ public int analyze(Config config) throws Exception { rootNode = null; urlBuilder = null; - List recursiveConstraints = new ArrayList(); + List recursiveConstraints = new ArrayList(); // side effect is that the RI relationships get trashed // also populates the recursiveConstraints collection - List orderedTables = spy.sortTablesByRI(recursiveConstraints); + List
orderedTables = spy.sortTablesByRI(recursiveConstraints); out = new LineWriter(new File(outputDir, "insertionOrder.txt"), 16 * 1024, Config.DOT_CHARSET); TextFormatter.getInstance().write(orderedTables, false, out); @@ -369,8 +367,8 @@ private static Connection getConnection(Config config, String connectionURL, System.out.println("Using database properties:"); System.out.println(" " + config.getDbPropertiesLoadedFrom()); - List classpath = new ArrayList(); - List invalidClasspathEntries = new ArrayList(); + List classpath = new ArrayList(); + List invalidClasspathEntries = new ArrayList(); StringTokenizer tokenizer = new StringTokenizer(driverPath, File.pathSeparator); while (tokenizer.hasMoreTokens()) { File pathElement = new File(tokenizer.nextToken()); @@ -380,7 +378,7 @@ private static Connection getConnection(Config config, String connectionURL, invalidClasspathEntries.add(pathElement); } - URLClassLoader loader = new URLClassLoader((URL[])classpath.toArray(new URL[classpath.size()])); + URLClassLoader loader = new URLClassLoader(classpath.toArray(new URL[classpath.size()])); Driver driver = null; try { driver = (Driver)Class.forName(driverClass, true, loader).newInstance(); diff --git a/src/net/sourceforge/schemaspy/SchemaSpy.java b/src/net/sourceforge/schemaspy/SchemaSpy.java index fedf194..a7e7f5b 100755 --- a/src/net/sourceforge/schemaspy/SchemaSpy.java +++ b/src/net/sourceforge/schemaspy/SchemaSpy.java @@ -25,11 +25,11 @@ public Database getDatabase() { * @param recursiveConstraints * @return */ - public List sortTablesByRI(Collection recursiveConstraints) { - List heads = new ArrayList(); - List tails = new ArrayList(); - List remainingTables = new ArrayList(getDatabase().getTables()); - List unattached = new ArrayList(); + public List
sortTablesByRI(Collection recursiveConstraints) { + List
heads = new ArrayList
(); + List
tails = new ArrayList
(); + List
remainingTables = new ArrayList
(getDatabase().getTables()); + List
unattached = new ArrayList
(); // first pass to gather the 'low hanging fruit' for (Iterator iter = remainingTables.iterator(); iter.hasNext(); ) { @@ -62,13 +62,11 @@ public List sortTablesByRI(Collection recursiveConstraints) { if (!foundSimpleRecursion) { // expensive comparison, but we're down to the end of the tables so it shouldn't really matter - Set byParentChildDelta = new TreeSet(new Comparator() { + Set
byParentChildDelta = new TreeSet
(new Comparator
() { // sort on the delta between number of parents and kids so we can // target the tables with the biggest delta and therefore the most impact // on reducing the smaller of the two - public int compare(Object object1, Object object2) { - Table table1 = (Table)object1; - Table table2 = (Table)object2; + public int compare(Table table1, Table table2) { int rc = Math.abs(table2.getNumChildren() - table2.getNumParents()) - Math.abs(table1.getNumChildren() - table1.getNumParents()); if (rc == 0) rc = table1.getName().compareTo(table2.getName()); @@ -76,7 +74,7 @@ public int compare(Object object1, Object object2) { } }); byParentChildDelta.addAll(remainingTables); - Table recursiveTable = (Table)byParentChildDelta.iterator().next(); // this one has the largest delta + Table recursiveTable = byParentChildDelta.iterator().next(); // this one has the largest delta ForeignKeyConstraint removedConstraint = recursiveTable.removeAForeignKeyConstraint(); recursiveConstraints.add(removedConstraint); } @@ -84,27 +82,25 @@ public int compare(Object object1, Object object2) { } // we've gathered all the heads and tails, so combine them here moving 'unattached' tables to the end - List ordered = new ArrayList(heads.size() + tails.size()); - for (Iterator iter = heads.iterator(); iter.hasNext(); ) - ordered.add(iter.next()); - heads = null; // allow gc ASAP + List
ordered = new ArrayList
(heads.size() + tails.size()); - for (Iterator iter = tails.iterator(); iter.hasNext(); ) - ordered.add(iter.next()); + ordered.addAll(heads); + heads = null; // allow gc ASAP + + ordered.addAll(tails); tails = null; // allow gc ASAP - - for (Iterator iter = unattached.iterator(); iter.hasNext(); ) - ordered.add(iter.next()); + + ordered.addAll(unattached); return ordered; } - private static List trimRoots(List tables) { - List roots = new ArrayList(); + private static List
trimRoots(List
tables) { + List
roots = new ArrayList
(); - Iterator iter = tables.iterator(); + Iterator
iter = tables.iterator(); while (iter.hasNext()) { - Table root = (Table)iter.next(); + Table root = iter.next(); if (root.isRoot()) { roots.add(root); iter.remove(); @@ -117,18 +113,18 @@ private static List trimRoots(List tables) { while (iter.hasNext()) { // do this after the previous loop to prevent getting roots before they're ready // and so we can sort them correctly - ((Table)iter.next()).unlinkChildren(); + iter.next().unlinkChildren(); } return roots; } - private static List trimLeaves(List tables) { - List leaves = new ArrayList(); + private static List
trimLeaves(List
tables) { + List
leaves = new ArrayList
(); - Iterator iter = tables.iterator(); + Iterator
iter = tables.iterator(); while (iter.hasNext()) { - Table leaf = (Table)iter.next(); + Table leaf = iter.next(); if (leaf.isLeaf()) { leaves.add(leaf); iter.remove(); @@ -141,7 +137,7 @@ private static List trimLeaves(List tables) { while (iter.hasNext()) { // do this after the previous loop to prevent getting leaves before they're ready // and so we can sort them correctly - ((Table)iter.next()).unlinkParents(); + iter.next().unlinkParents(); } return leaves; @@ -150,7 +146,7 @@ private static List trimLeaves(List tables) { /** * this doesn't change the logical output of the program because all of these (leaves or roots) are at the same logical level */ - private static List sortTrimmedLevel(List tables) { + private static List
sortTrimmedLevel(List
tables) { /** * order by *
    @@ -159,10 +155,8 @@ private static List sortTrimmedLevel(List tables) { *
  • alpha name (ascending) *
*/ - final class TrimComparator implements Comparator { - public int compare(Object object1, Object object2) { - Table table1 = (Table)object1; - Table table2 = (Table)object2; + final class TrimComparator implements Comparator
{ + public int compare(Table table1, Table table2) { // have to keep track of and use the 'max' versions because // by the time we get here we'll (probably?) have no parents or children int rc = table2.getMaxChildren() - table1.getMaxChildren(); @@ -174,8 +168,8 @@ public int compare(Object object1, Object object2) { } } - Set sorter = new TreeSet(new TrimComparator()); + Set
sorter = new TreeSet
(new TrimComparator()); sorter.addAll(tables); - return new ArrayList(sorter); + return new ArrayList
(sorter); } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/model/Database.java b/src/net/sourceforge/schemaspy/model/Database.java index 70ea03b..fb0ff6e 100755 --- a/src/net/sourceforge/schemaspy/model/Database.java +++ b/src/net/sourceforge/schemaspy/model/Database.java @@ -11,13 +11,13 @@ public class Database { private final String databaseName; private final String schema; private final String description; - private final Map tables = new CaseInsensitiveMap(); - private final Map views = new CaseInsensitiveMap(); - private final Map remoteTables = new CaseInsensitiveMap(); // key: schema.tableName value: RemoteTable + private final Map tables = new CaseInsensitiveMap
(); + private final Map views = new CaseInsensitiveMap(); + private final Map remoteTables = new CaseInsensitiveMap
(); // key: schema.tableName value: RemoteTable private final DatabaseMetaData meta; private final Connection connection; private final String connectTime = new SimpleDateFormat("EEE MMM dd HH:mm z yyyy").format(new Date()); - private Set sqlKeywords; + private Set sqlKeywords; private Pattern invalidIdentifierPattern; public Database(Connection connection, DatabaseMetaData meta, String name, String schema, String description, Properties properties, Pattern include, int maxThreads) throws SQLException, MissingResourceException { @@ -46,15 +46,15 @@ public String getDescription() { return description; } - public Collection getTables() { + public Collection
getTables() { return tables.values(); } - public Collection getViews() { + public Collection getViews() { return views.values(); } - public Collection getRemoteTables() { + public Collection
getRemoteTables() { return remoteTables.values(); } @@ -170,7 +170,7 @@ private void initCheckConstraints(Properties properties) throws SQLException { while (rs.next()) { String tableName = rs.getString("table_name"); - Table table = (Table)tables.get(tableName); + Table table = tables.get(tableName); if (table != null) table.addCheckConstraint(rs.getString("constraint_name"), rs.getString("text")); } @@ -200,7 +200,7 @@ private void initTableIds(Properties properties) throws SQLException { while (rs.next()) { String tableName = rs.getString("table_name"); - Table table = (Table)tables.get(tableName); + Table table = tables.get(tableName); if (table != null) table.setId(rs.getObject("table_id")); } @@ -229,7 +229,7 @@ private void initIndexIds(Properties properties) throws SQLException { while (rs.next()) { String tableName = rs.getString("table_name"); - Table table = (Table)tables.get(tableName); + Table table = tables.get(tableName); if (table != null) { TableIndex index = table.getIndex(rs.getString("index_name")); if (index != null) @@ -261,7 +261,7 @@ private void initTableComments(Properties properties) throws SQLException { while (rs.next()) { String tableName = rs.getString("table_name"); - Table table = (Table)tables.get(tableName); + Table table = tables.get(tableName); if (table != null) table.setComments(rs.getString("comments")); } @@ -291,7 +291,7 @@ private void initColumnComments(Properties properties) throws SQLException { while (rs.next()) { String tableName = rs.getString("table_name"); - Table table = (Table)tables.get(tableName); + Table table = tables.get(tableName); if (table != null) { TableColumn column = table.getColumn(rs.getString("column_name")); if (column != null) @@ -327,7 +327,7 @@ private void initColumnComments(Properties properties) throws SQLException { */ public PreparedStatement prepareStatement(String sql, String tableName) throws SQLException { StringBuffer sqlBuf = new StringBuffer(sql); - List sqlParams = getSqlParams(sqlBuf, tableName); // modifies sqlBuf + List sqlParams = getSqlParams(sqlBuf, tableName); // modifies sqlBuf PreparedStatement stmt = getConnection().prepareStatement(sqlBuf.toString()); try { @@ -344,7 +344,7 @@ public PreparedStatement prepareStatement(String sql, String tableName) throws S public Table addRemoteTable(String remoteSchema, String remoteTableName, String baseSchema, Properties properties) throws SQLException { String fullName = remoteSchema + "." + remoteTableName; - Table remoteTable = (Table)remoteTables.get(fullName); + Table remoteTable = remoteTables.get(fullName); if (remoteTable == null) { remoteTable = new RemoteTable(this, remoteSchema, remoteTableName, baseSchema, properties); remoteTable.connectForeignKeys(tables, this, properties); @@ -360,7 +360,7 @@ public Table addRemoteTable(String remoteSchema, String remoteTableName, String * @return * @throws SQLException */ - public Set getSqlKeywords() throws SQLException { + public Set getSqlKeywords() throws SQLException { if (sqlKeywords == null) { // from http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt: String[] sql92Keywords = @@ -429,7 +429,7 @@ public Set getSqlKeywords() throws SQLException { String[] nonSql92Keywords = getMetaData().getSQLKeywords().toUpperCase().split(",\\s*"); - sqlKeywords = new HashSet(); + sqlKeywords = new HashSet(); sqlKeywords.addAll(Arrays.asList(sql92Keywords)); sqlKeywords.addAll(Arrays.asList(nonSql92Keywords)); } @@ -486,8 +486,8 @@ private Pattern getInvalidIdentifierPattern() throws SQLException { * * @see #prepareStatement(String, String) */ - private List getSqlParams(StringBuffer sql, String tableName) { - Map namedParams = new HashMap(); + private List getSqlParams(StringBuffer sql, String tableName) { + Map namedParams = new HashMap(); String schema = getSchema(); if (schema == null) schema = getName(); // some 'schema-less' db's treat the db name like a schema (unusual case) @@ -498,11 +498,11 @@ private List getSqlParams(StringBuffer sql, String tableName) { namedParams.put(":view", tableName); // alias for :table } - List sqlParams = new ArrayList(); + List sqlParams = new ArrayList(); int nextColon = sql.indexOf(":"); while (nextColon != -1) { String paramName = new StringTokenizer(sql.substring(nextColon), " ,").nextToken(); - String paramValue = (String)namedParams.get(paramName); + String paramValue = namedParams.get(paramName); if (paramValue == null) throw new IllegalArgumentException("Unexpected named parameter '" + paramName + "' found in SQL '" + sql + "'"); sqlParams.add(paramValue); @@ -526,7 +526,7 @@ private void initViews(String schema, DatabaseMetaData metadata, Properties prop System.out.print('.'); try { - Table view = new View(this, rs, properties.getProperty("selectViewSql")); + View view = new View(this, rs, properties.getProperty("selectViewSql")); if (include.matcher(view.getName()).matches()) views.put(view.getName(), view); @@ -546,9 +546,9 @@ private void initViews(String schema, DatabaseMetaData metadata, Properties prop } private void connectTables(Properties properties) throws SQLException { - Iterator iter = tables.values().iterator(); + Iterator
iter = tables.values().iterator(); while (iter.hasNext()) { - Table table = (Table)iter.next(); + Table table = iter.next(); table.connectForeignKeys(tables, this, properties); } } @@ -582,7 +582,7 @@ void join() { * Multi-threaded implementation of a class that creates tables */ private class ThreadedTableCreator extends TableCreator { - private final Set threads = new HashSet(); + private final Set threads = new HashSet(); private final int maxThreads; ThreadedTableCreator(int maxThreads) { @@ -628,11 +628,11 @@ public void join() { Thread thread; synchronized (threads) { - Iterator iter = threads.iterator(); + Iterator iter = threads.iterator(); if (!iter.hasNext()) break; - thread = (Thread)iter.next(); + thread = iter.next(); } try { diff --git a/src/net/sourceforge/schemaspy/model/ForeignKeyConstraint.java b/src/net/sourceforge/schemaspy/model/ForeignKeyConstraint.java index 599cf3e..8389efa 100755 --- a/src/net/sourceforge/schemaspy/model/ForeignKeyConstraint.java +++ b/src/net/sourceforge/schemaspy/model/ForeignKeyConstraint.java @@ -6,9 +6,9 @@ public class ForeignKeyConstraint { private final String name; private Table parentTable; - private final List parentColumns = new ArrayList(); + private final List parentColumns = new ArrayList(); private final Table childTable; - private final List childColumns = new ArrayList(); + private final List childColumns = new ArrayList(); private final char deleteRule; private final char updateRule; @@ -42,7 +42,7 @@ public Table getParentTable() { return parentTable; } - public List getParentColumns() { + public List getParentColumns() { return Collections.unmodifiableList(parentColumns); } @@ -50,7 +50,7 @@ public Table getChildTable() { return childTable; } - public List getChildColumns() { + public List getChildColumns() { return Collections.unmodifiableList(childColumns); } @@ -80,7 +80,7 @@ public boolean isImplied() { * @param columns * @return */ - public static String toString(List columns) { + public static String toString(List columns) { if (columns.size() == 1) return columns.iterator().next().toString(); return columns.toString(); diff --git a/src/net/sourceforge/schemaspy/model/Table.java b/src/net/sourceforge/schemaspy/model/Table.java index fd543b0..7806e66 100755 --- a/src/net/sourceforge/schemaspy/model/Table.java +++ b/src/net/sourceforge/schemaspy/model/Table.java @@ -5,15 +5,15 @@ import net.sourceforge.schemaspy.*; import net.sourceforge.schemaspy.util.*; -public class Table implements Comparable { +public class Table implements Comparable
{ private final String schema; private final String name; - protected final CaseInsensitiveMap columns = new CaseInsensitiveMap(); - private final List primaryKeys = new ArrayList(); - private final CaseInsensitiveMap foreignKeys = new CaseInsensitiveMap(); - private final CaseInsensitiveMap indexes = new CaseInsensitiveMap(); + protected final CaseInsensitiveMap columns = new CaseInsensitiveMap(); + private final List primaryKeys = new ArrayList(); + private final CaseInsensitiveMap foreignKeys = new CaseInsensitiveMap(); + private final CaseInsensitiveMap indexes = new CaseInsensitiveMap(); private Object id; - private final Map checkConstraints = new TreeMap(new ByCheckConstraintStringsComparator()); + private final Map checkConstraints = new TreeMap(new ByCheckConstraintStringsComparator()); private final int numRows; private String comments; private int maxChildren; @@ -62,10 +62,10 @@ public void connectForeignKeys(Map tables, Database db, Properties properties) t } public ForeignKeyConstraint getForeignKey(String keyName) { - return (ForeignKeyConstraint)foreignKeys.get(keyName); + return foreignKeys.get(keyName); } - public Collection getForeignKeys() { + public Collection getForeignKeys() { return Collections.unmodifiableCollection(foreignKeys.values()); } @@ -320,7 +320,7 @@ private boolean initIndexes(Database db, String selectIndexesSql) { } public TableIndex getIndex(String indexName) { - return (TableIndex)indexes.get(indexName); + return indexes.get(indexName); } private void addIndex(ResultSet rs) throws SQLException { @@ -356,15 +356,15 @@ public Object getId() { return id; } - public Map getCheckConstraints() { + public Map getCheckConstraints() { return checkConstraints; } - public Set getIndexes() { - return new HashSet(indexes.values()); + public Set getIndexes() { + return new HashSet(indexes.values()); } - public List getPrimaryColumns() { + public List getPrimaryColumns() { return Collections.unmodifiableList(primaryKeys); } @@ -380,17 +380,17 @@ public void setComments(String comments) { } public TableColumn getColumn(String columnName) { - return (TableColumn)columns.get(columnName); + return columns.get(columnName); } /** * Returns List of TableColumns in ascending column number order. * @return */ - public List getColumns() { - Set sorted = new TreeSet(new ByIndexColumnComparator()); + public List getColumns() { + Set sorted = new TreeSet(new ByIndexColumnComparator()); sorted.addAll(columns.values()); - return new ArrayList(sorted); + return new ArrayList(sorted); } public int getMaxParents() { @@ -450,8 +450,8 @@ public ForeignKeyConstraint removeSelfReferencingConstraint() { if (recursiveConstraint != null) { // more drastic removal solution by Remke Rutgers: for (int i = 0; i < recursiveConstraint.getChildColumns().size(); i++) { - TableColumn childColumn = (TableColumn)recursiveConstraint.getChildColumns().get(i); - TableColumn parentColumn = (TableColumn)recursiveConstraint.getParentColumns().get(i); + TableColumn childColumn = recursiveConstraint.getChildColumns().get(i); + TableColumn parentColumn = recursiveConstraint.getParentColumns().get(i); childColumn.removeParent(parentColumn); parentColumn.removeChild(childColumn); } @@ -462,10 +462,8 @@ public ForeignKeyConstraint removeSelfReferencingConstraint() { } private ForeignKeyConstraint getSelfReferencingConstraint() { - for (Iterator columnIter = getColumns().iterator(); columnIter.hasNext(); ) { - TableColumn column = (TableColumn)columnIter.next(); - for (Iterator parentColumnIter = column.getParents().iterator(); parentColumnIter.hasNext(); ) { - TableColumn parentColumn = (TableColumn)parentColumnIter.next(); + for (TableColumn column : getColumns()) { + for (TableColumn parentColumn : column.getParents()) { if (parentColumn.getTable().getName().equals(getName())) { return column.getParentConstraint(parentColumn); } @@ -661,7 +659,8 @@ protected int fetchNumRows(Database db, String clause, boolean forceQuotes) thro stmt.close(); } } - + + @Override public String toString() { return getName(); } @@ -695,15 +694,12 @@ public boolean isOrphan(boolean withImpliedRelationships) { return true; } - public int compareTo(Object o) { - Table table = (Table)o; + public int compareTo(Table table) { return getName().compareTo(table.getName()); } - private static class ByIndexColumnComparator implements Comparator { - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + private static class ByIndexColumnComparator implements Comparator { + public int compare(TableColumn column1, TableColumn column2) { if (column1.getId() == null || column2.getId() == null) return column1.getName().compareTo(column2.getName()); if (column1.getId() instanceof Number) @@ -712,9 +708,9 @@ public int compare(Object object1, Object object2) { } } - private static class ByCheckConstraintStringsComparator implements Comparator { - public int compare(Object object1, Object object2) { - return object1.toString().compareTo(object2.toString()); + private static class ByCheckConstraintStringsComparator implements Comparator { + public int compare(String string1, String string2) { + return string1.compareTo(string2); } } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/model/TableColumn.java b/src/net/sourceforge/schemaspy/model/TableColumn.java index d91ce64..f1467d7 100755 --- a/src/net/sourceforge/schemaspy/model/TableColumn.java +++ b/src/net/sourceforge/schemaspy/model/TableColumn.java @@ -16,8 +16,8 @@ public class TableColumn { private boolean isAutoUpdated; private final Object defaultValue; private String comments; - private final Map parents = new HashMap(); - private final Map children = new TreeMap(new ColumnComparator()); + private final Map parents = new HashMap(); + private final Map children = new TreeMap(new ColumnComparator()); /** * Create a column associated with a table. @@ -95,9 +95,7 @@ public boolean isAutoUpdated() { } public boolean isUnique() { - Iterator iter = table.getIndexes().iterator(); - while (iter.hasNext()) { - TableIndex index = (TableIndex)iter.next(); + for (TableIndex index : table.getIndexes()) { if (index.isUnique()) { List indexColumns = index.getColumns(); if (indexColumns.size() == 1 && indexColumns.contains(this)) { @@ -153,7 +151,7 @@ public void unlinkParents() { parents.clear(); } - public Set getParents() { + public Set getParents() { return parents.keySet(); } @@ -161,7 +159,7 @@ public Set getParents() { * returns the constraint that connects this column to the specified column (this 'child' column to specified 'parent' column) */ public ForeignKeyConstraint getParentConstraint(TableColumn parent) { - return (ForeignKeyConstraint)parents.get(parent); + return parents.get(parent); } /** @@ -169,9 +167,8 @@ public ForeignKeyConstraint getParentConstraint(TableColumn parent) { * @return */ public ForeignKeyConstraint removeAParentFKConstraint() { - for (Iterator iter = parents.keySet().iterator(); iter.hasNext(); ) { - TableColumn relatedColumn = (TableColumn)iter.next(); - ForeignKeyConstraint constraint = (ForeignKeyConstraint)parents.remove(relatedColumn); + for (TableColumn relatedColumn : parents.keySet()) { + ForeignKeyConstraint constraint = parents.remove(relatedColumn); relatedColumn.removeChild(this); return constraint; } @@ -180,9 +177,8 @@ public ForeignKeyConstraint removeAParentFKConstraint() { } public ForeignKeyConstraint removeAChildFKConstraint() { - for (Iterator iter = children.keySet().iterator(); iter.hasNext(); ) { - TableColumn relatedColumn = (TableColumn)iter.next(); - ForeignKeyConstraint constraint = (ForeignKeyConstraint)children.remove(relatedColumn); + for (TableColumn relatedColumn : children.keySet()) { + ForeignKeyConstraint constraint = children.remove(relatedColumn); relatedColumn.removeParent(this); return constraint; } @@ -200,10 +196,8 @@ public void removeChild(TableColumn child) { } public void unlinkChildren() { - for (Iterator iter = children.keySet().iterator(); iter.hasNext(); ) { - TableColumn child = (TableColumn)iter.next(); + for (TableColumn child : children.keySet()) child.removeParent(this); - } children.clear(); } @@ -212,7 +206,7 @@ public void unlinkChildren() { * references this TableColumn. * @return Set */ - public Set getChildren() { + public Set getChildren() { return children.keySet(); } @@ -221,7 +215,7 @@ public Set getChildren() { * (specified 'child' to this 'parent' column) */ public ForeignKeyConstraint getChildConstraint(TableColumn child) { - return (ForeignKeyConstraint)children.get(child); + return children.get(child); } /** @@ -241,10 +235,8 @@ public String toString() { return getName(); } - private class ColumnComparator implements Comparator { - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + private class ColumnComparator implements Comparator { + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getTable().getName().compareTo(column2.getTable().getName()); if (rc == 0) rc = column1.getName().compareTo(column2.getName()); diff --git a/src/net/sourceforge/schemaspy/model/TableIndex.java b/src/net/sourceforge/schemaspy/model/TableIndex.java index ae90ecc..ae1e058 100755 --- a/src/net/sourceforge/schemaspy/model/TableIndex.java +++ b/src/net/sourceforge/schemaspy/model/TableIndex.java @@ -8,8 +8,8 @@ public class TableIndex implements Comparable { private final boolean isUnique; private Object id; private boolean isPrimary; - private final List columns = new ArrayList(); - private final List columnsAscending = new ArrayList(); // Booleans for whether colums are ascending order + private final List columns = new ArrayList(); + private final List columnsAscending = new ArrayList(); // for whether colums are ascending order /** * @param rs @@ -86,7 +86,7 @@ public String getColumnsAsString() { return buf.toString(); } - public List getColumns() { + public List getColumns() { return Collections.unmodifiableList(columns); } @@ -115,7 +115,7 @@ public boolean isUniqueNullable() { * @return */ public boolean isAscending(TableColumn column) { - return ((Boolean)columnsAscending.get(columns.indexOf(column))).booleanValue(); + return columnsAscending.get(columns.indexOf(column)).booleanValue(); } /** diff --git a/src/net/sourceforge/schemaspy/ui/DbConfigTableModel.java b/src/net/sourceforge/schemaspy/ui/DbConfigTableModel.java index 9ad6af1..c7f7283 100644 --- a/src/net/sourceforge/schemaspy/ui/DbConfigTableModel.java +++ b/src/net/sourceforge/schemaspy/ui/DbConfigTableModel.java @@ -13,7 +13,7 @@ */ public class DbConfigTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; - private final List options = new ArrayList(); + private final List options = new ArrayList(); private Config config = Config.getInstance(); // the config associated with DbSpecificConfig public DbConfigTableModel() { @@ -111,20 +111,20 @@ public boolean isCellEditable(int row, int col) { if (col != 1) return false; - return ((PropertyDescriptor)options.get(row)).getWriteMethod() != null; + return options.get(row).getWriteMethod() != null; } /* (non-Javadoc) * @see javax.swing.table.TableModel#getValueAt(int, int) */ public Object getValueAt(int row, int column) { - PropertyDescriptor descriptor = (PropertyDescriptor)options.get(row); + PropertyDescriptor descriptor = options.get(row); switch (column) { case 0: return descriptor.getName(); case 1: try { - Object value = descriptor.getReadMethod().invoke(config, null); + Object value = descriptor.getReadMethod().invoke(config, (Object[])null); //System.out.println(descriptor.getReadMethod().getName() + ":'" + value + "' " + (value != null ? value.getClass().toString() : "")); return value; } catch (InvocationTargetException exc) { @@ -142,7 +142,7 @@ public Object getValueAt(int row, int column) { public void setValueAt(Object value, int row, int col) { Object oldValue = getValueAt(row, col); if (oldValue != value && (value == null || oldValue == null || !value.equals(oldValue))) { - PropertyDescriptor descriptor = (PropertyDescriptor)options.get(row); + PropertyDescriptor descriptor = options.get(row); try { //System.out.println(descriptor.getWriteMethod().getName() + ":'" + value + "' " + (value != null ? value.getClass().toString() : "")); if (value instanceof String && descriptor.getPropertyType().isAssignableFrom(Integer.class)) { @@ -167,7 +167,7 @@ public void setValueAt(Object value, int row, int col) { * @return */ public Class getClass(int row) { - PropertyDescriptor descriptor = (PropertyDescriptor)options.get(row); + PropertyDescriptor descriptor = options.get(row); return descriptor.getPropertyType(); } @@ -176,7 +176,7 @@ public Class getClass(int row) { * @return */ public String getDescription(int row) { - PropertyDescriptor descriptor = (PropertyDescriptor)options.get(row); + PropertyDescriptor descriptor = options.get(row); return descriptor.getShortDescription(); } } \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/ui/DbTypeSelectorModel.java b/src/net/sourceforge/schemaspy/ui/DbTypeSelectorModel.java index 38bfd3a..8347bfe 100644 --- a/src/net/sourceforge/schemaspy/ui/DbTypeSelectorModel.java +++ b/src/net/sourceforge/schemaspy/ui/DbTypeSelectorModel.java @@ -11,12 +11,12 @@ */ public class DbTypeSelectorModel extends AbstractListModel implements ComboBoxModel { private static final long serialVersionUID = 1L; - private List dbConfigs = new ArrayList(); + private List dbConfigs = new ArrayList(); private Object selected; public DbTypeSelectorModel(String defaultType) { Pattern pattern = Pattern.compile(".*/" + defaultType); - Set dbTypes = new TreeSet(Config.getBuiltInDatabaseTypes(Config.getLoadedFromJar())); + Set dbTypes = new TreeSet(Config.getBuiltInDatabaseTypes(Config.getLoadedFromJar())); for (Iterator iter = dbTypes.iterator(); iter.hasNext(); ) { String dbType = iter.next().toString(); DbSpecificConfig config = new DbSpecificConfig(dbType); diff --git a/src/net/sourceforge/schemaspy/util/CaseInsensitiveMap.java b/src/net/sourceforge/schemaspy/util/CaseInsensitiveMap.java index e2cdbcb..2c9f83f 100644 --- a/src/net/sourceforge/schemaspy/util/CaseInsensitiveMap.java +++ b/src/net/sourceforge/schemaspy/util/CaseInsensitiveMap.java @@ -11,31 +11,37 @@ * * @author John Currier */ -public class CaseInsensitiveMap extends HashMap +public class CaseInsensitiveMap extends HashMap { private static final long serialVersionUID = 1L; - public Object get(Object key) { + @Override + public V get(Object key) { return super.get(((String)key).toUpperCase()); } - public Object put(Object key, Object value) { - return super.put(((String)key).toUpperCase(), value); + @Override + public V put(String key, V value) { + return super.put(key.toUpperCase(), value); } - public void putAll(Map map) { + @Override + @SuppressWarnings("unchecked") // until I get the iter declaration correct + public void putAll(Map map) { Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { - Map.Entry entry = (Map.Entry)iter.next(); + Map.Entry entry = (Map.Entry)iter.next(); put(entry.getKey(), entry.getValue()); } } - public Object remove(Object key) { + @Override + public V remove(Object key) { return super.remove(((String)key).toUpperCase()); } + @Override public boolean containsKey(Object key) { return super.containsKey(((String)key).toUpperCase()); } diff --git a/src/net/sourceforge/schemaspy/util/ConnectionURLBuilder.java b/src/net/sourceforge/schemaspy/util/ConnectionURLBuilder.java index 8ef9bed..2ea4657 100755 --- a/src/net/sourceforge/schemaspy/util/ConnectionURLBuilder.java +++ b/src/net/sourceforge/schemaspy/util/ConnectionURLBuilder.java @@ -8,17 +8,16 @@ */ public class ConnectionURLBuilder { private final String connectionURL; - private List options; + private List options; /** * @param config * @param properties */ public ConnectionURLBuilder(Config config, Properties properties) { - List opts = new ArrayList(); - Iterator iter = config.getDbSpecificOptions().keySet().iterator(); - while (iter.hasNext()) { - String key = iter.next().toString(); + List opts = new ArrayList(); + + for (String key : config.getDbSpecificOptions().keySet()) { opts.add((key.startsWith("-") ? "" : "-") + key); opts.add(config.getDbSpecificOptions().get(key)); } @@ -28,10 +27,9 @@ public ConnectionURLBuilder(Config config, Properties properties) { options = dbConfig.getOptions(); connectionURL = buildUrl(opts, properties, config); - List remaining = config.getRemainingParameters(); - iter = options.iterator(); - while (iter.hasNext()) { - DbSpecificOption option = (DbSpecificOption)iter.next(); + List remaining = config.getRemainingParameters(); + + for (DbSpecificOption option : options) { int idx = remaining.indexOf("-" + option.getName()); if (idx >= 0) { remaining.remove(idx); // -paramKey @@ -43,9 +41,7 @@ public ConnectionURLBuilder(Config config, Properties properties) { private String buildUrl(List args, Properties properties, Config config) { String connectionSpec = properties.getProperty("connectionSpec"); - Iterator iter = options.iterator(); - while (iter.hasNext()) { - DbSpecificOption option = (DbSpecificOption)iter.next(); + for (DbSpecificOption option : options) { option.setValue(getParam(args, option, config)); // replace e.g. with @@ -65,7 +61,7 @@ public String getConnectionURL() { * * @return */ - public List getOptions() { + public List getOptions() { return options; } diff --git a/src/net/sourceforge/schemaspy/util/DbSpecificConfig.java b/src/net/sourceforge/schemaspy/util/DbSpecificConfig.java index 9aeedf0..86811b8 100644 --- a/src/net/sourceforge/schemaspy/util/DbSpecificConfig.java +++ b/src/net/sourceforge/schemaspy/util/DbSpecificConfig.java @@ -10,7 +10,7 @@ public class DbSpecificConfig { private final String type; private String description; - private final List options = new ArrayList(); + private final List options = new ArrayList(); private final Config config = new Config(); public DbSpecificConfig(final String dbType) { @@ -71,7 +71,7 @@ private void loadOptions(Properties properties) { * * @return */ - public List getOptions() { + public List getOptions() { return options; } diff --git a/src/net/sourceforge/schemaspy/util/DbSpecificOption.java b/src/net/sourceforge/schemaspy/util/DbSpecificOption.java index 1f9ebe0..94df753 100644 --- a/src/net/sourceforge/schemaspy/util/DbSpecificOption.java +++ b/src/net/sourceforge/schemaspy/util/DbSpecificOption.java @@ -31,6 +31,7 @@ public String getDescription() { return description; } + @Override public String toString() { return description; } diff --git a/src/net/sourceforge/schemaspy/util/Dot.java b/src/net/sourceforge/schemaspy/util/Dot.java index 2fe7349..09f68ec 100755 --- a/src/net/sourceforge/schemaspy/util/Dot.java +++ b/src/net/sourceforge/schemaspy/util/Dot.java @@ -19,8 +19,8 @@ public class Dot { private final String lineSeparator = System.getProperty("line.separator"); private String format = "png"; private String renderer; - private Set validatedRenderers = Collections.synchronizedSet(new HashSet()); - private Set invalidatedRenderers = Collections.synchronizedSet(new HashSet()); + private Set validatedRenderers = Collections.synchronizedSet(new HashSet()); + private Set invalidatedRenderers = Collections.synchronizedSet(new HashSet()); private Dot() { String versionText = null; diff --git a/src/net/sourceforge/schemaspy/util/HtmlEncoder.java b/src/net/sourceforge/schemaspy/util/HtmlEncoder.java index 0630ac1..ef4079a 100644 --- a/src/net/sourceforge/schemaspy/util/HtmlEncoder.java +++ b/src/net/sourceforge/schemaspy/util/HtmlEncoder.java @@ -10,7 +10,7 @@ * @author John Currier */ public class HtmlEncoder { - private static final Map map = new HashMap(); + private static final Map map = new HashMap(); static { map.put("<", "<"); @@ -26,7 +26,7 @@ public static String encode(char ch) { } public static String encode(String str) { - Object result = map.get(str); - return (result == null) ? str : result.toString(); + String result = map.get(str); + return (result == null) ? str : result; } } diff --git a/src/net/sourceforge/schemaspy/util/Version.java b/src/net/sourceforge/schemaspy/util/Version.java index 08e0142..30598ef 100755 --- a/src/net/sourceforge/schemaspy/util/Version.java +++ b/src/net/sourceforge/schemaspy/util/Version.java @@ -10,8 +10,8 @@ * @author John Currier * @version 1.0 */ -public class Version implements Comparable { - private final List segments = new ArrayList(); +public class Version implements Comparable { + private final List segments = new ArrayList(); private final String asString; private final int hashCode; @@ -36,12 +36,11 @@ public Version(String version) { * negative integer, zero, or a positive integer as this object is less * than, equal to, or greater than the specified object. */ - public int compareTo(Object version) { - Version other = (Version)version; + public int compareTo(Version other) { int size = Math.min(segments.size(), other.segments.size()); for (int i = 0; i < size; ++i) { - Integer thisSegment = (Integer)segments.get(i); - Integer otherSegment = (Integer)other.segments.get(i); + Integer thisSegment = segments.get(i); + Integer otherSegment = other.segments.get(i); int result = thisSegment.compareTo(otherSegment); if (result != 0) return result; @@ -54,17 +53,20 @@ public int compareTo(Object version) { return -1; } + @Override public boolean equals(Object other) { if (other == null || !(other instanceof Version)) return false; - return compareTo(other) == 0; + return compareTo((Version)other) == 0; } + @Override public int hashCode() { return hashCode; } + @Override public String toString() { return asString; } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/view/DotConnectorFinder.java b/src/net/sourceforge/schemaspy/view/DotConnectorFinder.java index f1e55da..f22864e 100755 --- a/src/net/sourceforge/schemaspy/view/DotConnectorFinder.java +++ b/src/net/sourceforge/schemaspy/view/DotConnectorFinder.java @@ -27,12 +27,11 @@ public static DotConnectorFinder getInstance() { * @throws IOException * @return Set of dot relationships (as DotEdges) */ - public Set getRelatedConnectors(Table table, WriteStats stats) { - Set relationships = new HashSet(); + public Set getRelatedConnectors(Table table, WriteStats stats) { + Set relationships = new HashSet(); - Iterator iter = table.getColumns().iterator(); - while (iter.hasNext()) { - relationships.addAll(getRelatedConnectors((TableColumn)iter.next(), null, stats)); + for (TableColumn column : table.getColumns()) { + relationships.addAll(getRelatedConnectors(column, null, stats)); } return relationships; @@ -46,17 +45,15 @@ public Set getRelatedConnectors(Table table, WriteStats stats) { * @throws IOException * @return Set of dot relationships (as DotEdges) */ - public Set getRelatedConnectors(Table table1, Table table2, WriteStats stats) { - Set relationships = new HashSet(); + public Set getRelatedConnectors(Table table1, Table table2, WriteStats stats) { + Set relationships = new HashSet(); - Iterator iter = table1.getColumns().iterator(); - while (iter.hasNext()) { - relationships.addAll(getRelatedConnectors((TableColumn)iter.next(), table2, stats)); + for (TableColumn column : table1.getColumns()) { + relationships.addAll(getRelatedConnectors(column, table2, stats)); } - iter = table2.getColumns().iterator(); - while (iter.hasNext()) { - relationships.addAll(getRelatedConnectors((TableColumn)iter.next(), table1, stats)); + for (TableColumn column : table2.getColumns()) { + relationships.addAll(getRelatedConnectors(column, table1, stats)); } return relationships; @@ -68,13 +65,12 @@ public Set getRelatedConnectors(Table table1, Table table2, WriteStats stats) { * @throws IOException * @return Set of dot relationships (as DotEdges) */ - private Set getRelatedConnectors(TableColumn column, Table targetTable, WriteStats stats) { - Set relatedConnectors = new HashSet(); + private Set getRelatedConnectors(TableColumn column, Table targetTable, WriteStats stats) { + Set relatedConnectors = new HashSet(); if (DotConnector.isExcluded(column, stats)) return relatedConnectors; - for (Iterator iter = column.getParents().iterator(); iter.hasNext(); ) { - TableColumn parentColumn = (TableColumn)iter.next(); + for (TableColumn parentColumn : column.getParents()) { Table parentTable = parentColumn.getTable(); if (targetTable != null && parentTable != targetTable) continue; @@ -86,8 +82,7 @@ private Set getRelatedConnectors(TableColumn column, Table targetTable, WriteSta } } - for (Iterator iter = column.getChildren().iterator(); iter.hasNext(); ) { - TableColumn childColumn = (TableColumn)iter.next(); + for (TableColumn childColumn : column.getChildren()) { Table childTable = childColumn.getTable(); if (targetTable != null && childTable != targetTable) continue; diff --git a/src/net/sourceforge/schemaspy/view/DotFormatter.java b/src/net/sourceforge/schemaspy/view/DotFormatter.java index 296ead6..17f345a 100755 --- a/src/net/sourceforge/schemaspy/view/DotFormatter.java +++ b/src/net/sourceforge/schemaspy/view/DotFormatter.java @@ -51,24 +51,22 @@ public void writeAllRelationships(Table table, boolean twoDegreesOfSeparation, W private void writeRelationships(Table table, boolean twoDegreesOfSeparation, WriteStats stats, LineWriter dot) throws IOException { Pattern regex = getRegexWithoutTable(table, stats); Pattern originalRegex = stats.setExclusionPattern(regex); - Set tablesWritten = new HashSet(); + Set
tablesWritten = new HashSet
(); DotConnectorFinder finder = DotConnectorFinder.getInstance(); String graphName = stats.includeImplied() ? "impliedTwoDegreesRelationshipsGraph" : (twoDegreesOfSeparation ? "twoDegreesRelationshipsGraph" : "oneDegreeRelationshipsGraph"); writeHeader(graphName, true, dot); - Set relatedTables = getImmediateRelatives(table, stats); + Set
relatedTables = getImmediateRelatives(table, stats); - Set connectors = new TreeSet(finder.getRelatedConnectors(table, stats)); + Set connectors = new TreeSet(finder.getRelatedConnectors(table, stats)); tablesWritten.add(table); - Map nodes = new TreeMap(); + Map nodes = new TreeMap(); // write immediate relatives first - Iterator iter = relatedTables.iterator(); - while (iter.hasNext()) { - Table relatedTable = (Table)iter.next(); + for (Table relatedTable : relatedTables) { if (!tablesWritten.add(relatedTable)) continue; // already written @@ -78,26 +76,20 @@ private void writeRelationships(Table table, boolean twoDegreesOfSeparation, Wri // connect the edges that go directly to the target table // so they go to the target table's type column instead - iter = connectors.iterator(); - while (iter.hasNext()) { - DotConnector connector = (DotConnector)iter.next(); + for (DotConnector connector : connectors) { if (connector.pointsTo(table)) connector.connectToParentDetails(); } - Set allCousins = new HashSet(); - Set allCousinConnectors = new TreeSet(); + Set
allCousins = new HashSet
(); + Set allCousinConnectors = new TreeSet(); // next write 'cousins' (2nd degree of separation) if (twoDegreesOfSeparation) { - iter = relatedTables.iterator(); - while (iter.hasNext()) { - Table relatedTable = (Table)iter.next(); - Set cousins = getImmediateRelatives(relatedTable, stats); - - Iterator cousinsIter = cousins.iterator(); - while (cousinsIter.hasNext()) { - Table cousin = (Table)cousinsIter.next(); + for (Table relatedTable : relatedTables) { + Set
cousins = getImmediateRelatives(relatedTable, stats); + + for (Table cousin : cousins) { if (!tablesWritten.add(cousin)) continue; // already written @@ -113,9 +105,7 @@ private void writeRelationships(Table table, boolean twoDegreesOfSeparation, Wri // now directly connect the loose ends to the title of the // 2nd degree of separation tables - iter = allCousinConnectors.iterator(); - while (iter.hasNext()) { - DotConnector connector = (DotConnector)iter.next(); + for (DotConnector connector : allCousinConnectors) { if (allCousins.contains(connector.getParentTable())) connector.connectToParentTitle(); if (allCousins.contains(connector.getChildTable())) @@ -126,23 +116,19 @@ private void writeRelationships(Table table, boolean twoDegreesOfSeparation, Wri nodes.put(table, new DotNode(table, "")); connectors.addAll(allCousinConnectors); - iter = connectors.iterator(); - while (iter.hasNext()) { - DotConnector connector = (DotConnector)iter.next(); + for (DotConnector connector : connectors) { if (connector.isImplied()) { - DotNode node = (DotNode)nodes.get(connector.getParentTable()); + DotNode node = nodes.get(connector.getParentTable()); if (node != null) node.setShowImplied(true); - node = (DotNode)nodes.get(connector.getChildTable()); + node = nodes.get(connector.getChildTable()); if (node != null) node.setShowImplied(true); } dot.writeln(connector.toString()); } - iter = nodes.values().iterator(); - while (iter.hasNext()) { - DotNode node = (DotNode)iter.next(); + for (DotNode node : nodes.values()) { dot.writeln(node.toString()); stats.wroteTable(node.getTable()); } @@ -152,8 +138,8 @@ private void writeRelationships(Table table, boolean twoDegreesOfSeparation, Wri } private Pattern getRegexWithoutTable(Table table, WriteStats stats) { - Set pieces = new HashSet(); - List regexes = Arrays.asList(stats.getExclusionPattern().pattern().split("\\)\\|\\(")); + Set pieces = new HashSet(); + List regexes = Arrays.asList(stats.getExclusionPattern().pattern().split("\\)\\|\\(")); for (int i = 0; i < regexes.size(); ++i) { String regex = regexes.get(i).toString(); if (!regex.startsWith("(")) @@ -164,12 +150,10 @@ private Pattern getRegexWithoutTable(Table table, WriteStats stats) { } // now removed the pieces that match some of the columns of this table - Iterator iter = pieces.iterator(); + Iterator iter = pieces.iterator(); while (iter.hasNext()) { - String regex = iter.next().toString(); - Iterator columnIter = table.getColumns().iterator(); - while (columnIter.hasNext()) { - TableColumn column = (TableColumn)columnIter.next(); + String regex = iter.next(); + for (TableColumn column : table.getColumns()) { Pattern columnPattern = Pattern.compile(regex); if (column.matches(columnPattern)) { iter.remove(); @@ -179,18 +163,17 @@ private Pattern getRegexWithoutTable(Table table, WriteStats stats) { } StringBuffer pattern = new StringBuffer(); - iter = pieces.iterator(); - while (iter.hasNext()) { + for (String piece : pieces) { if (pattern.length() > 0) pattern.append("|"); - pattern.append(iter.next()); + pattern.append(piece); } return Pattern.compile(pattern.toString()); } - private Set getImmediateRelatives(Table table, WriteStats stats) { - Set relatedColumns = new HashSet(); + private Set
getImmediateRelatives(Table table, WriteStats stats) { + Set relatedColumns = new HashSet(); boolean foundImplied = false; Iterator iter = table.getColumns().iterator(); while (iter.hasNext()) { @@ -225,12 +208,9 @@ private Set getImmediateRelatives(Table table, WriteStats stats) { } } - Set relatedTables = new HashSet(); - iter = relatedColumns.iterator(); - while (iter.hasNext()) { - TableColumn column = (TableColumn)iter.next(); + Set
relatedTables = new HashSet
(); + for (TableColumn column : relatedColumns) relatedTables.add(column.getTable()); - } relatedTables.remove(table); stats.setWroteImplied(foundImplied); @@ -267,19 +247,19 @@ private void writeHeader(String graphName, boolean showLabel, LineWriter dot) th dot.writeln(" ];"); } - public void writeRealRelationships(Database db, Collection tables, boolean compact, boolean showColumns, WriteStats stats, LineWriter dot) throws IOException { + public void writeRealRelationships(Database db, Collection
tables, boolean compact, boolean showColumns, WriteStats stats, LineWriter dot) throws IOException { boolean oldImplied = stats.setIncludeImplied(false); writeRelationships(db, tables, compact, showColumns, stats, dot); stats.setIncludeImplied(oldImplied); } - public void writeAllRelationships(Database db, Collection tables, boolean compact, boolean showColumns, WriteStats stats, LineWriter dot) throws IOException { + public void writeAllRelationships(Database db, Collection
tables, boolean compact, boolean showColumns, WriteStats stats, LineWriter dot) throws IOException { boolean oldImplied = stats.setIncludeImplied(true); writeRelationships(db, tables, compact, showColumns, stats, dot); stats.setIncludeImplied(oldImplied); } - private void writeRelationships(Database db, Collection tables, boolean compact, boolean showColumns, WriteStats stats, LineWriter dot) throws IOException { + private void writeRelationships(Database db, Collection
tables, boolean compact, boolean showColumns, WriteStats stats, LineWriter dot) throws IOException { DotConnectorFinder finder = DotConnectorFinder.getInstance(); DotNodeConfig nodeConfig = showColumns ? new DotNodeConfig(!compact, false) : new DotNodeConfig(); @@ -297,33 +277,27 @@ private void writeRelationships(Database db, Collection tables, boolean compact, } writeHeader(graphName, true, dot); - Map nodes = new TreeMap(); + Map nodes = new TreeMap(); - Iterator iter = tables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + for (Table table : tables) { if (!table.isOrphan(stats.includeImplied())) { nodes.put(table, new DotNode(table, "tables/", nodeConfig)); } } - - iter = db.getRemoteTables().iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + + for (Table table : db.getRemoteTables()) { nodes.put(table, new DotNode(table, "../" + table.getSchema() + "/tables", nodeConfig)); } - Set connectors = new TreeSet(); + Set connectors = new TreeSet(); - iter = nodes.values().iterator(); - while (iter.hasNext()) - connectors.addAll(finder.getRelatedConnectors(((DotNode)iter.next()).getTable(), stats)); + for (DotNode node : nodes.values()) { + connectors.addAll(finder.getRelatedConnectors(node.getTable(), stats)); + } markExcludedColumns(nodes, stats.getExcludedColumns()); - iter = nodes.values().iterator(); - while (iter.hasNext()) { - DotNode node = (DotNode)iter.next(); + for (DotNode node : nodes.values()) { Table table = node.getTable(); dot.writeln(node.toString()); @@ -333,18 +307,16 @@ private void writeRelationships(Database db, Collection tables, boolean compact, } } - iter = connectors.iterator(); - while (iter.hasNext()) - dot.writeln(iter.next().toString()); + for (DotConnector connector : connectors) { + dot.writeln(connector.toString()); + } dot.writeln("}"); } - private void markExcludedColumns(Map nodes, Set excludedColumns) { - Iterator iter = excludedColumns.iterator(); - while (iter.hasNext()) { - TableColumn column = (TableColumn)iter.next(); - DotNode node = (DotNode)nodes.get(column.getTable()); + private void markExcludedColumns(Map nodes, Set excludedColumns) { + for (TableColumn column : excludedColumns) { + DotNode node = nodes.get(column.getTable()); if (node != null) { node.excludeColumn(column); } diff --git a/src/net/sourceforge/schemaspy/view/DotNode.java b/src/net/sourceforge/schemaspy/view/DotNode.java index 2b12e91..990ffc8 100755 --- a/src/net/sourceforge/schemaspy/view/DotNode.java +++ b/src/net/sourceforge/schemaspy/view/DotNode.java @@ -9,7 +9,7 @@ public class DotNode { private final Table table; private final DotNodeConfig config; private final String path; - private final Set excludedColumns = new HashSet(); + private final Set excludedColumns = new HashSet(); private final String lineSeparator = System.getProperty("line.separator"); private final boolean displayNumRows = Config.getInstance().isNumRowsEnabled(); @@ -71,17 +71,15 @@ public String toString() { boolean skippedTrivial = false; if (config.showColumns) { - List primaryColumns = table.getPrimaryColumns(); - Set indexColumns = new HashSet(); - Iterator iter = table.getIndexes().iterator(); - while (iter.hasNext()) { - TableIndex index = (TableIndex)iter.next(); + List primaryColumns = table.getPrimaryColumns(); + Set indexColumns = new HashSet(); + + for (TableIndex index : table.getIndexes()) { indexColumns.addAll(index.getColumns()); } indexColumns.removeAll(primaryColumns); - - for (iter = table.getColumns().iterator(); iter.hasNext(); ) { - TableColumn column = (TableColumn)iter.next(); + + for (TableColumn column : table.getColumns()) { if (config.showTrivialColumns || config.showColumnDetails || column.isPrimary() || column.isForeignKey() || indexColumns.contains(column)) { buf.append(" "); buf.append("
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); + 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); + writeDefaultNullStrings(DbAnalyzer.getDefaultNullStringColumns(new HashSet
(tables)), out); writeFooter(out); } @@ -44,13 +44,12 @@ private void writeHeader(Database database, boolean hasOrphans, LineWriter html) html.writeln("
    "); } - private void writeImpliedConstraints(List impliedConstraints, LineWriter out) throws IOException { + private void writeImpliedConstraints(List impliedConstraints, LineWriter out) throws IOException { out.writeln("
  • "); out.writeln("Columns whose name and type imply a relationship to another table's primary key:"); int numDetected = 0; - Iterator iter = impliedConstraints.iterator(); - while (iter.hasNext()) { - ForeignKeyConstraint impliedConstraint = (ForeignKeyConstraint)iter.next(); + + for (ForeignKeyConstraint impliedConstraint : impliedConstraints) { Table childTable = impliedConstraint.getChildTable(); if (!childTable.isView()) { ++numDetected; @@ -68,9 +67,8 @@ private void writeImpliedConstraints(List impliedConstraints, LineWriter out) th out.writeln(""); out.writeln(""); out.writeln("
"); - iter = impliedConstraints.iterator(); - while (iter.hasNext()) { - ForeignKeyConstraint impliedConstraint = (ForeignKeyConstraint)iter.next(); + + for (ForeignKeyConstraint impliedConstraint : impliedConstraints) { Table childTable = impliedConstraint.getChildTable(); if (!childTable.isView()) { out.writeln(" "); @@ -106,14 +104,14 @@ private void writeImpliedConstraints(List impliedConstraints, LineWriter out) th out.writeln("

"); } - private void writeUniqueNullables(List uniqueNullables, LineWriter out) throws IOException { + private void writeUniqueNullables(List uniqueNullables, LineWriter out) throws IOException { out.writeln("

  • "); out.writeln("Columns that are flagged as both 'nullable' and 'must be unique':"); writeColumnBasedAnomaly(uniqueNullables, out); out.writeln("

  • "); } - private void writeTablesWithoutIndexes(List unindexedTables, LineWriter out) throws IOException { + private void writeTablesWithoutIndexes(List
    unindexedTables, LineWriter out) throws IOException { out.writeln("
  • "); out.writeln("Tables without indexes:"); if (!unindexedTables.isEmpty()) { @@ -130,9 +128,8 @@ private void writeTablesWithoutIndexes(List unindexedTables, LineWriter out) thr out.writeln(""); out.writeln(""); out.writeln("
  • "); - Iterator iter = unindexedTables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + + for (Table table : unindexedTables) { out.writeln(" "); out.write("
    "); out.write(""); out.write(""); out.write(""); writeColumnBasedAnomaly(uniqueNullables, out); out.writeln("

    "); } - private void writeColumnBasedAnomaly(List columns, LineWriter out) throws IOException { + private void writeColumnBasedAnomaly(List columns, LineWriter out) throws IOException { if (!columns.isEmpty()) { out.writeln(""); out.writeln(""); @@ -241,9 +236,7 @@ private void writeColumnBasedAnomaly(List columns, LineWriter out) throws IOExce out.writeln(""); out.writeln(""); out.writeln(""); - Iterator iter = columns.iterator(); - while (iter.hasNext()) { - TableColumn column = (TableColumn)iter.next(); + for (TableColumn column : columns) { out.writeln(" "); out.write(" "); if (showIds) { out.write("
    "); String tableName = column.getTable().getName(); diff --git a/src/net/sourceforge/schemaspy/view/HtmlColumnsPage.java b/src/net/sourceforge/schemaspy/view/HtmlColumnsPage.java index 676bba1..3e90f85 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlColumnsPage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlColumnsPage.java @@ -24,9 +24,9 @@ public static HtmlColumnsPage getInstance() { * * @return */ - public List getColumnInfos() + public List getColumnInfos() { - List columns = new ArrayList(); + List columns = new ArrayList(); columns.add(new ColumnInfo("Column", new ByColumnComparator())); columns.add(new ColumnInfo("Table", new ByTableComparator())); @@ -44,9 +44,9 @@ public List getColumnInfos() public class ColumnInfo { private final String columnName; - private final Comparator comparator; + private final Comparator comparator; - private ColumnInfo(String columnName, Comparator comparator) + private ColumnInfo(String columnName, Comparator comparator) { this.columnName = columnName; this.comparator = comparator; @@ -64,19 +64,20 @@ public String getLocation(String columnName) { return "columns.by" + columnName + ".html"; } - private Comparator getComparator() { + private Comparator getComparator() { return comparator; } - + + @Override public String toString() { return getLocation(); } } public void write(Database database, Collection tables, ColumnInfo columnInfo, boolean showOrphansGraph, LineWriter html) throws IOException { - Set columns = new TreeSet(columnInfo.getComparator()); - Set primaryColumns = new HashSet(); - Set indexedColumns = new HashSet(); + Set columns = new TreeSet(columnInfo.getComparator()); + Set primaryColumns = new HashSet(); + Set indexedColumns = new HashSet(); Iterator iter = tables.iterator(); while (iter.hasNext()) { @@ -218,10 +219,8 @@ protected boolean isColumnsPage() { return true; } - private class ByColumnComparator implements Comparator { - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + private class ByColumnComparator implements Comparator { + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getName().compareTo(column2.getName()); if (rc == 0) rc = column1.getTable().getName().compareTo(column2.getTable().getName()); @@ -229,10 +228,8 @@ public int compare(Object object1, Object object2) { } } - private class ByTableComparator implements Comparator { - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + private class ByTableComparator implements Comparator { + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getTable().getName().compareTo(column2.getTable().getName()); if (rc == 0) rc = column1.getName().compareTo(column2.getName()); @@ -240,12 +237,10 @@ public int compare(Object object1, Object object2) { } } - private class ByTypeComparator implements Comparator { - private Comparator bySize = new BySizeComparator(); + private class ByTypeComparator implements Comparator { + private Comparator bySize = new BySizeComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getType().compareTo(column2.getType()); if (rc == 0) { rc = bySize.compare(column1, column2); @@ -254,12 +249,10 @@ public int compare(Object object1, Object object2) { } } - private class BySizeComparator implements Comparator { - private Comparator byColumn = new ByColumnComparator(); + private class BySizeComparator implements Comparator { + private Comparator byColumn = new ByColumnComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.getLength() - column2.getLength(); if (rc == 0) { rc = column1.getDecimalDigits() - column2.getDecimalDigits(); @@ -270,12 +263,10 @@ public int compare(Object object1, Object object2) { } } - private class ByNullableComparator implements Comparator { - private Comparator byColumn = new ByColumnComparator(); + private class ByNullableComparator implements Comparator { + private Comparator byColumn = new ByColumnComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.isNullable() == column2.isNullable() ? 0 : column1.isNullable() ? -1 : 1; if (rc == 0) rc = byColumn.compare(column1, column2); @@ -283,12 +274,10 @@ public int compare(Object object1, Object object2) { } } - private class ByAutoUpdateComparator implements Comparator { - private Comparator byColumn = new ByColumnComparator(); + private class ByAutoUpdateComparator implements Comparator { + private Comparator byColumn = new ByColumnComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + public int compare(TableColumn column1, TableColumn column2) { int rc = column1.isAutoUpdated() == column2.isAutoUpdated() ? 0 : column1.isAutoUpdated() ? -1 : 1; if (rc == 0) rc = byColumn.compare(column1, column2); @@ -296,12 +285,10 @@ public int compare(Object object1, Object object2) { } } - private class ByDefaultValueComparator implements Comparator { - private Comparator byColumn = new ByColumnComparator(); + private class ByDefaultValueComparator implements Comparator { + private Comparator byColumn = new ByColumnComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; + public int compare(TableColumn column1, TableColumn column2) { int rc = String.valueOf(column1.getDefaultValue()).compareTo(String.valueOf(column2.getDefaultValue())); if (rc == 0) rc = byColumn.compare(column1, column2); @@ -309,14 +296,12 @@ public int compare(Object object1, Object object2) { } } - private class ByChildrenComparator implements Comparator { - private Comparator byColumn = new ByColumnComparator(); + private class ByChildrenComparator implements Comparator { + private Comparator byColumn = new ByColumnComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; - Set childTables1 = new TreeSet(); - Set childTables2 = new TreeSet(); + public int compare(TableColumn column1, TableColumn column2) { + Set childTables1 = new TreeSet(); + Set childTables2 = new TreeSet(); Iterator iter = column1.getChildren().iterator(); while (iter.hasNext()) { @@ -339,14 +324,12 @@ public int compare(Object object1, Object object2) { } } - private class ByParentsComparator implements Comparator { - private Comparator byColumn = new ByColumnComparator(); + private class ByParentsComparator implements Comparator { + private Comparator byColumn = new ByColumnComparator(); - public int compare(Object object1, Object object2) { - TableColumn column1 = (TableColumn)object1; - TableColumn column2 = (TableColumn)object2; - Set parentTables1 = new TreeSet(); - Set parentTables2 = new TreeSet(); + public int compare(TableColumn column1, TableColumn column2) { + Set parentTables1 = new TreeSet(); + Set parentTables2 = new TreeSet(); Iterator iter = column1.getParents().iterator(); while (iter.hasNext()) { @@ -368,4 +351,4 @@ public int compare(Object object1, Object object2) { return rc; } } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java b/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java index a72296e..fec2199 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlConstraintsPage.java @@ -19,7 +19,7 @@ public static HtmlConstraintsPage getInstance() { return instance; } - public void write(Database database, List constraints, Collection tables, boolean hasOrphans, LineWriter html) throws IOException { + public void write(Database database, List constraints, Collection tables, boolean hasOrphans, LineWriter html) throws IOException { writeHeader(database, hasOrphans, html); writeForeignKeyConstraints(constraints, html); writeCheckConstraints(tables, html); @@ -43,10 +43,10 @@ protected void writeFooter(LineWriter html) throws IOException { * @param html LineWriter * @throws IOException */ - private void writeForeignKeyConstraints(List constraints, LineWriter html) throws IOException { - Set constraintsByName = new TreeSet(new Comparator() { - public int compare(Object object1, Object object2) { - return ((ForeignKeyConstraint)object1).getName().compareTo(((ForeignKeyConstraint)object2).getName()); + private void writeForeignKeyConstraints(List constraints, LineWriter html) throws IOException { + Set constraintsByName = new TreeSet(new Comparator() { + public int compare(ForeignKeyConstraint cons1, ForeignKeyConstraint cons2) { + return cons1.getName().compareTo(cons2.getName()); } }); constraintsByName.addAll(constraints); @@ -138,7 +138,7 @@ private void writeForeignKeyConstraint(ForeignKeyConstraint constraint, LineWrit * @param html LineWriter * @throws IOException */ - public void writeCheckConstraints(Collection tables, LineWriter html) throws IOException { + public void writeCheckConstraints(Collection
    tables, LineWriter html) throws IOException { html.writeln("

    "); html.writeln("Check Constraints:"); html.writeln("

    "); @@ -154,13 +154,12 @@ 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; // iter over all tables...only ones with check constraints will write anything - for (Iterator iter = tablesByName.iterator(); iter.hasNext(); ) { - Table table = (Table)iter.next(); + for (Table table : tablesByName) { constraintsWritten += writeCheckConstraints(table, html); } @@ -206,7 +205,8 @@ private int writeCheckConstraints(Table table, LineWriter html) throws IOExcepti return constraintsWritten; } + @Override protected boolean isConstraintsPage() { return true; } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/schemaspy/view/HtmlMainIndexPage.java b/src/net/sourceforge/schemaspy/view/HtmlMainIndexPage.java index 985b021..166ef94 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlMainIndexPage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlMainIndexPage.java @@ -20,10 +20,10 @@ public static HtmlMainIndexPage getInstance() { return instance; } - public void write(Database database, Collection tables, boolean showOrphansGraph, LineWriter html) throws IOException { - Set byName = new TreeSet(new Comparator() { - public int compare(Object object1, Object object2) { - return ((Table)object1).getName().compareTo(((Table)object2).getName()); + public void write(Database database, Collection
    tables, boolean showOrphansGraph, LineWriter html) throws IOException { + Set
    byName = new TreeSet
    (new Comparator
    () { + public int compare(Table table1, Table table2) { + return table1.getName().compareTo(table2.getName()); } }); byName.addAll(tables); @@ -41,8 +41,7 @@ public int compare(Object object1, Object object2) { writeHeader(database, byName.size() - numViews, numViews, showIds, showOrphansGraph, html); int numRows = 0; - for (Iterator iter = byName.iterator(); iter.hasNext(); ) { - Table table = (Table)iter.next(); + for (Table table : byName) { numRows += writeLineItem(table, showIds, html); } diff --git a/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java b/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java index 62464af..9b643b7 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlOrphansPage.java @@ -3,7 +3,6 @@ import java.io.File; import java.io.IOException; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Set; import net.sourceforge.schemaspy.Config; @@ -22,15 +21,14 @@ public static HtmlOrphansPage getInstance() { return instance; } - public boolean write(Database db, List orphanTables, File graphDir, LineWriter html) throws IOException { + public boolean write(Database db, List
    orphanTables, File graphDir, LineWriter html) throws IOException { Dot dot = getDot(); if (dot == null) return false; - Set orphansWithImpliedRelationships = new HashSet(); - Iterator iter = orphanTables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + Set
    orphansWithImpliedRelationships = new HashSet
    (); + + for (Table table : orphanTables) { if (!table.isOrphan(true)){ orphansWithImpliedRelationships.add(table); } @@ -41,10 +39,8 @@ public boolean write(Database db, List orphanTables, File graphDir, LineWriter h html.writeln(""); try { StringBuffer maps = new StringBuffer(64 * 1024); - - iter = orphanTables.iterator(); - while (iter.hasNext()) { - Table table = (Table)iter.next(); + + for (Table table : orphanTables) { String dotBaseFilespec = table.getName(); File dotFile = new File(graphDir, dotBaseFilespec + ".1degree.dot"); diff --git a/src/net/sourceforge/schemaspy/view/HtmlTablePage.java b/src/net/sourceforge/schemaspy/view/HtmlTablePage.java index 0df3700..7fc7f0a 100755 --- a/src/net/sourceforge/schemaspy/view/HtmlTablePage.java +++ b/src/net/sourceforge/schemaspy/view/HtmlTablePage.java @@ -10,11 +10,11 @@ public class HtmlTablePage extends HtmlFormatter { private static final HtmlTablePage instance = new HtmlTablePage(); - private Set keywords = null; + private Set keywords = null; private final boolean encodeComments = Config.getInstance().isEncodeCommentsEnabled(); private final boolean commentsInitiallyDisplayed = Config.getInstance().isDisplayCommentsIntiallyEnabled(); - private Map defaultValueAliases = new HashMap(); + private Map defaultValueAliases = new HashMap(); { defaultValueAliases.put("CURRENT TIMESTAMP", "now"); // DB2 defaultValueAliases.put("CURRENT TIME", "now"); // DB2 @@ -93,17 +93,14 @@ public boolean writeMainTable(Table table, LineWriter out) throws IOException { HtmlColumnsPage.getInstance().writeMainTableHeader(table.getId() != null, null, out); out.writeln(""); - Set primaries = new HashSet(table.getPrimaryColumns()); - Set indexedColumns = new HashSet(); - Iterator indexIter = table.getIndexes().iterator(); - while (indexIter.hasNext()) { - TableIndex index = (TableIndex)indexIter.next(); + Set primaries = new HashSet(table.getPrimaryColumns()); + Set indexedColumns = new HashSet(); + for (TableIndex index : table.getIndexes()) { indexedColumns.addAll(index.getColumns()); } boolean showIds = table.getId() != null; - for (Iterator iter = table.getColumns().iterator(); iter.hasNext(); ) { - TableColumn column = (TableColumn)iter.next(); + for (TableColumn column : table.getColumns()) { onCascadeDelete = writeColumn(column, null, primaries, indexedColumns, onCascadeDelete, showIds, out); } out.writeln("
    "); @@ -111,7 +108,7 @@ public boolean writeMainTable(Table table, LineWriter out) throws IOException { return onCascadeDelete; } - public boolean writeColumn(TableColumn column, String tableName, Set primaries, Set indexedColumns, boolean onCascadeDelete, boolean showIds, LineWriter out) throws IOException { + public boolean writeColumn(TableColumn column, String tableName, Set primaries, Set indexedColumns, boolean onCascadeDelete, boolean showIds, LineWriter out) throws IOException { out.writeln("
    "); @@ -202,7 +199,7 @@ else if (indexedColumns.contains(column)) */ private boolean writeRelatives(TableColumn baseRelative, boolean dumpParents, String path, LineWriter out) throws IOException { boolean onCascadeDelete = false; - Set columns = dumpParents ? baseRelative.getParents() : baseRelative.getChildren(); + Set columns = dumpParents ? baseRelative.getParents() : baseRelative.getChildren(); final int numColumns = columns.size(); if (numColumns > 0) { @@ -210,8 +207,7 @@ private boolean writeRelatives(TableColumn baseRelative, boolean dumpParents, St out.writeln(" "); } - for (Iterator iter = columns.iterator(); iter.hasNext(); ) { - TableColumn column = (TableColumn)iter.next(); + for (TableColumn column : columns) { String columnTableName = column.getTable().getName(); ForeignKeyConstraint constraint = dumpParents ? column.getChildConstraint(baseRelative) : column.getParentConstraint(baseRelative); if (constraint.isImplied()) @@ -287,7 +283,7 @@ private void writeCheckConstraints(Table table, LineWriter out) throws IOExcepti private void writeIndexes(Table table, LineWriter out) throws IOException { boolean showId = table.getId() != null; - Set indexes = table.getIndexes(); + Set indexes = table.getIndexes(); if (indexes != null && !indexes.isEmpty()) { // see if we've got any strangeness so we can have the correct number of colgroups boolean containsAnomalies = false; @@ -311,7 +307,7 @@ private void writeIndexes(Table table, LineWriter out) throws IOException { out.writeln(""); out.writeln(""); - indexes = new TreeSet(indexes); // sort primary keys first + indexes = new TreeSet(indexes); // sort primary keys first for (Iterator iter = indexes.iterator(); iter.hasNext(); ) { TableIndex index = (TableIndex)iter.next(); @@ -372,15 +368,12 @@ private void writeIndexes(Table table, LineWriter out) throws IOException { private void writeView(Table table, Database db, LineWriter out) throws IOException { String sql; if (table.isView() && (sql = table.getViewSql()) != null) { - Map tables = new CaseInsensitiveMap(); - for (Iterator iter = db.getTables().iterator(); iter.hasNext(); ) { - Table t = (Table)iter.next(); - tables.put(t.getName(), t); - } - for (Iterator iter = db.getViews().iterator(); iter.hasNext(); ) { - Table t = (Table)iter.next(); + Map tables = new CaseInsensitiveMap
    (); + + for (Table t : db.getTables()) tables.put(t.getName(), t); - } + for (View v : db.getViews()) + tables.put(v.getName(), v); out.writeln("
    "); out.writeln("View SQL:"); @@ -398,7 +391,7 @@ private void writeView(Table table, Database db, LineWriter out) throws IOExcept out.write(nextToken); out.write(""); } else { - Table t = (Table)tables.get(nextToken); + Table t = tables.get(nextToken); if (t != null) { out.write("