[jOOQ/jOOQ#14618] Missing nullability information on nullable DOMAIN types that are made non-null by CREATE TABLE

This commit is contained in:
Lukas Eder 2023-02-13 11:49:44 +01:00
parent a37ddfff2b
commit a716afb4ad
3 changed files with 49 additions and 3 deletions

View File

@ -9679,6 +9679,8 @@ public class JavaGenerator extends AbstractGenerator {
else if (db.getDomain(schema, u) != null) {
sb.append(getStrategy().getFullJavaIdentifier(db.getDomain(schema, u)));
sb.append(".getDataType()");
appendTypeReferenceNullability(sb, n);
}
else if (db.getUDT(schema, u) != null) {
sb.append(getStrategy().getFullJavaIdentifier(db.getUDT(schema, u)));
@ -9773,8 +9775,7 @@ public class JavaGenerator extends AbstractGenerator {
sb.append(sqlDataTypeRef);
}
if (!dataType.nullable())
sb.append(".nullable(false)");
appendTypeReferenceNullability(sb, n);
if (dataType.identity())
sb.append(".identity(true)");
@ -9841,6 +9842,11 @@ public class JavaGenerator extends AbstractGenerator {
return sb.toString();
}
private final void appendTypeReferenceNullability(StringBuilder sb, boolean n) {
if (!n)
sb.append(".nullable(false)");
}
private DataType<?> mapTypes(DataType<?> dataType) {
DataType<?> result = dataType;

View File

@ -80,7 +80,6 @@ final class DataTypeProxy<T> extends AbstractDataType<T> {
this(type, null, null, null, null, null, null, null, null, null, null, null, null);
}
@SuppressWarnings("unchecked")
private DataTypeProxy(
AbstractDataType<T> type,
Integer overridePrecision,

View File

@ -37,9 +37,16 @@
*/
package org.jooq.impl;
import org.jooq.CharacterSet;
import org.jooq.Collation;
import org.jooq.Configuration;
import org.jooq.DataType;
import org.jooq.Domain;
import org.jooq.Field;
import org.jooq.Generator;
import org.jooq.Nullability;
import org.jooq.impl.QOM.GenerationLocation;
import org.jooq.impl.QOM.GenerationOption;
/**
* A <code>DataType</code> used for {@link Domain} types.
@ -78,6 +85,40 @@ final class DomainDataType<T> extends DefaultDataType<T> {
this.baseType = baseType;
}
@Override
DefaultDataType<T> construct(
Integer newPrecision,
Integer newScale,
Integer newLength,
Nullability newNullability,
boolean newReadonly,
Generator<?, ?, T> newGeneratedAlwaysAs,
GenerationOption newGenerationOption,
GenerationLocation newGenerationLocation,
Collation newCollation,
CharacterSet newCharacterSet,
boolean newIdentity,
Field<T> newDefaultValue
) {
return new DomainDataType<>(
domain,
((AbstractDataTypeX<T>) baseType).construct(
newPrecision,
newScale,
newLength,
newNullability,
newReadonly,
newGeneratedAlwaysAs,
newGenerationOption,
newGenerationLocation,
newCollation,
newCharacterSet,
newIdentity,
newDefaultValue
)
);
}
@Override
public final Domain<T> getDomain() {
return domain;