[jOOQ/jOOQ#14713] Add support for interval types in DefaultConverterProvider

This commit is contained in:
Lukas Eder 2023-02-27 16:17:19 +01:00
parent ebb5528609
commit 193b9caf2b
2 changed files with 102 additions and 0 deletions

View File

@ -120,10 +120,14 @@ import org.jooq.tools.json.JSONObject;
import org.jooq.tools.json.JSONParser;
import org.jooq.tools.json.ParseException;
import org.jooq.tools.reflect.Reflect;
import org.jooq.types.DayToSecond;
import org.jooq.types.UByte;
import org.jooq.types.UInteger;
import org.jooq.types.ULong;
import org.jooq.types.UShort;
import org.jooq.types.YearToMonth;
import org.jooq.types.YearToSecond;
import org.jooq.util.postgres.PostgresUtils;
import org.jooq.util.xml.jaxb.InformationSchema;
import jakarta.xml.bind.JAXB;
@ -1113,6 +1117,53 @@ final class Convert {
}
}
// [#14437] [#14713] Interval conversions
else if (fromClass == String.class && toClass == YearToMonth.class) {
// Try our own standard SQL implementation first
YearToMonth r = YearToMonth.valueOf((String) from);
if (r != null)
return (U) r;
// If that failed, try the PostgreSQL specific formats
try {
return (U) PostgresUtils.toYearToMonth(from);
}
catch (Exception e) {
return null;
}
}
else if (fromClass == String.class && toClass == DayToSecond.class) {
// Try our own standard SQL implementation first
DayToSecond r = DayToSecond.valueOf((String) from);
if (r != null)
return (U) r;
// If that failed, try the PostgreSQL specific formats
try {
return (U) PostgresUtils.toDayToSecond(from);
}
catch (Exception e) {
return null;
}
}
else if (fromClass == String.class && toClass == YearToSecond.class) {
// Try our own standard SQL implementation first
YearToSecond r = YearToSecond.valueOf((String) from);
if (r != null)
return (U) r;
// If that failed, try the PostgreSQL specific formats
try {
return (U) PostgresUtils.toYearToSecond(from);
}
catch (Exception e) {
return null;
}
}
// [#1448] [#6255] [#5720] To Enum conversion
else if (java.lang.Enum.class.isAssignableFrom(toClass) && (fromClass == String.class || from instanceof Enum || from instanceof EnumType)) {
try {

View File

@ -114,10 +114,14 @@ import org.jooq.impl.Internal;
import org.jooq.tools.jdbc.MockArray;
import org.jooq.tools.jdbc.MockResultSet;
import org.jooq.tools.reflect.Reflect;
import org.jooq.types.DayToSecond;
import org.jooq.types.UByte;
import org.jooq.types.UInteger;
import org.jooq.types.ULong;
import org.jooq.types.UShort;
import org.jooq.types.YearToMonth;
import org.jooq.types.YearToSecond;
import org.jooq.util.postgres.PostgresUtils;
import org.jooq.util.xml.jaxb.InformationSchema;
/**
@ -1057,6 +1061,53 @@ public final class Convert {
}
}
// [#14437] [#14713] Interval conversions
else if (fromClass == String.class && toClass == YearToMonth.class) {
// Try our own standard SQL implementation first
YearToMonth r = YearToMonth.valueOf((String) from);
if (r != null)
return (U) r;
// If that failed, try the PostgreSQL specific formats
try {
return (U) PostgresUtils.toYearToMonth(from);
}
catch (Exception e) {
return null;
}
}
else if (fromClass == String.class && toClass == DayToSecond.class) {
// Try our own standard SQL implementation first
DayToSecond r = DayToSecond.valueOf((String) from);
if (r != null)
return (U) r;
// If that failed, try the PostgreSQL specific formats
try {
return (U) PostgresUtils.toDayToSecond(from);
}
catch (Exception e) {
return null;
}
}
else if (fromClass == String.class && toClass == YearToSecond.class) {
// Try our own standard SQL implementation first
YearToSecond r = YearToSecond.valueOf((String) from);
if (r != null)
return (U) r;
// If that failed, try the PostgreSQL specific formats
try {
return (U) PostgresUtils.toYearToSecond(from);
}
catch (Exception e) {
return null;
}
}
// [#1448] [#6255] [#5720] To Enum conversion
else if (java.lang.Enum.class.isAssignableFrom(toClass) && (fromClass == String.class || from instanceof Enum || from instanceof EnumType)) {
try {