[jOOQ/jOOQ#16043] DATE column in Oracle is null when fetched through

multiset

This includes:

- [jOOQ/jOOQ#16044] org.jooq.tools.Convert should delegate to
org.jooq.impl.Convert, instead of duplicating implementations
This commit is contained in:
Lukas Eder 2024-01-10 11:14:31 +01:00
parent 27390cfd7b
commit f7923c5f5e
3 changed files with 138 additions and 1241 deletions

View File

@ -114,7 +114,6 @@ import org.jooq.exception.DataTypeException;
import org.jooq.tools.Ints;
import org.jooq.tools.JooqLogger;
import org.jooq.tools.Longs;
import org.jooq.tools.StringUtils;
import org.jooq.tools.jdbc.MockArray;
import org.jooq.tools.jdbc.MockResultSet;
import org.jooq.tools.json.ContainerFactory;
@ -1014,7 +1013,7 @@ final class Convert {
// [#1501] Strings can be converted to java.sql.Date
else if (fromClass == String.class && toClass == java.sql.Date.class) {
try {
return (U) java.sql.Date.valueOf((String) from);
return (U) java.sql.Date.valueOf(patchIso8601Date((String) from));
}
catch (IllegalArgumentException e) {
return null;
@ -1041,14 +1040,15 @@ final class Convert {
}
}
else if (fromClass == String.class && toClass == LocalDate.class) {
String s = patchIso8601Date((String) from);
// Try "lenient" ISO date formats first
try {
return (U) java.sql.Date.valueOf((String) from).toLocalDate();
return (U) java.sql.Date.valueOf(s).toLocalDate();
}
catch (IllegalArgumentException e1) {
try {
return (U) LocalDate.parse((String) from);
return (U) LocalDate.parse(s);
}
catch (DateTimeParseException e2) {
return null;
@ -1682,6 +1682,38 @@ final class Convert {
return s;
}
static final String patchIso8601Date(String s) {
// [#11485] Trino produces a non-ISO 8601 "UTC" suffix, instead of "Z"
if (s.endsWith(" UTC"))
s = s.replace(" UTC", "Z");
int l = s.length();
int d1 = s.indexOf('-');
int d2 = s.indexOf('-', d1 + 1);
int ss = s.indexOf(' ', d2 + 1);
int st = s.indexOf('T', d2 + 1);
int sx = Math.max(ss, st);
if (d1 == -1 || d2 == -1)
return s;
// [#12547] Support year numbers with more or less than 4 digits
// [#13786] Be lenient with PostgreSQL style abbreviated time stamp literals
else if (sx == -1)
if (l - d2 < 3 || d2 - d1 < 3)
return padLead4(s, d1) + '-'
+ padMid2(s, d1, d2) + '-'
+ padMid2(s, d2);
else
return s;
else
return padLead4(s, d1) + '-'
+ padMid2(s, d1, d2) + '-'
+ padMid2(s, d2, sx);
}
private static final String padLead2(String s, int i1) {
return leftPad(s.substring(0, i1), 2, '0');
}

View File

@ -48,6 +48,7 @@ import static org.jooq.tools.StringUtils.isBlank;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
@ -1031,4 +1032,94 @@ public final class Internal {
public static final int javaVersion() {
return JAVA_VERSION.get();
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final Object[] convert(Object[] values, Field<?>[] fields) {
return Convert.convert(values, fields);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final Object[] convert(Object[] values, Class<?>[] types) {
return Convert.convert(values, types);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final <U> U[] convertArray(Object[] from, Converter<?, ? extends U> converter) throws DataTypeException {
return Convert.convertArray(from, converter);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final Object[] convertArray(Object[] from, Class<?> toClass) throws DataTypeException {
return Convert.convertArray(from, toClass);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final <U> U[] convertCollection(Collection from, Class<? extends U[]> to) {
return Convert.convertCollection(from, to);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final <U> U convert(Object from, Converter<?, ? extends U> converter) throws DataTypeException {
return Convert.convert(from, converter);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final <T> T convert(Object from, Class<? extends T> toClass) throws DataTypeException {
return Convert.convert(from, toClass);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final <T> List<T> convert(Collection<?> collection, Class<? extends T> type) throws DataTypeException {
return Convert.convert(collection, type);
}
/**
* [#11898] [#16044] This method just acts as a bridge to internal API from
* the deprecated-for-removal {@link org.jooq.tools.Convert} utility. Do not
* reuse these methods.
*/
@Deprecated(forRemoval = true)
public static final <U> List<U> convert(Collection<?> collection, Converter<?, ? extends U> converter) throws DataTypeException {
return Convert.convert(collection, converter);
}
}

File diff suppressed because it is too large Load Diff