Skip to content

Commit

Permalink
[jOOQ#5609] Better fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaseder committed Oct 21, 2016
1 parent 6c0bc24 commit a79e800
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 19 deletions.
6 changes: 6 additions & 0 deletions jOOQ-codegen/src/main/java/org/jooq/util/GenerationTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ else if (j != null) {
catalog.setOutputCatalogToDefault(d.isOutputCatalogToDefault());
catalogs.add(catalog);

if (!StringUtils.isBlank(catalog.getInputCatalog()))
catalogsEmpty = false;

// For convenience and backwards-compatibility, the schema configuration can be set also directly
// in the <database/> element
if (schemataEmpty) {
Expand All @@ -320,6 +323,9 @@ else if (j != null) {
schema.setOutputSchema(trim(d.getOutputSchema()));
schema.setOutputSchemaToDefault(d.isOutputSchemaToDefault());
catalog.getSchemata().add(schema);

if (!StringUtils.isBlank(schema.getInputSchema()))
schemataEmpty = false;
}
else {
catalog.getSchemata().addAll(schemata);
Expand Down
45 changes: 26 additions & 19 deletions jOOQ-meta/src/main/java/org/jooq/util/AbstractDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -480,25 +480,13 @@ public final List<String> getInputSchemata() {
inputSchemata = new ArrayList<String>();
inputSchemataPerCatalog = new LinkedHashMap<String, List<String>>();

// [#1312] [#5609] Allow for ommitting inputSchema configuration. Generate all schemata instead.
if (configuredSchemata.size() == 0 ||
(configuredSchemata.size() == 1 && StringUtils.isBlank(configuredSchemata.get(0).getInputSchema()))) {
try {
for (SchemaDefinition schema : getSchemata0()) {
inputSchemata.add(schema.getName());
List<String> list = inputSchemataPerCatalog.get(schema.getCatalog().getName());

if (list == null) {
list = new ArrayList<String>();
inputSchemataPerCatalog.put(schema.getCatalog().getName(), list);
}

list.add(schema.getName());
}
}
catch (Exception e) {
log.error("Could not load schemata", e);
}
// [#1312] Allow for ommitting inputSchema configuration. Generate all schemata instead.
if (configuredSchemata.size() == 1 && StringUtils.isBlank(configuredSchemata.get(0).getInputSchema())) {
initAllSchemata();
}
else if (configuredCatalogs.size() == 1 && StringUtils.isBlank(configuredCatalogs.get(0).getInputCatalog())
&& configuredCatalogs.get(0).getSchemata().size() == 1 && StringUtils.isBlank(configuredCatalogs.get(0).getSchemata().get(0).getInputSchema())) {
initAllSchemata();
}
else if (configuredCatalogs.isEmpty()) {
inputSchemataPerCatalog.put("", inputSchemata);
Expand Down Expand Up @@ -551,6 +539,25 @@ else if (configuredCatalogs.isEmpty()) {
return inputSchemata;
}

private void initAllSchemata() {
try {
for (SchemaDefinition schema : getSchemata0()) {
inputSchemata.add(schema.getName());
List<String> list = inputSchemataPerCatalog.get(schema.getCatalog().getName());

if (list == null) {
list = new ArrayList<String>();
inputSchemataPerCatalog.put(schema.getCatalog().getName(), list);
}

list.add(schema.getName());
}
}
catch (Exception e) {
log.error("Could not load schemata", e);
}
}

@Override
public final List<String> getInputSchemata(CatalogDefinition catalog) {
return getInputSchemata(catalog.getInputName());
Expand Down

0 comments on commit a79e800

Please sign in to comment.