Skip to content

Commit

Permalink
[jOOQ#5301] Display a warning in the generator logs for regexes that …
Browse files Browse the repository at this point in the history
…never match
  • Loading branch information
lukaseder committed May 25, 2016
1 parent 4755504 commit d3ec840
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
36 changes: 34 additions & 2 deletions jOOQ-codegen/src/main/java/org/jooq/util/JavaGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,12 @@ public final void generate(Database db) {

if (generateImmutablePojos && generateInterfaces)
log.info(" immutable pojos", "Immutable POJOs do not have any setters. Hence, setters are also missing from interfaces");
else
log.info(" none");

if (contains(db.getIncludes(), ',') && db.getIncluded().isEmpty())
log.info(" includes", "The <includes/> element takes a Java regular expression, not a comma-separated list. This might be why no objects were included.");

if (contains(db.getExcludes(), ',') && db.getExcluded().isEmpty())
log.info(" excludes", "The <excludes/> element takes a Java regular expression, not a comma-separated list. This might be why no objects were excluded.");

log.info("");
log.info("----------------------------------------------------------");
Expand All @@ -287,6 +291,34 @@ public final void generate(Database db) {
}
}

private boolean isEmpty(Database db) {
for (SchemaDefinition schema : db.getSchemata()) {
for (TableDefinition table : db.getTables(schema))
return false;
for (SequenceDefinition sequence : db.getSequences(schema))
return false;
for (PackageDefinition pkg : db.getPackages(schema))
return false;
for (RoutineDefinition routine : db.getRoutines(schema))
return false;
for (UDTDefinition udt : db.getUDTs(schema))
return false;
}

return true;
}

private boolean contains(String[] array, char c) {
if (array == null)
return false;

for (String string : array)
if (string != null && string.indexOf(c) > -1)
return true;

return false;
}

private void generate(CatalogDefinition catalog) {
String newVersion = catalog.getDatabase().getCatalogVersionProvider().version(catalog);

Expand Down
40 changes: 35 additions & 5 deletions jOOQ-meta/src/main/java/org/jooq/util/AbstractDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,19 @@ public abstract class AbstractDatabase implements Database {
private transient boolean initialised;

// Other caches
private final List<Definition> all;
private final List<Definition> included;
private final List<Definition> excluded;
private final Map<Table<?>, Boolean> exists;
private final Map<String, Pattern> patterns;

protected AbstractDatabase() {
exists = new HashMap<Table<?>, Boolean>();
patterns = new HashMap<String, Pattern>();
filters = new ArrayList<Filter>();
all = new ArrayList<Definition>();
included = new ArrayList<Definition>();
excluded = new ArrayList<Definition>();
}

@Override
Expand Down Expand Up @@ -877,6 +883,7 @@ public final List<SequenceDefinition> getSequences(SchemaDefinition schema) {
try {
List<SequenceDefinition> s = getSequences0();

all.addAll(s);
sequences = filterExcludeInclude(s);
log.info("Sequences fetched", fetchedSize(s, sequences));
}
Expand Down Expand Up @@ -979,6 +986,7 @@ public final List<TableDefinition> getTables(SchemaDefinition schema) {
try {
List<TableDefinition> t = getTables0();

all.addAll(t);
tables = filterExcludeInclude(t);
log.info("Tables fetched", fetchedSize(t, tables));
}
Expand Down Expand Up @@ -1238,6 +1246,7 @@ public final List<RoutineDefinition> getRoutines(SchemaDefinition schema) {
try {
List<RoutineDefinition> r = getRoutines0();

all.addAll(r);
routines = filterExcludeInclude(r);
log.info("Routines fetched", fetchedSize(r, routines));
}
Expand All @@ -1264,6 +1273,7 @@ public final List<PackageDefinition> getPackages(SchemaDefinition schema) {
try {
List<PackageDefinition> p = getPackages0();

all.addAll(p);
packages = filterExcludeInclude(p);
log.info("Packages fetched", fetchedSize(p, packages));
}
Expand Down Expand Up @@ -1311,19 +1321,39 @@ protected final <T extends Definition> List<T> filterSchema(List<T> definitions,
else {
List<T> result = new ArrayList<T>();

for (T definition : definitions) {
if (definition.getSchema().equals(schema)) {
for (T definition : definitions)
if (definition.getSchema().equals(schema))
result.add(definition);
}
}

return result;
}
}

@Override
public final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions) {
return filterExcludeInclude(definitions, excludes, includes, filters);
List<T> result = filterExcludeInclude(definitions, excludes, includes, filters);

this.all.addAll(definitions);
this.included.addAll(result);
this.excluded.addAll(definitions);
this.excluded.removeAll(result);

return result;
}

@Override
public final List<Definition> getIncluded() {
return Collections.unmodifiableList(included);
}

@Override
public final List<Definition> getExcluded() {
return Collections.unmodifiableList(excluded);
}

@Override
public final List<Definition> getAll() {
return Collections.unmodifiableList(all);
}

protected final <T extends Definition> List<T> filterExcludeInclude(List<T> definitions, String[] e, String[] i, List<Filter> f) {
Expand Down
15 changes: 15 additions & 0 deletions jOOQ-meta/src/main/java/org/jooq/util/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,21 @@ public interface Database {
*/
<D extends Definition> List<D> filterExcludeInclude(List<D> definitions);

/**
* Retrieve all included objects.
*/
List<Definition> getIncluded();

/**
* Retrieve all excluded objects.
*/
List<Definition> getExcluded();

/**
* Retrieve all objects.
*/
List<Definition> getAll();

/**
* The regular expression flags that should be applied when using regular expressions.
*/
Expand Down

0 comments on commit d3ec840

Please sign in to comment.