[jOOQ/jOOQ#10280] Add Meta.detach() to create an in-memory copy of a Meta implementation

This commit is contained in:
Lukas Eder 2020-06-15 17:12:36 +02:00
parent 88aa871b8e
commit 580ea3e837
5 changed files with 18 additions and 12 deletions

View File

@ -287,6 +287,12 @@ public interface Meta extends Scope {
*/
Meta filterIndexes(Predicate<? super Index> filter);
/**
* Eager-create an in-memory copy of this {@link Meta} instance without any
* connection to the original data source.
*/
Meta detach() throws DataAccessException;
/**
* Generate a creation script for the entire meta data.
*

View File

@ -460,6 +460,11 @@ abstract class AbstractMeta extends AbstractScope implements Meta, Serializable
);
}
@Override
public final Meta detach() {
return new DetachedMeta(this);
}
@Override
public final Queries ddl() {
return ddl(new DDLExportConfiguration());

View File

@ -52,7 +52,6 @@ import org.jooq.Field;
import org.jooq.ForeignKey;
import org.jooq.Index;
import org.jooq.Meta;
import org.jooq.MetaProvider;
import org.jooq.Name;
import org.jooq.Package;
import org.jooq.Record;
@ -77,11 +76,7 @@ final class DetachedMeta extends AbstractMeta {
private static final long serialVersionUID = 5561057000510740144L;
private Meta delegate;
static Meta detach(MetaProvider provider) {
return new DetachedMeta(provider.provide());
}
private DetachedMeta(Meta meta) {
DetachedMeta(Meta meta) {
super(meta.configuration());
delegate = meta;
@ -224,7 +219,7 @@ final class DetachedMeta extends AbstractMeta {
}
static <R extends Record> DetachedTable<R> copyOf(Table<R> table, Schema owner) {
DetachedTable<R> result = new DetachedTable<>(table.getUnqualifiedName(), owner, DSL.comment(table.getComment()));
DetachedTable<R> result = new DetachedTable<>(table.getUnqualifiedName(), owner, table.getCommentPart());
for (Field<?> field : table.fields())
DetachedTable.createField(field.getName(), field.getDataType(), result, field.getComment());

View File

@ -233,7 +233,7 @@ final class FilteredMeta extends AbstractMeta {
private transient List<Schema> schemas;
private FilteredCatalog(Catalog delegate) {
super(delegate.getQualifiedName(), DSL.comment(delegate.getComment()));
super(delegate.getQualifiedName(), delegate.getCommentPart());
this.delegate = delegate;
}
@ -261,7 +261,7 @@ final class FilteredMeta extends AbstractMeta {
private transient List<Sequence<?>> sequences;
private FilteredSchema(FilteredCatalog catalog, Schema delegate) {
super(delegate.getQualifiedName(), catalog, DSL.comment(delegate.getComment()));
super(delegate.getQualifiedName(), catalog, delegate.getCommentPart());
this.delegate = delegate;
}
@ -325,7 +325,7 @@ final class FilteredMeta extends AbstractMeta {
private transient List<ForeignKey<R, ?>> references;
private FilteredTable(FilteredSchema schema, Table<R> delegate) {
super(delegate.getQualifiedName(), schema, null, null, DSL.comment(delegate.getComment()), delegate.getOptions());
super(delegate.getQualifiedName(), schema, null, null, delegate.getCommentPart(), delegate.getOptions());
this.delegate = delegate;

View File

@ -96,9 +96,9 @@ final class TranslatingMetaProvider implements MetaProvider {
for (Source script : scripts)
initializer.loadScript(script);
return DetachedMeta.detach(new DefaultMetaProvider(
return new DetachedMeta(new DefaultMetaProvider(
configuration.derive().set(initializer.connection).set(configuration.settings().getInterpreterDialect())
));
).provide());
}
finally {
JDBCUtils.safeClose(initializer);