use of org.jooq.meta.DomainDefinition in project jOOQ by jOOQ.
the class JavaGenerator method generateDomainReferences.
/**
* Generating central static domain access
*/
protected void generateDomainReferences(SchemaDefinition schema) {
log.info("Generating DOMAIN references");
JavaWriter out = newJavaWriter(getStrategy().getGlobalReferencesFile(schema, DomainDefinition.class));
out.refConflicts(getStrategy().getJavaIdentifiers(database.getDomains(schema)));
printGlobalReferencesPackage(out, schema, DomainDefinition.class);
final String schemaId = out.ref(getStrategy().getFullJavaIdentifier(schema), 2);
if (!kotlin) {
printClassJavadoc(out, "Convenience access to all Domains in " + schemaNameOrDefault(schema) + ".");
printClassAnnotations(out, schema, Mode.DOMAIN);
}
final String referencesClassName = getStrategy().getGlobalReferencesJavaClassName(schema, DomainDefinition.class);
if (scala)
out.println("%sobject %s {", visibility(), referencesClassName);
else if (kotlin) {
} else
out.println("%sclass %s {", visibility(), referencesClassName);
for (DomainDefinition domain : database.getDomains(schema)) {
final String id = getStrategy().getJavaIdentifier(domain);
final String domainTypeFull = getJavaType(domain.getType(resolver(out)), out);
final String domainType = out.ref(domainTypeFull);
final String domainTypeRef = getJavaTypeReference(domain.getDatabase(), domain.getType(resolver(out)), out);
out.javadoc("The domain <code>%s</code>.", domain.getQualifiedOutputName());
if (scala) {
out.println("%sval %s: %s[%s] = %s.createDomain(", visibility(), scalaWhitespaceSuffix(id), Domain.class, domainType, Internal.class);
out.println(" schema");
out.println(", %s.name(\"%s\")", DSL.class, escapeString(domain.getOutputName()));
out.println(", %s", domainTypeRef);
for (String check : domain.getCheckClauses()) out.println(", %s.createCheck(null, null, \"%s\")", Internal.class, escapeString(check));
out.println(")");
} else if (kotlin) {
out.println("%sval %s: %s<%s> = %s.createDomain(", visibility(), id, Domain.class, domainType, Internal.class);
out.println(" schema()");
out.println(", %s.name(\"%s\")", DSL.class, escapeString(domain.getOutputName()));
out.println(", %s", domainTypeRef);
for (String check : domain.getCheckClauses()) out.println(", %s.createCheck<%s>(null, null, \"%s\")", Internal.class, Record.class, escapeString(check));
out.println(")");
} else {
out.println("%sstatic final %s<%s> %s = %s.createDomain(", visibility(), Domain.class, domainType, id, Internal.class);
out.println(" schema()");
out.println(", %s.name(\"%s\")", DSL.class, escapeString(domain.getOutputName()));
out.println(", %s", domainTypeRef);
for (String check : domain.getCheckClauses()) out.println(", %s.createCheck(null, null, \"%s\")", Internal.class, escapeString(check));
out.println(");");
}
}
if (scala) {
out.println();
out.println("private def schema: %s = new %s(%s.name(\"%s\"), %s.comment(\"\"), () => %s)", Schema.class, LazySchema.class, DSL.class, escapeString(schema.getOutputName()), DSL.class, schemaId);
} else if (kotlin) {
out.println();
out.println("private fun schema(): %s = %s(%s.name(\"%s\"), %s.comment(\"\"), %s { %s })", Schema.class, LazySchema.class, DSL.class, escapeString(schema.getOutputName()), DSL.class, LazySupplier.class, schemaId);
} else {
out.println();
out.println("private static final %s schema() {", Schema.class);
out.println("return new %s(%s.name(\"%s\"), %s.comment(\"\"), () -> %s);", LazySchema.class, DSL.class, escapeString(schema.getOutputName()), DSL.class, schemaId);
out.println("}");
}
generateDomainReferencesClassFooter(schema, out);
if (!kotlin)
out.println("}");
closeJavaWriter(out);
watch.splitInfo("DOMAIN references generated");
}
use of org.jooq.meta.DomainDefinition 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.DomainDefinition 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.DomainDefinition 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.DomainDefinition 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;
}
Aggregations