Skip to content

Commit

Permalink
refactor(schema): simplify expression
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperolsson-se committed Apr 23, 2024
1 parent b609d4f commit 3c85d4f
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/main/java/org/schemaspy/DbAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
package org.schemaspy;

import org.schemaspy.model.*;
import org.schemaspy.util.Filtered;
import org.schemaspy.util.Inflection;
import org.schemaspy.util.WhenFalse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -290,20 +292,24 @@ public static List<String> getPopulatedSchemas(
Set<String> schemas = new TreeSet<>(); // alpha sorted
Pattern schemaRegex = Pattern.compile(schemaSpec);

for (String schema : candidates) {
if (schemaRegex.matcher(schema).matches()) {
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);
}
} catch (SQLException sqlex) {
LOGGER.debug("SQLException caught during populateSchemas", sqlex);
final Iterable<String> matched = new Filtered<>(
candidates,
new WhenFalse<>(
schema -> schemaRegex.matcher(schema).matches(),
schema -> LOGGER.debug("Excluding schema {}: doesn't match '{}'", schema, schemaRegex)
)
);

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);
}
} else {
LOGGER.debug("Excluding schema {}: doesn't match '{}'", schema, schemaRegex);
} catch (SQLException sqlex) {
LOGGER.debug("SQLException caught during populateSchemas", sqlex);
}
}

Expand Down

0 comments on commit 3c85d4f

Please sign in to comment.