Search in sources :

Example 1 with DefaultCheckConstraintDefinition

use of org.jooq.util.DefaultCheckConstraintDefinition 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 2 with DefaultCheckConstraintDefinition

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

the class HSQLDBDatabase method loadCheckConstraints.

@Override
protected void loadCheckConstraints(DefaultRelations relations) throws SQLException {
    TableConstraints tc = TABLE_CONSTRAINTS.as("tc");
    CheckConstraints cc = CHECK_CONSTRAINTS.as("cc");
    // [#2808] [#3019] Workaround for bad handling of JOIN .. USING
    Field<String> constraintName = field(name(cc.CONSTRAINT_NAME.getName()), String.class);
    for (Record record : create().select(tc.TABLE_SCHEMA, tc.TABLE_NAME, constraintName, 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(constraintName), record.get(cc.CHECK_CLAUSE)));
        }
    }
}
Also used : TableConstraints(org.jooq.util.hsqldb.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.hsqldb.information_schema.tables.CheckConstraints)

Aggregations

Record (org.jooq.Record)2 DefaultCheckConstraintDefinition (org.jooq.util.DefaultCheckConstraintDefinition)2 SchemaDefinition (org.jooq.util.SchemaDefinition)2 TableDefinition (org.jooq.util.TableDefinition)2 CheckConstraints (org.jooq.util.hsqldb.information_schema.tables.CheckConstraints)1 TableConstraints (org.jooq.util.hsqldb.information_schema.tables.TableConstraints)1 CheckConstraints (org.jooq.util.postgres.information_schema.tables.CheckConstraints)1 TableConstraints (org.jooq.util.postgres.information_schema.tables.TableConstraints)1