[jOOQ/jOOQ#10690] Use some newer JDK API when creating a distribution for JDK 17

This commit is contained in:
Lukas Eder 2021-04-23 09:57:22 +02:00
parent f268bc2bcd
commit 70dadcb9f2
5 changed files with 23 additions and 16 deletions

View File

@ -37,13 +37,13 @@
*/
package org.jooq;
import static org.jooq.impl.Internal.arrayType;
import static org.jooq.tools.Convert.convertArray;
import java.lang.reflect.Array;
import org.jooq.impl.AbstractConverter;
import org.jooq.impl.IdentityConverter;
import org.jooq.impl.SQLDataType;
import org.jetbrains.annotations.NotNull;
/**
@ -124,7 +124,7 @@ public class Converters<T, U> extends AbstractConverter<T, U> {
* Inverse a converter.
*/
public static <T, U> Converter<U, T> inverse(final Converter<T, U> converter) {
// [#11099] Allow instanceof checks on IdentityConverter for performance reasons
if (converter instanceof IdentityConverter)
return (Converter<U, T>) converter;
@ -154,10 +154,7 @@ public class Converters<T, U> extends AbstractConverter<T, U> {
}
public static <T, U> Converter<T[], U[]> forArrays(final Converter<T, U> converter) {
return new AbstractConverter<T[], U[]>(
(Class<T[]>) Array.newInstance(converter.fromType(), 0).getClass(),
(Class<U[]>) Array.newInstance(converter.toType(), 0).getClass()
) {
return new AbstractConverter<T[], U[]>(arrayType(converter.fromType()), arrayType(converter.toType())) {
/**
* Generated UID

View File

@ -42,6 +42,7 @@ import static org.jooq.SQLDialect.FIREBIRD;
// ...
// ...
import static org.jooq.impl.DSL.unquotedName;
import static org.jooq.impl.Internal.arrayType;
import static org.jooq.impl.SQLDataType.BLOB;
import static org.jooq.impl.SQLDataType.CLOB;
import static org.jooq.impl.SQLDataType.NCHAR;
@ -49,7 +50,6 @@ import static org.jooq.impl.SQLDataType.NCLOB;
import static org.jooq.impl.SQLDataType.NVARCHAR;
import static org.jooq.impl.Tools.NO_SUPPORT_BINARY_TYPE_LENGTH;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Blob;
@ -465,7 +465,7 @@ abstract class AbstractDataType<T> extends AbstractNamed implements DataType<T>
@Override
public final Class<T[]> getArrayType() {
return (Class<T[]>) Array.newInstance(getType(), 0).getClass();
return arrayType(getType());
}
@Override

View File

@ -85,6 +85,7 @@ import static org.jooq.impl.DefaultBinding.DefaultDoubleBinding.REQUIRES_LITERAL
import static org.jooq.impl.DefaultBinding.DefaultDoubleBinding.infinity;
import static org.jooq.impl.DefaultBinding.DefaultDoubleBinding.nan;
import static org.jooq.impl.DefaultExecuteContext.localTargetConnection;
import static org.jooq.impl.Internal.arrayType;
import static org.jooq.impl.Keywords.K_ARRAY;
import static org.jooq.impl.Keywords.K_AS;
import static org.jooq.impl.Keywords.K_BLOB;
@ -156,20 +157,17 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.format.SignStyle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import java.util.function.Function;
import java.util.function.Supplier;
@ -1136,10 +1134,10 @@ public class DefaultBinding<T, U> implements Binding<T, U> {
}
}
private final Class<?> deriveArrayTypeFromComponentType(Object[] value) {
private final Class<? extends Object[]> deriveArrayTypeFromComponentType(Object[] value) {
for (Object o : value)
if (o != null)
return java.lang.reflect.Array.newInstance(o.getClass(), 0).getClass();
return arrayType(o.getClass());
// PostgreSQL often defaults to using varchar as well, so we can
// mimick this behaviour (without documenting it).

View File

@ -414,7 +414,7 @@ public final class Internal {
* <p>
* This is used for internal purposes and thus subject for change.
*/
public static <T> Subscriber<T> subscriber(
public static final <T> Subscriber<T> subscriber(
Consumer<? super Subscription> subscription,
Consumer<? super T> onNext,
Consumer<? super Throwable> onError,
@ -442,4 +442,14 @@ public final class Internal {
}
};
}
@SuppressWarnings({ "unchecked", "unused" })
public static final <T> Class<T[]> arrayType(Class<T> type) {
return (Class<T[]>) java.lang.reflect.Array.newInstance(type, 0).getClass();
}
}

View File

@ -40,6 +40,7 @@ package org.jooq.tools;
import static java.time.temporal.ChronoField.INSTANT_SECONDS;
import static java.time.temporal.ChronoField.MILLI_OF_DAY;
import static java.time.temporal.ChronoField.MILLI_OF_SECOND;
import static org.jooq.impl.Internal.arrayType;
import static org.jooq.tools.reflect.Reflect.accessible;
import static org.jooq.tools.reflect.Reflect.wrapper;
import static org.jooq.types.Unsigned.ubyte;
@ -99,6 +100,7 @@ import org.jooq.SQLDialect;
import org.jooq.XML;
import org.jooq.exception.DataTypeException;
import org.jooq.impl.IdentityConverter;
import org.jooq.impl.Internal;
import org.jooq.tools.jdbc.MockArray;
import org.jooq.tools.jdbc.MockResultSet;
import org.jooq.tools.reflect.Reflect;
@ -328,7 +330,7 @@ public final class Convert {
if (from == null)
return null;
else if (!toClass.isArray())
return convertArray(from, Array.newInstance(toClass, 0).getClass());
return convertArray(from, arrayType(toClass));
else if (toClass == from.getClass())
return from;
else {