use of org.jooq.meta.DefaultDomainDefinition in project jOOQ by jOOQ.
the class PostgresDatabase method getDomains0.
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
List<DomainDefinition> result = new ArrayList<>();
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);
Field<String> constraintDef = field("pg_get_constraintdef({0})", VARCHAR, c.OID);
for (Record record : create().withRecursive("domains", "domain_id", "base_id", "typbasetype", "src").as(select(d.OID, d.OID, d.TYPBASETYPE, when(c.OID.isNotNull(), array(constraintDef))).from(d).join(n).on(n.OID.eq(d.TYPNAMESPACE)).leftJoin(c).on(d.OID.eq(c.CONTYPID)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).unionAll(select(field(name("domains", "domain_id"), Long.class), d.OID, d.TYPBASETYPE, decode().when(c.CONBIN.isNull(), src).otherwise(arrayAppend(src, constraintDef))).from(name("domains")).join(d).on(field(name("domains", d.TYPBASETYPE.getName())).eq(d.OID)).leftJoin(c).on(d.OID.eq(c.CONTYPID)))).select(n.NSPNAME, d.TYPNAME, d.TYPNOTNULL, d.TYPDEFAULT, b.TYPNAME, // See https://github.com/postgres/postgres/blob/master/src/backend/catalog/information_schema.sql
field("information_schema._pg_char_max_length({0}, {1})", INTEGER, d.TYPBASETYPE, d.TYPTYPMOD).as(DOMAINS.CHARACTER_MAXIMUM_LENGTH), field("information_schema._pg_numeric_precision({0}, {1})", INTEGER, d.TYPBASETYPE, d.TYPTYPMOD).as(DOMAINS.NUMERIC_PRECISION), field("information_schema._pg_numeric_scale({0}, {1})", INTEGER, d.TYPBASETYPE, d.TYPTYPMOD).as(DOMAINS.NUMERIC_SCALE), src).from(d).join(name("domains")).on(field(name("domains", "typbasetype")).eq(0)).and(field(name("domains", "domain_id")).eq(d.OID)).join(b).on(field(name("domains", "base_id")).eq(b.OID)).join(n).on(n.OID.eq(d.TYPNAMESPACE)).where(d.TYPTYPE.eq("d")).and(n.NSPNAME.in(getInputSchemata())).orderBy(n.NSPNAME, d.TYPNAME)) {
SchemaDefinition schema = getSchema(record.get(n.NSPNAME));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(b.TYPNAME), record.get(DOMAINS.CHARACTER_MAXIMUM_LENGTH), record.get(DOMAINS.NUMERIC_PRECISION), record.get(DOMAINS.NUMERIC_SCALE), !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;
}
use of org.jooq.meta.DefaultDomainDefinition in project jOOQ by jOOQ.
the class FirebirdDatabase method getDomains0.
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
List<DomainDefinition> result = new ArrayList<>();
Rdb$fields f = RDB$FIELDS;
for (Record record : create().select(trim(f.RDB$FIELD_NAME).as(f.RDB$FIELD_NAME), CHARACTER_LENGTH(f).as("CHAR_LEN"), f.RDB$FIELD_PRECISION, FIELD_SCALE(f).as("FIELD_SCALE"), FIELD_TYPE(f).as("FIELD_TYPE"), DSL.bitOr(f.RDB$NULL_FLAG.nvl((short) 0), f.RDB$NULL_FLAG.nvl((short) 0)).as(f.RDB$NULL_FLAG), trim(f.RDB$VALIDATION_SOURCE).as(f.RDB$VALIDATION_SOURCE), trim(f.RDB$DEFAULT_SOURCE).as(f.RDB$DEFAULT_SOURCE)).from(f).where(f.RDB$FIELD_NAME.notLike(any("RDB$%", "SEC$%", "MON$%"))).orderBy(f.RDB$FIELD_NAME)) {
SchemaDefinition schema = getSchemata().get(0);
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get("FIELD_TYPE", String.class), record.get("CHAR_LEN", short.class), record.get(f.RDB$FIELD_PRECISION), record.get("FIELD_SCALE", Integer.class), record.get(f.RDB$NULL_FLAG) == 0, record.get(f.RDB$DEFAULT_SOURCE) == null ? null : record.get(f.RDB$DEFAULT_SOURCE).replaceAll("(?i:default )", ""));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(f.RDB$FIELD_NAME), baseType);
if (!StringUtils.isBlank(record.get(f.RDB$VALIDATION_SOURCE)))
domain.addCheckClause(record.get(f.RDB$VALIDATION_SOURCE).replaceAll("(?i:check )", ""));
result.add(domain);
}
return result;
}
use of org.jooq.meta.DefaultDomainDefinition in project jOOQ by jOOQ.
the class H2Database method getDomains1_4.
private List<DomainDefinition> getDomains1_4() {
List<DomainDefinition> result = new ArrayList<>();
for (Record record : create().select(DOMAINS.DOMAIN_SCHEMA, DOMAINS.DOMAIN_NAME, DOMAINS.TYPE_NAME, DOMAINS.PRECISION, DOMAINS.SCALE, DOMAINS.IS_NULLABLE, DOMAINS.COLUMN_DEFAULT, DOMAINS.CHECK_CONSTRAINT).from(DOMAINS).where(DOMAINS.DOMAIN_SCHEMA.in(getInputSchemata())).and(DOMAINS.TYPE_NAME.ne(inline("ENUM"))).orderBy(DOMAINS.DOMAIN_SCHEMA, DOMAINS.DOMAIN_NAME)) {
// [#7644] [#11721] H2 puts DATETIME_PRECISION in NUMERIC_SCALE column
boolean isTimestamp = record.get(DOMAINS.TYPE_NAME).trim().toLowerCase().startsWith("timestamp");
SchemaDefinition schema = getSchema(record.get(DOMAINS.DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(DOMAINS.TYPE_NAME), record.get(DOMAINS.PRECISION), isTimestamp ? record.get(DOMAINS.SCALE) : record.get(DOMAINS.PRECISION), isTimestamp ? 0 : record.get(DOMAINS.SCALE), !record.get(DOMAINS.IS_NULLABLE, boolean.class), record.get(DOMAINS.COLUMN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(DOMAINS.DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(DOMAINS.CHECK_CONSTRAINT)))
domain.addCheckClause(record.get(DOMAINS.CHECK_CONSTRAINT));
result.add(domain);
}
return result;
}
use of org.jooq.meta.DefaultDomainDefinition in project jOOQ by jOOQ.
the class H2Database method getDomains2_0.
private List<DomainDefinition> getDomains2_0() {
List<DomainDefinition> result = new ArrayList<>();
Domains d = Tables.DOMAINS.as("d");
DomainConstraints dc = DOMAIN_CONSTRAINTS.as("dc");
for (Record record : create().select(d.DOMAIN_SCHEMA, d.DOMAIN_NAME, d.DATA_TYPE, d.CHARACTER_MAXIMUM_LENGTH, coalesce(d.DATETIME_PRECISION, d.NUMERIC_PRECISION).as(d.NUMERIC_PRECISION), d.NUMERIC_SCALE, d.DOMAIN_DEFAULT, dc.checkConstraints().CHECK_CLAUSE).from(d).leftJoin(dc).on(d.DOMAIN_CATALOG.eq(dc.DOMAIN_CATALOG)).and(d.DOMAIN_SCHEMA.eq(dc.DOMAIN_SCHEMA)).and(d.DOMAIN_NAME.eq(dc.DOMAIN_NAME)).where(d.DOMAIN_SCHEMA.in(getInputSchemata())).and(d.DATA_TYPE.ne(inline("ENUM"))).orderBy(d.DOMAIN_SCHEMA, d.DOMAIN_NAME)) {
SchemaDefinition schema = getSchema(record.get(d.DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(d.DATA_TYPE), record.get(d.CHARACTER_MAXIMUM_LENGTH), record.get(d.NUMERIC_PRECISION), record.get(d.NUMERIC_SCALE), true, record.get(d.DOMAIN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(d.DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(dc.checkConstraints().CHECK_CLAUSE)))
domain.addCheckClause(record.get(dc.checkConstraints().CHECK_CLAUSE));
result.add(domain);
}
return result;
}
use of org.jooq.meta.DefaultDomainDefinition in project jOOQ by jOOQ.
the class HSQLDBDatabase method getDomains0.
@Override
protected List<DomainDefinition> getDomains0() throws SQLException {
List<DomainDefinition> result = new ArrayList<>();
DomainConstraints dc = DOMAIN_CONSTRAINTS.as("dc");
for (Record record : create().select(dc.domains().DOMAIN_SCHEMA, dc.domains().DOMAIN_NAME, dc.domains().DATA_TYPE, dc.domains().CHARACTER_MAXIMUM_LENGTH, dc.domains().NUMERIC_PRECISION, dc.domains().NUMERIC_SCALE, dc.domains().DOMAIN_DEFAULT, dc.checkConstraints().CHECK_CLAUSE).from(dc).where(dc.domains().DOMAIN_SCHEMA.in(getInputSchemata())).orderBy(dc.domains().DOMAIN_SCHEMA, dc.domains().DOMAIN_NAME)) {
SchemaDefinition schema = getSchema(record.get(dc.domains().DOMAIN_SCHEMA));
DataTypeDefinition baseType = new DefaultDataTypeDefinition(this, schema, record.get(dc.domains().DATA_TYPE), record.get(dc.domains().CHARACTER_MAXIMUM_LENGTH), record.get(dc.domains().NUMERIC_PRECISION), record.get(dc.domains().NUMERIC_SCALE), true, record.get(dc.domains().DOMAIN_DEFAULT));
DefaultDomainDefinition domain = new DefaultDomainDefinition(schema, record.get(dc.domains().DOMAIN_NAME), baseType);
if (!StringUtils.isBlank(record.get(dc.checkConstraints().CHECK_CLAUSE)))
domain.addCheckClause(record.get(dc.checkConstraints().CHECK_CLAUSE));
result.add(domain);
}
return result;
}
Aggregations