[#3559] Propagate jOOQ-codegen's relations flag also to jOOQ-meta, to prevent (possibly expensive) queries to fetch relations

This commit is contained in:
Lukas Eder 2014-08-15 14:13:01 +02:00
parent 57650f08e3
commit 3a117886ba
3 changed files with 33 additions and 5 deletions

View File

@ -144,6 +144,7 @@ public class JavaGenerator extends AbstractGenerator {
public final void generate(Database db) {
this.database = db;
this.database.addFilter(new AvoidAmbiguousClassesFilter());
this.database.setIncludeRelations(generateRelations());
String url = "";
try {

View File

@ -125,6 +125,7 @@ public abstract class AbstractDatabase implements Database {
private List<RoutineDefinition> routines;
private List<PackageDefinition> packages;
private Relations relations;
private boolean includeRelations = true;
private transient Map<SchemaDefinition, List<SequenceDefinition>> sequencesBySchema;
private transient Map<SchemaDefinition, List<IdentityDefinition>> identitiesBySchema;
@ -456,6 +457,16 @@ public abstract class AbstractDatabase implements Database {
return dateAsTimestamp;
}
@Override
public final void setIncludeRelations(boolean includeRelations) {
this.includeRelations = includeRelations;
}
@Override
public final boolean includeRelations() {
return includeRelations;
}
@Override
public final List<SequenceDefinition> getSequences(SchemaDefinition schema) {
if (sequences == null) {
@ -750,11 +761,17 @@ public abstract class AbstractDatabase implements Database {
@Override
public final Relations getRelations() {
if (relations == null) {
try {
relations = getRelations0();
} catch (Exception e) {
log.error("Error while fetching relations", e);
relations = new DefaultRelations();
relations = new DefaultRelations();
// [#3559] If the code generator doesn't need relation information, we shouldn't
// populate them here to avoid running potentially expensive queries.
if (includeRelations) {
try {
relations = getRelations0();
}
catch (Exception e) {
log.error("Error while fetching relations", e);
}
}
}

View File

@ -383,6 +383,16 @@ public interface Database {
*/
boolean dateAsTimestamp();
/**
* [#3559] Whether relations (i.e. constraints) should be included in this database.
*/
void setIncludeRelations(boolean includeRelations);
/**
* [#3559] Whether relations (i.e. constraints) should be included in this database.
*/
boolean includeRelations();
/**
* Check for the existence of a table in the dictionary views.
*/