Search in sources :

Example 1 with Catalog

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

the class AbstractMetaDatabase method getCatalogs0.

@Override
protected List<CatalogDefinition> getCatalogs0() throws SQLException {
    List<CatalogDefinition> result = new ArrayList<>();
    for (Catalog catalog : getCatalogsFromMeta()) result.add(new CatalogDefinition(this, catalog.getName(), ""));
    result.sort(COMP);
    return result;
}
Also used : ArrayList(java.util.ArrayList) Catalog(org.jooq.Catalog)

Example 2 with Catalog

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

the class InformationSchemaExport method exportCatalogs.

static final InformationSchema exportCatalogs(Configuration configuration, List<Catalog> catalogs) {
    InformationSchema result = new InformationSchema();
    Set<Table<?>> includedTables = new LinkedHashSet<>();
    for (Catalog c : catalogs) for (Schema s : c.getSchemas()) includedTables.addAll(s.getTables());
    for (Catalog c : catalogs) {
        exportCatalog0(result, c);
        for (Schema s : c.getSchemas()) {
            exportSchema0(result, s);
            for (Domain<?> d : s.getDomains()) exportDomain0(configuration, result, d);
            for (Table<?> t : s.getTables()) exportTable0(configuration, result, t, includedTables);
            for (Sequence<?> q : s.getSequences()) exportSequence0(configuration, result, q);
        }
    }
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Table(org.jooq.Table) InformationSchema(org.jooq.util.xml.jaxb.InformationSchema) Schema(org.jooq.Schema) InformationSchema(org.jooq.util.xml.jaxb.InformationSchema) Catalog(org.jooq.Catalog)

Example 3 with Catalog

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

the class DefaultParseContext method parseRename.

private final DDLQuery parseRename() {
    parseKeyword("RENAME");
    switch(characterUpper()) {
        case 'C':
            if (parseKeywordIf("COLUMN")) {
                TableField<?, ?> oldName = parseFieldName();
                parseKeyword("AS", "TO");
                return dsl.alterTable(oldName.getTable()).renameColumn(oldName).to(parseFieldName());
            }
            break;
        case 'D':
            if (parseKeywordIf("DATABASE")) {
                Catalog oldName = parseCatalogName();
                parseKeyword("AS", "TO");
                return dsl.alterDatabase(oldName).renameTo(parseCatalogName());
            }
            break;
        case 'I':
            if (parseKeywordIf("INDEX")) {
                Name oldName = parseIndexName();
                parseKeyword("AS", "TO");
                return dsl.alterIndex(oldName).renameTo(parseIndexName());
            }
            break;
        case 'S':
            if (parseKeywordIf("SCHEMA")) {
                Schema oldName = parseSchemaName();
                parseKeyword("AS", "TO");
                return dsl.alterSchema(oldName).renameTo(parseSchemaName());
            } else if (parseKeywordIf("SEQUENCE")) {
                Sequence<?> oldName = parseSequenceName();
                parseKeyword("AS", "TO");
                return dsl.alterSequence(oldName).renameTo(parseSequenceName());
            }
            break;
        case 'V':
            if (parseKeywordIf("VIEW")) {
                Table<?> oldName = parseTableName();
                parseKeyword("AS", "TO");
                return dsl.alterView(oldName).renameTo(parseTableName());
            }
            break;
    }
    // If all of the above fails, we can assume we're renaming a table.
    parseKeywordIf("TABLE");
    Table<?> oldName = parseTableName();
    parseKeyword("AS", "TO");
    return dsl.alterTable(oldName).renameTo(parseTableName());
}
Also used : Schema(org.jooq.Schema) ParseSearchSchema(org.jooq.conf.ParseSearchSchema) DSL.currentSchema(org.jooq.impl.DSL.currentSchema) Sequence(org.jooq.Sequence) DSL.currentCatalog(org.jooq.impl.DSL.currentCatalog) Catalog(org.jooq.Catalog) Name(org.jooq.Name) DSL.systemName(org.jooq.impl.DSL.systemName)

Example 4 with Catalog

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

the class AbstractMeta method lookupTable.

final Table<?> lookupTable(Table<?> table) {
    // TODO: This is a re-occurring pattern in Meta implementations. Should we have a more generic way to look up objects in a Catalog/Schema?
    Catalog catalog = getCatalog(table.getCatalog().getName());
    if (catalog == null)
        return null;
    Schema schema = catalog.getSchema(table.getSchema().getName());
    if (schema == null)
        return null;
    return schema.getTable(table.getName());
}
Also used : InformationSchema(org.jooq.util.xml.jaxb.InformationSchema) Schema(org.jooq.Schema) Catalog(org.jooq.Catalog)

Example 5 with Catalog

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

the class SchemaImpl method accept.

@Override
public final void accept(Context<?> ctx) {
    if (ctx.qualifyCatalog()) {
        Catalog mappedCatalog = getMappedCatalog(ctx, getCatalog());
        if (mappedCatalog != null && !"".equals(mappedCatalog.getName()))
            ctx.visit(mappedCatalog).sql('.');
    }
    Schema mappedSchema = getMappedSchema(ctx, this);
    ctx.visit(mappedSchema != null ? mappedSchema.getUnqualifiedName() : getUnqualifiedName());
}
Also used : Tools.getMappedSchema(org.jooq.impl.Tools.getMappedSchema) Schema(org.jooq.Schema) Tools.getMappedCatalog(org.jooq.impl.Tools.getMappedCatalog) Catalog(org.jooq.Catalog)

Aggregations

Catalog (org.jooq.Catalog)12 Schema (org.jooq.Schema)8 Table (org.jooq.Table)5 InformationSchema (org.jooq.util.xml.jaxb.InformationSchema)5 LinkedHashSet (java.util.LinkedHashSet)4 ArrayList (java.util.ArrayList)3 Name (org.jooq.Name)3 DSL.currentCatalog (org.jooq.impl.DSL.currentCatalog)3 List (java.util.List)2 Map (java.util.Map)2 Configuration (org.jooq.Configuration)2 Sequence (org.jooq.Sequence)2 FALSE (java.lang.Boolean.FALSE)1 TRUE (java.lang.Boolean.TRUE)1 BigInteger (java.math.BigInteger)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Collections.emptyList (java.util.Collections.emptyList)1 Comparator.comparing (java.util.Comparator.comparing)1 Comparator.comparingInt (java.util.Comparator.comparingInt)1