Search in sources :

Example 71 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class H2Database method getTables0.

@Override
protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<>();
    for (TableRecord r : create().select(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME, when(TABLES.TABLE_TYPE.eq(inline("VIEW")), inline(TableType.VIEW.name())).when(TABLES.STORAGE_TYPE.like(inline("%TEMPORARY%")), inline(TableType.TEMPORARY.name())).else_(inline(TableType.TABLE.name())).convertFrom(TableType::valueOf).as("table_type"), TABLES.REMARKS, VIEWS.VIEW_DEFINITION).from(TABLES).leftJoin(VIEWS).on(TABLES.TABLE_SCHEMA.eq(VIEWS.TABLE_SCHEMA)).and(TABLES.TABLE_NAME.eq(VIEWS.TABLE_NAME)).where(TABLES.TABLE_SCHEMA.in(getInputSchemata())).orderBy(TABLES.TABLE_SCHEMA, TABLES.TABLE_NAME).fetch(mapping(TableRecord::new))) {
        SchemaDefinition schema = getSchema(r.schema);
        String source = r.source;
        if (source != null && !source.toLowerCase().startsWith("create"))
            source = "create view \"" + r.table + "\" as " + source;
        if (schema != null)
            result.add(new H2TableDefinition(schema, r.table, r.comment, r.type, source));
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) ArrayList(java.util.ArrayList) TableDefinition(org.jooq.meta.TableDefinition)

Example 72 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class H2Database method getDomains2_0.

