Search in sources :

Example 6 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class PostgresDatabase method loadCheckConstraints.

@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
    TableConstraints tc = TABLE_CONSTRAINTS.as("tc");
    CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
    for (Record record : create().select(tc.TABLE_SCHEMA, tc.TABLE_NAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE).from(tc).join(cc).using(tc.CONSTRAINT_CATALOG, tc.CONSTRAINT_SCHEMA, tc.CONSTRAINT_NAME).where(tc.TABLE_SCHEMA.in(getInputSchemata())).fetch()) {
        SchemaDefinition schema = getSchema(record.get(tc.TABLE_SCHEMA));
        TableDefinition table = getTable(schema, record.get(tc.TABLE_NAME));
        if (table != null) {
            relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(cc.CONSTRAINT_NAME), record.get(cc.CHECK_CLAUSE)));
        }
    }
}
Also used : TableConstraints(org.jooq.util.postgres.information_schema.tables.TableConstraints) SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record) DefaultCheckConstraintDefinition(org.jooq.util.DefaultCheckConstraintDefinition) CheckConstraints(org.jooq.util.postgres.information_schema.tables.CheckConstraints)

Example 7 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class HSQLDBDatabase method loadUniqueKeys.

@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys("UNIQUE")) {
        SchemaDefinition schema = getSchema(record.get(KEY_COLUMN_USAGE.TABLE_SCHEMA));
        String key = record.get(KEY_COLUMN_USAGE.CONSTRAINT_NAME);
        String tableName = record.get(KEY_COLUMN_USAGE.TABLE_NAME);
        String columnName = record.get(KEY_COLUMN_USAGE.COLUMN_NAME);
        TableDefinition table = getTable(schema, tableName);
        if (table != null) {
            relations.addUniqueKey(key, table.getColumn(columnName));
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 8 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class MySQLDatabase method getTables0.

@Override
protected List<TableDefinition> getTables0() throws SQLException {
    List<TableDefinition> result = new ArrayList<TableDefinition>();
    for (Record record : create().select(Tables.TABLE_SCHEMA, Tables.TABLE_NAME, Tables.TABLE_COMMENT).from(TABLES).where(Tables.TABLE_SCHEMA.in(getInputSchemata())).orderBy(Tables.TABLE_SCHEMA, Tables.TABLE_NAME).fetch()) {
        SchemaDefinition schema = getSchema(record.get(Tables.TABLE_SCHEMA));
        String name = record.get(Tables.TABLE_NAME);
        String comment = record.get(Tables.TABLE_COMMENT);
        MySQLTableDefinition table = new MySQLTableDefinition(schema, name, comment);
        result.add(table);
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) ArrayList(java.util.ArrayList) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Example 9 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class MySQLDatabase method loadForeignKeys.

@Override
protected void loadForeignKeys(DefaultRelations relations) throws SQLException {
    for (Record record : create().select(ReferentialConstraints.CONSTRAINT_SCHEMA, ReferentialConstraints.CONSTRAINT_NAME, ReferentialConstraints.TABLE_NAME, ReferentialConstraints.REFERENCED_TABLE_NAME, ReferentialConstraints.UNIQUE_CONSTRAINT_NAME, ReferentialConstraints.UNIQUE_CONSTRAINT_SCHEMA, KeyColumnUsage.COLUMN_NAME).from(REFERENTIAL_CONSTRAINTS).join(KEY_COLUMN_USAGE).on(ReferentialConstraints.CONSTRAINT_SCHEMA.equal(KeyColumnUsage.CONSTRAINT_SCHEMA)).and(ReferentialConstraints.CONSTRAINT_NAME.equal(KeyColumnUsage.CONSTRAINT_NAME)).where(ReferentialConstraints.CONSTRAINT_SCHEMA.in(getInputSchemata())).orderBy(KeyColumnUsage.CONSTRAINT_SCHEMA.asc(), KeyColumnUsage.CONSTRAINT_NAME.asc(), KeyColumnUsage.ORDINAL_POSITION.asc()).fetch()) {
        SchemaDefinition foreignKeySchema = getSchema(record.get(ReferentialConstraints.CONSTRAINT_SCHEMA));
        SchemaDefinition uniqueKeySchema = getSchema(record.get(ReferentialConstraints.UNIQUE_CONSTRAINT_SCHEMA));
        String foreignKey = record.get(ReferentialConstraints.CONSTRAINT_NAME);
        String foreignKeyColumn = record.get(KeyColumnUsage.COLUMN_NAME);
        String foreignKeyTableName = record.get(ReferentialConstraints.TABLE_NAME);
        String referencedKey = record.get(ReferentialConstraints.UNIQUE_CONSTRAINT_NAME);
        String referencedTableName = record.get(ReferentialConstraints.REFERENCED_TABLE_NAME);
        TableDefinition foreignKeyTable = getTable(foreignKeySchema, foreignKeyTableName);
        if (foreignKeyTable != null) {
            ColumnDefinition column = foreignKeyTable.getColumn(foreignKeyColumn);
            String key = getKeyName(referencedTableName, referencedKey);
            relations.addForeignKey(foreignKey, key, column, uniqueKeySchema);
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record) ColumnDefinition(org.jooq.util.ColumnDefinition)

Example 10 with TableDefinition

use of org.jooq.util.TableDefinition in project jOOQ by jOOQ.

the class H2Database method loadUniqueKeys.

@Override
protected void loadUniqueKeys(DefaultRelations relations) throws SQLException {
    for (Record record : fetchKeys("UNIQUE")) {
        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.getColumn(columnName));
            }
        }
    }
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) TableDefinition(org.jooq.util.TableDefinition) Record(org.jooq.Record)

Aggregations

TableDefinition (org.jooq.util.TableDefinition)37 Record (org.jooq.Record)32 SchemaDefinition (org.jooq.util.SchemaDefinition)28 ColumnDefinition (org.jooq.util.ColumnDefinition)14 ArrayList (java.util.ArrayList)9 KeyColumnUsage (org.jooq.util.xml.jaxb.KeyColumnUsage)3 HashMap (java.util.HashMap)2 DefaultCheckConstraintDefinition (org.jooq.util.DefaultCheckConstraintDefinition)2 DefaultEnumDefinition (org.jooq.util.DefaultEnumDefinition)2 EnumDefinition (org.jooq.util.EnumDefinition)2 StringReader (java.io.StringReader)1 Name (org.jooq.Name)1 Record5 (org.jooq.Record5)1 Record6 (org.jooq.Record6)1 Schema (org.jooq.Schema)1 CSVReader (org.jooq.tools.csv.CSVReader)1 Rdb$indexSegments (org.jooq.util.firebird.rdb.tables.Rdb$indexSegments)1 Rdb$refConstraints (org.jooq.util.firebird.rdb.tables.Rdb$refConstraints)1 Rdb$relationConstraints (org.jooq.util.firebird.rdb.tables.Rdb$relationConstraints)1 CheckConstraints (org.jooq.util.hsqldb.information_schema.tables.CheckConstraints)1