use of org.jooq.meta.postgres.information_schema.tables.CheckConstraints 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)));
}
}
}
Aggregations