diff --git a/jOOQ/src/main/java/org/jooq/impl/Convert.java b/jOOQ/src/main/java/org/jooq/impl/Convert.java index 811861fc6e..d65117ff23 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Convert.java +++ b/jOOQ/src/main/java/org/jooq/impl/Convert.java @@ -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 { diff --git a/jOOQ/src/main/java/org/jooq/tools/Convert.java b/jOOQ/src/main/java/org/jooq/tools/Convert.java index 7939c93eff..9c80b1db0e 100644 --- a/jOOQ/src/main/java/org/jooq/tools/Convert.java +++ b/jOOQ/src/main/java/org/jooq/tools/Convert.java @@ -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 {