Search in sources :

Example 1 with Meta

use of org.jooq.Meta in project jOOQ by jOOQ.

the class VersionImpl method init.

private static final Meta init(DSLContext ctx) {
    Meta result = ctx.meta("");
    // TODO: Instead of reusing interpreter search path, we should have some dedicated
    // configuration for this.
    // TODO: Should this be moved in DSLContext.meta()?
    List<InterpreterSearchSchema> searchPath = ctx.settings().getInterpreterSearchPath();
    for (InterpreterSearchSchema schema : searchPath) result = result.apply(createSchema(schema(name(schema.getCatalog(), schema.getSchema()))));
    return result;
}
Also used : Meta(org.jooq.Meta) InterpreterSearchSchema(org.jooq.conf.InterpreterSearchSchema)

Example 2 with Meta

use of org.jooq.Meta in project jOOQ by jOOQ.

the class MigrationImpl method revertUntrackedQueries.

private final Queries revertUntrackedQueries(Set<Schema> includedSchemas) {
    Commit currentCommit = currentCommit();
    Meta currentMeta = currentCommit.meta();
    Meta existingMeta = dsl().meta().filterSchemas(includedSchemas::contains);
    Set<Schema> expectedSchemas = new HashSet<>();
    expectedSchemas.addAll(lookup(from().meta().getSchemas()));
    expectedSchemas.addAll(lookup(to().meta().getSchemas()));
    expectedSchemas.retainAll(includedSchemas);
    schemaLoop: for (Schema schema : existingMeta.getSchemas()) {
        if (!includedSchemas.contains(schema))
            continue schemaLoop;
        // TODO Why is this qualification necessary?
        existingMeta = existingMeta.apply(dropTableIfExists(schema.getQualifiedName().append(CHANGELOG.getUnqualifiedName())).cascade());
        if (!expectedSchemas.contains(schema))
            existingMeta = existingMeta.apply(dropSchemaIfExists(schema).cascade());
        else
            currentMeta = currentMeta.apply(createSchemaIfNotExists(schema));
    }
    return existingMeta.migrateTo(currentMeta);
}
Also used : Meta(org.jooq.Meta) Commit(org.jooq.Commit) MigrationSchema(org.jooq.conf.MigrationSchema) Schema(org.jooq.Schema) InterpreterSearchSchema(org.jooq.conf.InterpreterSearchSchema) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with Meta

use of org.jooq.Meta in project jOOQ by jOOQ.

the class CatalogMetaImpl method filterSchemas.

static final Meta filterSchemas(Configuration configuration, Set<Schema> schemas) {
    Map<Name, Catalog> c = new LinkedHashMap<>();
    Map<Name, List<Schema>> mapping = new LinkedHashMap<>();
    for (Schema schema : schemas) mapping.computeIfAbsent(nameOrDefault(schema.getCatalog()), k -> new ArrayList<>()).add(schema);
    for (Schema schema : schemas) c.computeIfAbsent(nameOrDefault(schema.getCatalog()), k -> new CatalogImpl(k) {

        @Override
        public List<Schema> getSchemas() {
            return mapping.get(getQualifiedName());
        }
    });
    return filterCatalogs(configuration, new LinkedHashSet<>(c.values())).filterSchemas(schemas::contains);
}
Also used : Arrays(java.util.Arrays) Predicate(java.util.function.Predicate) Name(org.jooq.Name) Set(java.util.Set) Table(org.jooq.Table) EMPTY_CATALOG(org.jooq.impl.Tools.EMPTY_CATALOG) Meta(org.jooq.Meta) ArrayList(java.util.ArrayList) QueryPart(org.jooq.QueryPart) LinkedHashMap(java.util.LinkedHashMap) Configuration(org.jooq.Configuration) List(java.util.List) Catalog(org.jooq.Catalog) AbstractNamed.nameOrDefault(org.jooq.impl.AbstractNamed.nameOrDefault) Map(java.util.Map) Schema(org.jooq.Schema) LinkedHashSet(java.util.LinkedHashSet) LinkedHashSet(java.util.LinkedHashSet) Schema(org.jooq.Schema) ArrayList(java.util.ArrayList) List(java.util.List) Catalog(org.jooq.Catalog) Name(org.jooq.Name) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Meta (org.jooq.Meta)3 LinkedHashSet (java.util.LinkedHashSet)2 Schema (org.jooq.Schema)2 InterpreterSearchSchema (org.jooq.conf.InterpreterSearchSchema)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Predicate (java.util.function.Predicate)1 Catalog (org.jooq.Catalog)1 Commit (org.jooq.Commit)1 Configuration (org.jooq.Configuration)1 Name (org.jooq.Name)1 QueryPart (org.jooq.QueryPart)1 Table (org.jooq.Table)1 MigrationSchema (org.jooq.conf.MigrationSchema)1 AbstractNamed.nameOrDefault (org.jooq.impl.AbstractNamed.nameOrDefault)1