private List<DomainDefinition> getDomains2_0() {
    List<DomainDefinition> result = new ArrayList<>();
    Domains d = Tables.DOMAINS.as("d");
    DomainConstraints dc = DOMAIN_CONSTRAINTS.as("dc");
    for (Record record : create().select(d.DOMAIN_SCHEMA, d.DOMAIN_NAME, d.DATA_TYPE, d.CHARACTER_MAXIMUM_LENGTH, coalesce(d.DATETIME_PRECISION, d.NUMERIC_PRECISION).as(d.NUMERIC_PRECISION), d.NUMERIC_SCALE, d.DOMAIN_DEFAULT, dc.checkConstraints().CHECK_CLAUSE).from(d).leftJoin(dc).on(d.DOMAIN_CATALOG.eq(dc.DOMAIN_CATALOG)).and(d.DOMAIN_SCHEMA.eq(dc.DOMAIN_SCHEMA)).and(d.DOMAIN_NAME.eq(dc.DOMAIN_NAME)).where(d.DOMAIN_SCHEMA.in(getInputSchemata())).and(d.DATA_TYPE.ne(inline("ENUM"))).orderBy(d.DOMAIN_SCHEMA, d.DOMAIN_NAME)) {
        SchemaDefinition schema = getSchema(record.get(d.DOMAIN_SCHEMA));
        DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(d.DATA_TYPE), record.get(d.CHARACTER_MAXIMUM_LENGTH), record.get(d.NUMERIC_PRECISION), record.get(d.NUMERIC_SCALE), true, record.get(d.DOMAIN_DEFAULT));
        DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.DOMAIN_NAME), baseType);
        if (!StringUtils.isBlank(record.get(dc.checkConstraints().CHECK_CLAUSE)))
            domain.addCheckClause(record.get(dc.checkConstraints().CHECK_CLAUSE));
        result.add(domain);
    }
    return result;
}
Also used : Domains(org.jooq.meta.hsqldb.information_schema.tables.Domains) DefaultDomainDefinition(org.jooq.meta.DefaultDomainDefinition) SchemaDefinition(org.jooq.meta.SchemaDefinition) DefaultDomainDefinition(org.jooq.meta.DefaultDomainDefinition) DomainDefinition(org.jooq.meta.DomainDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DomainConstraints(org.jooq.meta.hsqldb.information_schema.tables.DomainConstraints) Record(org.jooq.Record) DataTypeDefinition(org.jooq.meta.DataTypeDefinition) DefaultDataTypeDefinition(org.jooq.meta.DefaultDataTypeDefinition)

Example 73 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class H2Database method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
    for (Record record : primaryKeys(getInputSchemata())) {
        SchemaDefinition schema = getSchema(record.get(CONSTRAINTS.TABLE_SCHEMA));
        if (schema != null) {
            String tableName = record.get(CONSTRAINTS.TABLE_NAME);
            String primaryKey = record.get(CONSTRAINTS.CONSTRAINT_NAME);
            String columnName = record.get(INDEXES.COLUMN_NAME);
            TableDefinition table = getTable(schema, tableName);
            if (table != null)
                relations.addPrimaryKey(primaryKey, table, table.getColumn(columnName));
        }
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Example 74 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class H2Database method getInlineEnums2_0.

private void getInlineEnums2_0(List<EnumDefinition> result) {
    // TODO: Re-generate the H2 schema and use generated code to run this query
    create().resultQuery(("" + "select c.TABLE_SCHEMA , c.TABLE_NAME , c.COLUMN_NAME , array_agg(ev.value_name order by ev.VALUE_ORDINAL)\n" + "from INFORMATION_SCHEMA.ENUM_VALUES ev\n" + "join information_schema.columns c\n" + "on ev.OBJECT_SCHEMA = c.TABLE_SCHEMA\n" + "and ev.OBJECT_NAME = c.TABLE_NAME\n" + "and ev.ENUM_IDENTIFIER = c.DTD_IDENTIFIER\n" + "where ev.OBJECT_TYPE = 'TABLE'\n" + "and c.DOMAIN_NAME IS NULL\n" + "group by c.TABLE_SCHEMA , c.TABLE_NAME , c.COLUMN_NAME\n" + "order by 1, 2, 3\n" + "")).coerce(COLUMNS.TABLE_SCHEMA, COLUMNS.TABLE_NAME, COLUMNS.COLUMN_NAME, arrayAgg(COLUMNS.COLUMN_NAME)).forEach(r -> {
        SchemaDefinition schema = getSchema(r.value1());
        if (schema == null)
            return;
        // [#1237] Don't generate enum classes for columns in MySQL tables
        // that are excluded from code generation
        TableDefinition tableDefinition = getTable(schema, r.value2());
        if (tableDefinition != null) {
            ColumnDefinition columnDefinition = tableDefinition.getColumn(r.value3());
            if (columnDefinition != null) {
                // are explicitly forced to another type
                if (getConfiguredForcedType(columnDefinition, columnDefinition.getType()) == null) {
                    String name = r.value2() + "_" + r.value3();
                    DefaultEnumDefinition definition = new DefaultEnumDefinition(schema, name, "");
                    for (String string : r.value4()) definition.addLiteral(string);
                    result.add(definition);
                }
            }
        }
    });
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) DefaultEnumDefinition(org.jooq.meta.DefaultEnumDefinition) DefaultIndexColumnDefinition(org.jooq.meta.DefaultIndexColumnDefinition) ColumnDefinition(org.jooq.meta.ColumnDefinition) IndexColumnDefinition(org.jooq.meta.IndexColumnDefinition)

Example 75 with SchemaDefinition

use of org.jooq.meta.SchemaDefinition in project jOOQ by jOOQ.

the class H2Database method loadUniqueKeys.

@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
    for (Record record : uniqueKeys(getInputSchemata())) {
        SchemaDefinition schema = getSchema(record.get(CONSTRAINTS.TABLE_SCHEMA));
        if (schema != null) {
            String tableName = record.get(CONSTRAINTS.TABLE_NAME);
            String primaryKey = record.get(CONSTRAINTS.CONSTRAINT_NAME);
            String columnName = record.get(INDEXES.COLUMN_NAME);
            TableDefinition table = getTable(schema, tableName);
            if (table != null)
                relations.addUniqueKey(primaryKey, table, table.getColumn(columnName));
        }
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Aggregations

SchemaDefinition (org.jooq.meta.SchemaDefinition)81 Record (org.jooq.Record)51 ArrayList (java.util.ArrayList)46 TableDefinition (org.jooq.meta.TableDefinition)44 DefaultDataTypeDefinition (org.jooq.meta.DefaultDataTypeDefinition)22 DataTypeDefinition (org.jooq.meta.DataTypeDefinition)21 ColumnDefinition (org.jooq.meta.ColumnDefinition)14 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)14 IndexDefinition (org.jooq.meta.IndexDefinition)12 SequenceDefinition (org.jooq.meta.SequenceDefinition)12 List (java.util.List)10 DefaultIndexColumnDefinition (org.jooq.meta.DefaultIndexColumnDefinition)10 DomainDefinition (org.jooq.meta.DomainDefinition)9 RoutineDefinition (org.jooq.meta.RoutineDefinition)9 Result (org.jooq.Result)8 AbstractIndexDefinition (org.jooq.meta.AbstractIndexDefinition)8 DefaultCheckConstraintDefinition (org.jooq.meta.DefaultCheckConstraintDefinition)8 DefaultSequenceDefinition (org.jooq.meta.DefaultSequenceDefinition)8 PackageDefinition (org.jooq.meta.PackageDefinition)8 TableType (org.jooq.TableOptions.TableType)7