[#6663] Support new <catalogs/> element in DSLContext.informationSchema()
This commit is contained in:
parent
f12a625dc3
commit
d26730f3f6
@ -379,17 +379,12 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri
|
||||
|
||||
@Override
|
||||
public InformationSchema informationSchema(Catalog catalog) {
|
||||
return InformationSchemaExport.exportSchemas(configuration(), catalog.getSchemas());
|
||||
return InformationSchemaExport.exportCatalogs(configuration(), Arrays.asList(catalog));
|
||||
}
|
||||
|
||||
@Override
|
||||
public InformationSchema informationSchema(Catalog... catalogs) {
|
||||
List<Schema> schemas = new ArrayList<Schema>();
|
||||
|
||||
for (Catalog catalog : catalogs)
|
||||
schemas.addAll(catalog.getSchemas());
|
||||
|
||||
return InformationSchemaExport.exportSchemas(configuration(), schemas);
|
||||
return InformationSchemaExport.exportCatalogs(configuration(), Arrays.asList(catalogs));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -43,6 +43,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.Catalog;
|
||||
import org.jooq.Configuration;
|
||||
import org.jooq.Field;
|
||||
import org.jooq.ForeignKey;
|
||||
@ -71,12 +72,19 @@ final class InformationSchemaExport {
|
||||
static final InformationSchema exportTables(Configuration configuration, List<Table<?>> tables) {
|
||||
InformationSchema result = new InformationSchema();
|
||||
|
||||
Set<Catalog> includedCatalogs = new LinkedHashSet<Catalog>();
|
||||
Set<Schema> includedSchemas = new LinkedHashSet<Schema>();
|
||||
Set<Table<?>> includedTables = new LinkedHashSet<Table<?>>(tables);
|
||||
|
||||
for (Table<?> t : tables)
|
||||
includedSchemas.add(t.getSchema());
|
||||
|
||||
for (Schema s : includedSchemas)
|
||||
includedCatalogs.add(s.getCatalog());
|
||||
|
||||
for (Catalog c : includedCatalogs)
|
||||
exportCatalog0(result, c);
|
||||
|
||||
for (Schema s : includedSchemas)
|
||||
exportSchema0(result, s);
|
||||
|
||||
@ -89,10 +97,18 @@ final class InformationSchemaExport {
|
||||
static final InformationSchema exportSchemas(Configuration configuration, List<Schema> schemas) {
|
||||
InformationSchema result = new InformationSchema();
|
||||
|
||||
Set<Catalog> includedCatalogs = new LinkedHashSet<Catalog>();
|
||||
Set<Table<?>> includedTables = new LinkedHashSet<Table<?>>();
|
||||
for (Schema s : schemas)
|
||||
|
||||
for (Schema s : schemas) {
|
||||
includedCatalogs.add(s.getCatalog());
|
||||
|
||||
for (Table<?> t : s.getTables())
|
||||
includedTables.add(t);
|
||||
}
|
||||
|
||||
for (Catalog c : includedCatalogs)
|
||||
exportCatalog0(result, c);
|
||||
|
||||
for (Schema s : schemas) {
|
||||
exportSchema0(result, s);
|
||||
@ -107,6 +123,33 @@ final class InformationSchemaExport {
|
||||
return result;
|
||||
}
|
||||
|
||||
static final InformationSchema exportCatalogs(Configuration configuration, List<Catalog> catalogs) {
|
||||
InformationSchema result = new InformationSchema();
|
||||
|
||||
Set<Table<?>> includedTables = new LinkedHashSet<Table<?>>();
|
||||
|
||||
for (Catalog c : catalogs)
|
||||
for (Schema s : c.getSchemas())
|
||||
for (Table<?> t : s.getTables())
|
||||
includedTables.add(t);
|
||||
|
||||
for (Catalog c : catalogs) {
|
||||
exportCatalog0(result, c);
|
||||
|
||||
for (Schema s : c.getSchemas()) {
|
||||
exportSchema0(result, s);
|
||||
|
||||
for (Table<?> t : s.getTables())
|
||||
exportTable0(configuration, result, t, includedTables);
|
||||
|
||||
for (Sequence<?> q : s.getSequences())
|
||||
exportSequences0(configuration, result, q);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final void exportSequences0(Configuration configuration, InformationSchema result, Sequence<?> q) {
|
||||
org.jooq.util.xml.jaxb.Sequence iq = new org.jooq.util.xml.jaxb.Sequence();
|
||||
|
||||
@ -131,6 +174,15 @@ final class InformationSchemaExport {
|
||||
result.getSequences().add(iq);
|
||||
}
|
||||
|
||||
private static final void exportCatalog0(InformationSchema result, Catalog c) {
|
||||
org.jooq.util.xml.jaxb.Catalog ic = new org.jooq.util.xml.jaxb.Catalog();
|
||||
|
||||
if (!StringUtils.isBlank(c.getName())) {
|
||||
ic.setCatalogName(c.getName());
|
||||
result.getCatalogs().add(ic);
|
||||
}
|
||||
}
|
||||
|
||||
private static final void exportSchema0(InformationSchema result, Schema s) {
|
||||
org.jooq.util.xml.jaxb.Schema is = new org.jooq.util.xml.jaxb.Schema();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user