From aaedefc9eb8303f27a68d8b06f704cfa434f7deb Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Thu, 11 Jul 2019 16:24:09 +0200 Subject: [PATCH] [jOOQ/jOOQ#7811] Array types cannot change nullability when generating DDL --- .../java/org/jooq/impl/ArrayDataType.java | 51 +++++++++++++++++++ .../java/org/jooq/impl/DefaultDataType.java | 34 +++++++++---- 2 files changed, 76 insertions(+), 9 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/ArrayDataType.java b/jOOQ/src/main/java/org/jooq/impl/ArrayDataType.java index 1bffdcbd71..5d0462fcf1 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ArrayDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/ArrayDataType.java @@ -37,8 +37,12 @@ */ package org.jooq.impl; +import org.jooq.CharacterSet; +import org.jooq.Collation; import org.jooq.Configuration; import org.jooq.DataType; +import org.jooq.Field; +import org.jooq.Nullability; /** * A wrapper for anonymous array data types @@ -60,6 +64,53 @@ final class ArrayDataType extends DefaultDataType { this.elementType = elementType; } + /** + * [#3225] Performant constructor for creating derived types. + */ + ArrayDataType( + DefaultDataType t, + DataType elementType, + int precision, + int scale, + int length, + Nullability nullability, + Collation collation, + CharacterSet characterSet, + boolean identity, + Field defaultValue + ) { + super(t, precision, scale, length, nullability, collation, characterSet, identity, defaultValue); + + this.elementType= elementType; + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + @Override + DefaultDataType construct( + int newPrecision, + int newScale, + int newLength, + Nullability + newNullability, + Collation newCollation, + CharacterSet newCharacterSet, + boolean newIdentity, + Field newDefaultValue + ) { + return new ArrayDataType<>( + this, + (DefaultDataType) elementType, + newPrecision, + newScale, + newLength, + newNullability, + newCollation, + newCharacterSet, + newIdentity, + (Field) newDefaultValue + ); + } + @Override public final String getTypeName(Configuration configuration) { String typeName = elementType.getTypeName(configuration); diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java index 7b9955a7e2..1e06cd52d3 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java @@ -334,10 +334,26 @@ public class DefaultDataType implements DataType { this.tType = this.binding.converter().fromType(); } + /** + * [#7811] Allow for subtypes to override the constructor + */ + DefaultDataType construct( + int newPrecision, + int newScale, + int newLength, + Nullability newNullability, + Collation newCollation, + CharacterSet newCharacterSet, + boolean newIdentity, + Field newDefaultValue + ) { + return new DefaultDataType<>(this, newPrecision, newScale, newLength, newNullability, newCollation, newCharacterSet, newIdentity, newDefaultValue); + } + /** * [#3225] Performant constructor for creating derived types. */ - private DefaultDataType( + DefaultDataType( DefaultDataType t, int precision, int scale, @@ -385,7 +401,7 @@ public class DefaultDataType implements DataType { @Override public final DataType nullability(Nullability n) { - return new DefaultDataType<>(this, precision, scale, length, n, collation, characterSet, n.nullable() ? false : identity, defaultValue); + return construct(precision, scale, length, n, collation, characterSet, n.nullable() ? false : identity, defaultValue); } @Override @@ -405,7 +421,7 @@ public class DefaultDataType implements DataType { @Override public final DataType collation(Collation c) { - return new DefaultDataType<>(this, precision, scale, length, nullability, c, characterSet, identity, defaultValue); + return construct(precision, scale, length, nullability, c, characterSet, identity, defaultValue); } @Override @@ -415,7 +431,7 @@ public class DefaultDataType implements DataType { @Override public final DataType characterSet(CharacterSet c) { - return new DefaultDataType<>(this, precision, scale, length, nullability, collation, c, identity, defaultValue); + return construct(precision, scale, length, nullability, collation, c, identity, defaultValue); } @Override @@ -425,7 +441,7 @@ public class DefaultDataType implements DataType { @Override public final DataType identity(boolean i) { - return new DefaultDataType<>(this, precision, scale, length, i ? NOT_NULL : nullability, collation, characterSet, i, i ? null : defaultValue); + return construct(precision, scale, length, i ? NOT_NULL : nullability, collation, characterSet, i, i ? null : defaultValue); } @Override @@ -455,7 +471,7 @@ public class DefaultDataType implements DataType { @Override public final DataType default_(Field d) { - return new DefaultDataType<>(this, precision, scale, length, nullability, collation, characterSet, d != null ? false : identity, d); + return construct(precision, scale, length, nullability, collation, characterSet, d != null ? false : identity, d); } @Override @@ -488,7 +504,7 @@ public class DefaultDataType implements DataType { else if (isLob()) return this; else - return new DefaultDataType<>(this, p, s, length, nullability, collation, characterSet, identity, defaultValue); + return construct(p, s, length, nullability, collation, characterSet, identity, defaultValue); } @Override @@ -519,7 +535,7 @@ public class DefaultDataType implements DataType { if (isLob()) return this; else - return new DefaultDataType<>(this, precision, s, length, nullability, collation, characterSet, identity, defaultValue); + return construct(precision, s, length, nullability, collation, characterSet, identity, defaultValue); } @Override @@ -541,7 +557,7 @@ public class DefaultDataType implements DataType { if (isLob()) return this; else - return new DefaultDataType<>(this, precision, scale, l, nullability, collation, characterSet, identity, defaultValue); + return construct(precision, scale, l, nullability, collation, characterSet, identity, defaultValue); } @Override