diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java index 5bdf987874..b511f5b093 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultBinding.java @@ -268,6 +268,9 @@ public class DefaultBinding implements Binding { return new DefaultTimeBinding(converter, isLob); else if (type == Timestamp.class) return new DefaultTimestampBinding(converter, isLob); + // [#8022] Support for the "synthetic" timestamp type + else if (type == java.util.Date.class) + return new DefaultTimestampBinding(Converters.of(TimestampToJavaUtilDateConverter.INSTANCE, (Converter) converter), isLob); else if (type == UByte.class) return new DefaultUByteBinding(converter, isLob); else if (type == UInteger.class) @@ -2872,7 +2875,7 @@ public class DefaultBinding implements Binding { if (b instanceof DefaultOtherBinding) ctx.statement().setObject(ctx.index(), value); else - b.set0(ctx, value); + b.set0(ctx, b.converter().to(value)); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java index b640e7dabb..93d215d26b 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDataType.java @@ -832,9 +832,8 @@ public class DefaultDataType implements DataType { else { DataType result = null; - if (dialect != null) { + if (dialect != null) result = TYPES_BY_TYPE[dialect.family().ordinal()].get(type); - } if (result == null) { @@ -873,6 +872,10 @@ public class DefaultDataType implements DataType { else if (fallbackDataType != null) { return fallbackDataType; } + // [#8022] Special handling + else if (java.util.Date.class == type) { + return (DataType) SQLDataType.TIMESTAMP; + } // All other data types are illegal else { diff --git a/jOOQ/src/main/java/org/jooq/impl/TimestampToJavaUtilDateConverter.java b/jOOQ/src/main/java/org/jooq/impl/TimestampToJavaUtilDateConverter.java new file mode 100644 index 0000000000..ffadf1c68e --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/TimestampToJavaUtilDateConverter.java @@ -0,0 +1,66 @@ +/* + * 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. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import java.sql.Timestamp; + +/** + * @author Lukas Eder + */ +final class TimestampToJavaUtilDateConverter extends AbstractConverter { + + /** + * Generated UID + */ + private static final long serialVersionUID = 1L; + static final TimestampToJavaUtilDateConverter INSTANCE = new TimestampToJavaUtilDateConverter(); + + private TimestampToJavaUtilDateConverter () { + super(Timestamp.class, java.util.Date.class); + } + + @Override + public final java.util.Date from(Timestamp t) { + return t == null ? null : new java.util.Date(t.getTime()); + } + + @Override + public final Timestamp to(java.util.Date u) { + return u == null ? null : new Timestamp(u.getTime()); + } +} \ No newline at end of file