[jOOQ/jOOQ#11567] Add Database.getSources()
This returns a Map<Definition, String> as an alternative way to produce source code for generated objects. Implementations are offered for BigQuery and Exasol, for now.
This commit is contained in:
parent
c8c2248376
commit
ef59a15ddc
@ -59,6 +59,7 @@ import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
@ -219,6 +220,7 @@ public abstract class AbstractDatabase implements Database {
|
||||
// Loaded definitions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
private Map<Definition, String> sources;
|
||||
private List<String> inputCatalogs;
|
||||
private List<String> inputSchemata;
|
||||
private Map<String, List<String>> inputSchemataPerCatalog;
|
||||
@ -598,6 +600,19 @@ public abstract class AbstractDatabase implements Database {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Map<Definition, String> getSources() {
|
||||
if (sources == null) {
|
||||
sources = new LinkedHashMap<>();
|
||||
onError(ERROR, "Could not load sources", () -> {
|
||||
sources = getSources0();
|
||||
log.info("Sequences fetched", fetchedSize(sources.values(), sources.values()));
|
||||
});
|
||||
}
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final List<CatalogDefinition> getCatalogs() {
|
||||
if (catalogs == null) {
|
||||
@ -2702,7 +2717,7 @@ public abstract class AbstractDatabase implements Database {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static final String fetchedSize(List<?> fetched, List<?> included) {
|
||||
protected static final String fetchedSize(Collection<?> fetched, Collection<?> included) {
|
||||
return fetched.size() + " (" + included.size() + " included, " + (fetched.size() - included.size()) + " excluded)";
|
||||
}
|
||||
|
||||
@ -3080,6 +3095,13 @@ public abstract class AbstractDatabase implements Database {
|
||||
*/
|
||||
protected abstract DSLContext create0();
|
||||
|
||||
/**
|
||||
* Retrieve ALL source code from the database.
|
||||
*/
|
||||
protected Map<Definition, String> getSources0() throws SQLException {
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve ALL indexes from the database
|
||||
*/
|
||||
|
||||
@ -72,11 +72,11 @@ public abstract class AbstractDefinition implements Definition {
|
||||
private final String source;
|
||||
|
||||
// [#2238] Some caches for strings that are heavy to calculate in large schemas
|
||||
private transient String qualifiedInputName;
|
||||
private transient String qualifiedOutputName;
|
||||
private transient Name qualifiedInputNamePart;
|
||||
private transient Name qualifiedOutputNamePart;
|
||||
private transient Integer hashCode;
|
||||
private transient String qualifiedInputName;
|
||||
private transient String qualifiedOutputName;
|
||||
private transient Name qualifiedInputNamePart;
|
||||
private transient Name qualifiedOutputNamePart;
|
||||
private transient Integer hashCode;
|
||||
|
||||
public AbstractDefinition(Database database, SchemaDefinition schema, String name) {
|
||||
this(database, schema, name, null);
|
||||
@ -330,6 +330,6 @@ public abstract class AbstractDefinition implements Definition {
|
||||
|
||||
@Override
|
||||
public final String getSource() {
|
||||
return source;
|
||||
return source != null ? source : getDatabase().getSources().get(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,6 +41,7 @@ package org.jooq.meta;
|
||||
import java.sql.Connection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
@ -71,6 +72,11 @@ import org.jooq.meta.jaxb.SyntheticViewType;
|
||||
*/
|
||||
public interface Database extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* Get the sources for all objects that offer sources.
|
||||
*/
|
||||
Map<Definition, String> getSources();
|
||||
|
||||
/**
|
||||
* The catalogs generated from this database.
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user