Search in sources :

Example 1 with DefaultDomainDefinition

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

the class PostgresDatabase method getDomains0.

@SuppressWarnings("unchecked")
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
    List<DomainDefinition> result = new ArrayList<DomainDefinition>();
    if (existAll(PG_CONSTRAINT, PG_TYPE)) {
        PgNamespace n = PG_NAMESPACE.as("n");
        PgConstraint c = PG_CONSTRAINT.as("c");
        PgType d = PG_TYPE.as("d");
        PgType b = PG_TYPE.as("b");
        Field<String[]> src = field(name("domains", "src"), String[].class);
        for (Record record : create().withRecursive("domains", "domain_id", "base_id", "typbasetype", "src").as(select(oid(d), oid(d), d.TYPBASETYPE, array(c.CONSRC)).from(d).join(n).on(oid(n).eq(d.TYPNAMESPACE)).leftJoin(c).on(oid(d).eq(c.CONTYPID)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).unionAll(select(field(name("domains", "domain_id"), Long.class), oid(d), d.TYPBASETYPE, decode().when(c.CONSRC.isNull(), src).otherwise(arrayAppend(src, c.CONSRC))).from(name("domains")).join(d).on(field(name("domains", d.TYPBASETYPE.getName())).eq(oid(d))).leftJoin(c).on(oid(d).eq(c.CONTYPID)))).select(n.NSPNAME, d.TYPNAME, d.TYPNOTNULL, d.TYPDEFAULT, b.TYPNAME, b.TYPLEN, src).from(d).join(name("domains")).on(field(name("domains", "typbasetype")).eq(0)).and(field(name("domains", "domain_id")).eq(oid(d))).join(b).on(field(name("domains", "base_id")).eq(oid(b))).join(n).on(oid(n).eq(d.TYPNAMESPACE)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata()))) {
            SchemaDefinition schema = getSchema(record.get(n.NSPNAME));
            DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(b.TYPNAME), record.get(b.TYPLEN), record.get(b.TYPLEN), // ?
            0, !record.get(d.TYPNOTNULL, boolean.class), record.get(d.TYPDEFAULT), name(record.get(n.NSPNAME), record.get(b.TYPNAME)));
            DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.TYPNAME), baseType);
            domain.addCheckClause(record.get(src));
            result.add(domain);
        }
    }
    return result;
}
Also used : SchemaDefinition(org.jooq.util.SchemaDefinition) DomainDefinition(org.jooq.util.DomainDefinition) DefaultDomainDefinition(org.jooq.util.DefaultDomainDefinition) PgType(org.jooq.util.postgres.pg_catalog.tables.PgType) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) ArrayList(java.util.ArrayList) DefaultDataTypeDefinition(org.jooq.util.DefaultDataTypeDefinition) DataTypeDefinition(org.jooq.util.DataTypeDefinition) DefaultDomainDefinition(org.jooq.util.DefaultDomainDefinition) PgConstraint(org.jooq.util.postgres.pg_catalog.tables.PgConstraint) Record(org.jooq.Record) PgNamespace(org.jooq.util.postgres.pg_catalog.tables.PgNamespace)

Aggregations

ArrayList (java.util.ArrayList)1 Record (org.jooq.Record)1 DataTypeDefinition (org.jooq.util.DataTypeDefinition)1 DefaultDataTypeDefinition (org.jooq.util.DefaultDataTypeDefinition)1 DefaultDomainDefinition (org.jooq.util.DefaultDomainDefinition)1 DomainDefinition (org.jooq.util.DomainDefinition)1 SchemaDefinition (org.jooq.util.SchemaDefinition)1 PgConstraint (org.jooq.util.postgres.pg_catalog.tables.PgConstraint)1 PgNamespace (org.jooq.util.postgres.pg_catalog.tables.PgNamespace)1 PgType (org.jooq.util.postgres.pg_catalog.tables.PgType)1