Skip to content

Commit

Permalink
Added ability to filter out inappropriate tables (e.g. Oracle 10g's t…
Browse files Browse the repository at this point in the history
…ables with $'s and =='s in their names)
  • Loading branch information
johncurrier committed Mar 6, 2006
1 parent fd472a5 commit b9794a2
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/net/sourceforge/schemaspy/model/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ private void initTables(String schema, final DatabaseMetaData metadata, final Pr
String[] types = {"TABLE"};
ResultSet rs = null;

// "macro" to validate that a table is somewhat valid
class TableValidator {
boolean isValid(ResultSet rs) throws SQLException {
// some databases (MySQL) return more than we wanted
if (!rs.getString("TABLE_TYPE").equalsIgnoreCase("TABLE"))
return false;

// Oracle 10g introduced problematic flashback tables
// with bizarre illegal names
String tableName = rs.getString("TABLE_NAME");
if (tableName.indexOf("$") != -1)
return false;

return true;
}
}
TableValidator tableValidator = new TableValidator();

try {
// creating tables takes a LONG time (based on JProbe analysis).
// it's actually DatabaseMetaData.getIndexInfo() that's the pig.
Expand All @@ -79,15 +97,15 @@ private void initTables(String schema, final DatabaseMetaData metadata, final Pr
// "prime the pump" so if there's a database problem we'll probably see it now
// and not in a secondary thread
while (rs.next()) {
if (rs.getString("TABLE_TYPE").equals("TABLE")) { // some databases (MySQL) return more than we wanted
if (tableValidator.isValid(rs)) {
new TableCreator().create(rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME"), properties);
break;
}
}
}

while (rs.next()) {
if (rs.getString("TABLE_TYPE").equals("TABLE")) { // some databases (MySQL) return more than we wanted
if (tableValidator.isValid(rs)) {
creator.create(rs.getString("TABLE_SCHEM"), rs.getString("TABLE_NAME"), properties);
}
}
Expand Down

0 comments on commit b9794a2

Please sign in to comment.