[#8022] Support passing java.util.Date as a Field<Object> bind value
This commit is contained in:
parent
ee2b015350
commit
087e1ca01b
@ -268,6 +268,9 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
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<java.util.Date, java.util.Date>) converter), isLob);
|
||||
else if (type == UByte.class)
|
||||
return new DefaultUByteBinding(converter, isLob);
|
||||
else if (type == UInteger.class)
|
||||
@ -2872,7 +2875,7 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
|
||||
if (b instanceof DefaultOtherBinding)
|
||||
ctx.statement().setObject(ctx.index(), value);
|
||||
else
|
||||
b.set0(ctx, value);
|
||||
b.set0(ctx, b.converter().to(value));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -832,9 +832,8 @@ public class DefaultDataType<T> implements DataType<T> {
|
||||
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<T> implements DataType<T> {
|
||||
else if (fallbackDataType != null) {
|
||||
return fallbackDataType;
|
||||
}
|
||||
// [#8022] Special handling
|
||||
else if (java.util.Date.class == type) {
|
||||
return (DataType<T>) SQLDataType.TIMESTAMP;
|
||||
}
|
||||
|
||||
// All other data types are illegal
|
||||
else {
|
||||
|
||||
@ -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<Timestamp, java.util.Date> {
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user