Search in sources :

Example 31 with TableDefinition

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

the class PostgresDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) throws SQLException {
    for (Record record : primaryKeys(getInputSchemata())) {
        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.addPrimaryKey(key, table, table.getColumn(columnName));
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record)

Example 32 with TableDefinition

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

the class MySQLDatabase method loadPrimaryKeys.

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

Example 33 with TableDefinition

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

the class PostgresDatabase method loadCheckConstraints.

@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
    CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
    // [#10940] [#10992] Workaround for issue caused by re-using implicit join paths
    PgConstraint pc = PG_CONSTRAINT.as("pc");
    for (Record record : create().select(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, pc.CONNAME.as(cc.CONSTRAINT_NAME), replace(field("pg_get_constraintdef({0}.oid)", VARCHAR, pc), inline("CHECK "), inline("")).as(cc.CHECK_CLAUSE)).from(pc).where(pc.pgClass().pgNamespace().NSPNAME.in(getInputSchemata())).and(pc.CONTYPE.eq(inline("c"))).unionAll(getIncludeSystemCheckConstraints() ? select(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, cc.CONSTRAINT_NAME, cc.CHECK_CLAUSE).from(pc).join(cc).on(pc.CONNAME.eq(cc.CONSTRAINT_NAME)).and(pc.pgNamespace().NSPNAME.eq(cc.CONSTRAINT_NAME)).where(pc.pgNamespace().NSPNAME.in(getInputSchemata())).and(row(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, cc.CONSTRAINT_NAME).notIn(select(pc.pgClass().pgNamespace().NSPNAME, pc.pgClass().RELNAME, pc.CONNAME).from(pc).where(pc.CONTYPE.eq(inline("c"))))) : select(inline(""), inline(""), inline(""), inline("")).where(falseCondition())).orderBy(1, 2, 3)) {
        SchemaDefinition schema = getSchema(record.get(pc.pgClass().pgNamespace().NSPNAME));
        TableDefinition table = getTable(schema, record.get(pc.pgClass().RELNAME));
        if (table != null) {
            relations.addCheckConstraint(table, new DefaultCheckConstraintDefinition(schema, table, record.get(cc.CONSTRAINT_NAME), record.get(cc.CHECK_CLAUSE)));
        }
    }
}
Also used : SchemaDefinition(org.jooq.meta.SchemaDefinition) PgConstraint(org.jooq.meta.postgres.pg_catalog.tables.PgConstraint) TableDefinition(org.jooq.meta.TableDefinition) Record(org.jooq.Record) DefaultCheckConstraintDefinition(org.jooq.meta.DefaultCheckConstraintDefinition) CheckConstraints(org.jooq.meta.postgres.information_schema.tables.CheckConstraints)

Example 34 with TableDefinition

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

the class XMLDatabase method loadUniqueKeys.

@Override
protected void loadUniqueKeys(DefaultRelations relations) {
    for (KeyColumnUsage usage : keyColumnUsage(UNIQUE)) {
        SchemaDefinition schema = getSchema(usage.getConstraintSchema());
        String key = usage.getConstraintName();
        String tableName = usage.getTableName();
        String columnName = usage.getColumnName();
        TableConstraint tc = tableConstraint(usage.getConstraintCatalog(), usage.getConstraintSchema(), usage.getConstraintName());
        TableDefinition table = getTable(schema, tableName);
        if (table != null)
            relations.addUniqueKey(key, table, table.getColumn(columnName), tc != null && !FALSE.equals(tc.isEnforced()));
    }
}
Also used : KeyColumnUsage(org.jooq.util.xml.jaxb.KeyColumnUsage) SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) TableConstraint(org.jooq.util.xml.jaxb.TableConstraint)

Example 35 with TableDefinition

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

the class XMLDatabase method loadPrimaryKeys.

@Override
protected void loadPrimaryKeys(DefaultRelations relations) {
    for (KeyColumnUsage usage : keyColumnUsage(PRIMARY_KEY)) {
        SchemaDefinition schema = getSchema(usage.getConstraintSchema());
        String key = usage.getConstraintName();
        String tableName = usage.getTableName();
        String columnName = usage.getColumnName();
        TableConstraint tc = tableConstraint(usage.getConstraintCatalog(), usage.getConstraintSchema(), usage.getConstraintName());
        TableDefinition table = getTable(schema, tableName);
        if (table != null)
            relations.addPrimaryKey(key, table, table.getColumn(columnName), tc != null && !FALSE.equals(tc.isEnforced()));
    }
}
Also used : KeyColumnUsage(org.jooq.util.xml.jaxb.KeyColumnUsage) SchemaDefinition(org.jooq.meta.SchemaDefinition) TableDefinition(org.jooq.meta.TableDefinition) TableConstraint(org.jooq.util.xml.jaxb.TableConstraint)

Aggregations

TableDefinition (org.jooq.meta.TableDefinition)67 SchemaDefinition (org.jooq.meta.SchemaDefinition)47 Record (org.jooq.Record)44 ArrayList (java.util.ArrayList)23 IndexColumnDefinition (org.jooq.meta.IndexColumnDefinition)16 IndexDefinition (org.jooq.meta.IndexDefinition)14 List (java.util.List)12 ColumnDefinition (org.jooq.meta.ColumnDefinition)12 IOException (java.io.IOException)10 DefaultIndexColumnDefinition (org.jooq.meta.DefaultIndexColumnDefinition)10 Result (org.jooq.Result)9 CatalogDefinition (org.jooq.meta.CatalogDefinition)9 EnumDefinition (org.jooq.meta.EnumDefinition)9 RoutineDefinition (org.jooq.meta.RoutineDefinition)9 Arrays.asList (java.util.Arrays.asList)8 TableType (org.jooq.TableOptions.TableType)8 AbstractIndexDefinition (org.jooq.meta.AbstractIndexDefinition)8 DefaultCheckConstraintDefinition (org.jooq.meta.DefaultCheckConstraintDefinition)8 PackageDefinition (org.jooq.meta.PackageDefinition)8 SequenceDefinition (org.jooq.meta.SequenceDefinition)8