Skip to content

Commit

Permalink
chore(schema): simplify expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperolsson-se committed Apr 27, 2024
1 parent 9358e52 commit 0009ee7
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/main/java/org/schemaspy/DbAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public static List<String> getPopulatedSchemas(
DatabaseMetaData meta,
String schemaSpec,
final List<String> candidates
) throws SQLException {
) {
Set<String> schemas = new TreeSet<>(); // alpha sorted
Pattern schemaRegex = Pattern.compile(schemaSpec);

Expand All @@ -301,16 +301,25 @@ public static List<String> getPopulatedSchemas(
);

for (String schema : matched) {
try (ResultSet rs = meta.getTables(null, schema, "%", null)) {
if (rs.next()) {
LOGGER.debug("Including schema {}: matches + \"{}\" and contains tables", schema, schemaRegex);
schemas.add(schema);
} else {
LOGGER.debug("Excluding schema {}: matches \"{}\" but contains no tables", schema, schemaRegex);
}
if (hasTables(meta, schema)) {
LOGGER.debug("Including schema {}: matches + \"{}\" and contains tables", schema, schemaRegex);
schemas.add(schema);
} else {
LOGGER.debug("Excluding schema {}: matches \"{}\" but contains no tables", schema, schemaRegex);
}
}

return new ArrayList<>(schemas);
}

public static boolean hasTables(
final DatabaseMetaData meta,
final String schema
) {
try(final ResultSet rs = meta.getTables(null, schema, "%", null)) {
return rs.next();
} catch (SQLException e) {
return false;
}
}
}

0 comments on commit 0009ee7

Please sign in to comment.