From f4cee633c0c3583f94fd1b11552b2d85319af99f Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Tue, 19 Aug 2014 18:50:12 +0200 Subject: [PATCH] [#3571] Converted Data Type does not propagate nullable and defaulted properties --- jOOQ-test/pom.xml | 15 ++++- .../resources/org/jooq/test/h2/create.sql | 9 +++ .../src/test/java/org/jooq/test/H2Test.java | 15 +++++ .../org/jooq/test/all/converters/T_3571.java | 49 ++++++++++++++++ .../test/all/converters/T_3571_Converter.java | 58 +++++++++++++++++++ .../java/org/jooq/impl/ConvertedDataType.java | 12 +++- .../java/org/jooq/impl/DefaultDataType.java | 10 +++- 7 files changed, 163 insertions(+), 5 deletions(-) create mode 100644 jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571.java create mode 100644 jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571_Converter.java diff --git a/jOOQ-test/pom.xml b/jOOQ-test/pom.xml index ba3c0a5a50..d56080e81a 100644 --- a/jOOQ-test/pom.xml +++ b/jOOQ-test/pom.xml @@ -1193,7 +1193,14 @@ - + + + + 3571 + org.jooq.test.all.converters.T_3571 + org.jooq.test.all.converters.T_3571_Converter + + org.jooq.test.all.converters.Boolean_10 org.jooq.test.all.converters.Boolean_10_Converter @@ -1226,6 +1233,12 @@ + + + 3571 + (?i:.*?\.t_3571\..*) + + DECIMAL diff --git a/jOOQ-test/src/main/resources/org/jooq/test/h2/create.sql b/jOOQ-test/src/main/resources/org/jooq/test/h2/create.sql index 2d429bc27d..f1b4642d85 100644 --- a/jOOQ-test/src/main/resources/org/jooq/test/h2/create.sql +++ b/jOOQ-test/src/main/resources/org/jooq/test/h2/create.sql @@ -53,12 +53,21 @@ DROP TABLE IF EXISTS t_3488_abc_xyz_eee/ DROP TABLE IF EXISTS t_3488_abcxyz_eee/ DROP TABLE IF EXISTS t_3488_abc_xyzeee/ DROP TABLE IF EXISTS t_3488_abcxyzeee/ +DROP TABLE IF EXISTS t_3571/ DROP TABLE IF EXISTS t_unsigned/ DROP TABLE IF EXISTS t_booleans/ DROP TABLE IF EXISTS t_identity/ DROP TABLE IF EXISTS t_identity_pk/ DROP TABLE IF EXISTS t_2327_uk_only/ +CREATE TABLE t_3571 ( + e1 INTEGER, + e2 INTEGER NOT NULL, + e3 INTEGER DEFAULT 1, + e4 INTEGER NOT NULL DEFAULT 1 +) +/ + CREATE TABLE t_2327_uk_only ( id INTEGER, diff --git a/jOOQ-test/src/test/java/org/jooq/test/H2Test.java b/jOOQ-test/src/test/java/org/jooq/test/H2Test.java index 68f70c09c2..f2cf6d02aa 100644 --- a/jOOQ-test/src/test/java/org/jooq/test/H2Test.java +++ b/jOOQ-test/src/test/java/org/jooq/test/H2Test.java @@ -48,6 +48,7 @@ import static org.jooq.impl.DSL.select; import static org.jooq.impl.DSL.table; import static org.jooq.test.h2.generatedclasses.Tables.T_2486; import static org.jooq.test.h2.generatedclasses.Tables.T_2698; +import static org.jooq.test.h2.generatedclasses.Tables.T_3571; import static org.jooq.test.h2.generatedclasses.Tables.T_639_NUMBERS_TABLE; import static org.jooq.test.h2.generatedclasses.Tables.T_725_LOB_TEST; import static org.jooq.test.h2.generatedclasses.Tables.T_785; @@ -69,7 +70,9 @@ import static org.jooq.test.h2.generatedclasses.Tables.V_BOOK; import static org.jooq.test.h2.generatedclasses.Tables.V_LIBRARY; import static org.jooq.test.h2.generatedclasses.Tables.X_UNUSED; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.math.BigDecimal; import java.math.BigInteger; @@ -1060,4 +1063,16 @@ public class H2Test extends jOOQAbstractTest< assertEquals(0, T_2486.VAL8.getDataType().scale()); } + @Test + public void testH2MetaData3571() { + assertTrue(T_3571.E1.getDataType().nullable()); + assertFalse(T_3571.E1.getDataType().defaulted()); + assertFalse(T_3571.E2.getDataType().nullable()); + assertFalse(T_3571.E2.getDataType().defaulted()); + assertTrue(T_3571.E3.getDataType().nullable()); + assertTrue(T_3571.E3.getDataType().defaulted()); + assertFalse(T_3571.E4.getDataType().nullable()); + assertTrue(T_3571.E4.getDataType().defaulted()); + } + } diff --git a/jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571.java b/jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571.java new file mode 100644 index 0000000000..a0b72973f9 --- /dev/null +++ b/jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.0: + * ----------------------------------------------------------------------------- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq.test.all.converters; + +/** + * @author Lukas Eder + */ +public enum T_3571 { + + A, B, C +} diff --git a/jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571_Converter.java b/jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571_Converter.java new file mode 100644 index 0000000000..b34387db6f --- /dev/null +++ b/jOOQ-test/src/test/java/org/jooq/test/all/converters/T_3571_Converter.java @@ -0,0 +1,58 @@ +/** + * Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com) + * All rights reserved. + * + * This work is dual-licensed + * - under the Apache Software License 2.0 (the "ASL") + * - under the jOOQ License and Maintenance Agreement (the "jOOQ License") + * ============================================================================= + * You may choose which license applies to you: + * + * - If you're using this work with Open Source databases, you may choose + * either ASL or jOOQ License. + * - If you're using this work with at least one commercial database, you must + * choose jOOQ License + * + * For more information, please visit http://www.jooq.org/licenses + * + * Apache Software License 2.0: + * ----------------------------------------------------------------------------- + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * jOOQ License and Maintenance Agreement: + * ----------------------------------------------------------------------------- + * Data Geekery grants the Customer the non-exclusive, timely limited and + * non-transferable license to install and use the Software under the terms of + * the jOOQ License and Maintenance Agreement. + * + * This library is distributed with a LIMITED WARRANTY. See the jOOQ License + * and Maintenance Agreement for more details: http://www.jooq.org/licensing + */ +package org.jooq.test.all.converters; + +import org.jooq.impl.EnumConverter; + +/** + * @author Lukas Eder + */ +public class T_3571_Converter extends EnumConverter { + + /** + * Generated UID + */ + private static final long serialVersionUID = 4877220039498982300L; + + public T_3571_Converter() { + super(Integer.class, T_3571.class); + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java b/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java index 0af1912400..5f30e0846e 100644 --- a/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/ConvertedDataType.java @@ -60,7 +60,17 @@ class ConvertedDataType extends DefaultDataType { private final Converter converter; ConvertedDataType(DataType delegate, Converter converter) { - super(null, converter.toType(), delegate.getTypeName(), delegate.getCastTypeName()); + super( + null, + converter.toType(), + delegate.getTypeName(), + delegate.getCastTypeName(), + delegate.precision(), + delegate.scale(), + delegate.length(), + delegate.nullable(), + delegate.defaulted() + ); this.delegate = delegate; this.converter = converter; diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java index b16126f1d4..53484dd754 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java @@ -222,11 +222,11 @@ public class DefaultDataType implements DataType { } public DefaultDataType(SQLDialect dialect, DataType sqlDataType, String typeName) { - this(dialect, sqlDataType, sqlDataType.getType(), typeName, typeName, 0, 0, 0, sqlDataType.nullable(), sqlDataType.defaulted()); + this(dialect, sqlDataType, sqlDataType.getType(), typeName, typeName, sqlDataType.precision(), sqlDataType.scale(), sqlDataType.length(), sqlDataType.nullable(), sqlDataType.defaulted()); } public DefaultDataType(SQLDialect dialect, DataType sqlDataType, String typeName, String castTypeName) { - this(dialect, sqlDataType, sqlDataType.getType(), typeName, castTypeName, 0, 0, 0, sqlDataType.nullable(), sqlDataType.defaulted()); + this(dialect, sqlDataType, sqlDataType.getType(), typeName, castTypeName, sqlDataType.precision(), sqlDataType.scale(), sqlDataType.length(), sqlDataType.nullable(), sqlDataType.defaulted()); } public DefaultDataType(SQLDialect dialect, Class type, String typeName) { @@ -237,7 +237,11 @@ public class DefaultDataType implements DataType { this(dialect, null, type, typeName, castTypeName, 0, 0, 0, true, false); } - private DefaultDataType(SQLDialect dialect, DataType sqlDataType, Class type, String typeName, String castTypeName, int precision, int scale, int length, boolean nullable, boolean defaulted) { + DefaultDataType(SQLDialect dialect, Class type, String typeName, String castTypeName, int precision, int scale, int length, boolean nullable, boolean defaulted) { + this(dialect, null, type, typeName, castTypeName, precision, scale, length, nullable, defaulted); + } + + DefaultDataType(SQLDialect dialect, DataType sqlDataType, Class type, String typeName, String castTypeName, int precision, int scale, int length, boolean nullable, boolean defaulted) { // Initialise final instance members // ---------------------------------