This commit is contained in:
Lukas Eder 2020-01-16 14:09:47 +01:00
parent ffd7b0cf87
commit 6bdaee9d42
2 changed files with 33 additions and 0 deletions

View File

@ -205,6 +205,15 @@ public interface Meta extends Scope {
@Support
List<UniqueKey<?>> getPrimaryKeys() throws DataAccessException;
/**
* Get all indexes from the underlying meta data sources.
*
* @throws DataAccessException If something went wrong fetching the meta
* objects
*/
@Support
List<Index> getIndexes() throws DataAccessException;
/**
* Generate a creation script for the entire meta data.
*

View File

@ -51,6 +51,7 @@ import java.util.Map;
import org.jooq.Catalog;
import org.jooq.Configuration;
import org.jooq.DDLExportConfiguration;
import org.jooq.Index;
import org.jooq.Meta;
import org.jooq.Name;
import org.jooq.Named;
@ -78,6 +79,7 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
private Map<Name, List<Table<?>>> cachedUnqualifiedTables;
private Map<Name, List<Sequence<?>>> cachedUnqualifiedSequences;
private List<UniqueKey<?>> cachedPrimaryKeys;
private List<Index> cachedIndexes;
protected AbstractMeta(Configuration configuration) {
super(configuration);
@ -249,9 +251,31 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
protected List<UniqueKey<?>> getPrimaryKeys0() {
List<UniqueKey<?>> result = new ArrayList<>();
for (Table<?> table : getTables())
if (table.getPrimaryKey() != null)
result.add(table.getPrimaryKey());
return result;
}
@Override
public final List<Index> getIndexes() {
initIndexes();
return Collections.unmodifiableList(cachedIndexes);
}
private final void initIndexes() {
if (cachedIndexes == null)
cachedIndexes = new ArrayList<>(getIndexes0());
}
protected List<Index> getIndexes0() {
List<Index> result = new ArrayList<>();
for (Table<?> table : getTables())
result.addAll(table.getIndexes());
return result;
}