This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 3a3af13962a Added LocalDate support to the convertDateValue method
(#37053)
3a3af13962a is described below
commit 3a3af13962a7575b3a03296e067d9a30213fe0fe
Author: Harsh Mehta <[email protected]>
AuthorDate: Sun Nov 9 16:34:47 2025 +0530
Added LocalDate support to the convertDateValue method (#37053)
* added LocalDate support to the convertDateValue method in the
ResultSetUtils.java file
* Fix Spotless formatting issues in ResultSetUtilsTest.java
---
.../impl/driver/jdbc/type/util/ResultSetUtils.java | 2 ++
.../driver/jdbc/type/util/ResultSetUtilsTest.java | 27 ++++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
index a7bdd9fe558..971ca6bc4c0 100644
---
a/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
+++
b/infra/executor/src/main/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtils.java
@@ -196,6 +196,8 @@ public final class ResultSetUtils {
return new Time(value.getTime());
case "java.sql.Timestamp":
return new Timestamp(value.getTime());
+ case "java.time.LocalDate":
+ return new java.sql.Date(value.getTime()).toLocalDate();
case "java.lang.String":
return value.toString();
default:
diff --git
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilsTest.java
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilsTest.java
index f329d8760f1..2a77a5962ed 100644
---
a/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilsTest.java
+++
b/infra/executor/src/test/java/org/apache/shardingsphere/infra/executor/sql/execute/result/query/impl/driver/jdbc/type/util/ResultSetUtilsTest.java
@@ -172,4 +172,31 @@ class ResultSetUtilsTest {
assertThat(ResultSetUtils.convertBigDecimalValue("12.243", true, 2),
is(BigDecimal.valueOf(12.24)));
assertThrows(UnsupportedDataTypeConversionException.class, () ->
ResultSetUtils.convertBigDecimalValue(new Date(), true, 2));
}
+
+ @Test
+ void assertConvertDateValueToLocalDate() throws SQLException {
+ Date date = new Date(1609459200000L);
+ LocalDate result = (LocalDate) ResultSetUtils.convertValue(date,
LocalDate.class);
+ assertThat(result, isA(LocalDate.class));
+ java.sql.Date sqlDate = new java.sql.Date(date.getTime());
+ assertThat(result, is(sqlDate.toLocalDate()));
+ }
+
+ @Test
+ void assertConvertDateValueToLocalDateWithDifferentTimestamps() throws
SQLException {
+ Date epochDate = new Date(0L);
+ LocalDate epochResult = (LocalDate)
ResultSetUtils.convertValue(epochDate, LocalDate.class);
+ assertThat(epochResult, is(LocalDate.of(1970, 1, 1)));
+ Date christmasDate = new Date(1703462400000L);
+ LocalDate christmasResult = (LocalDate)
ResultSetUtils.convertValue(christmasDate, LocalDate.class);
+ assertThat(christmasResult, is(new
java.sql.Date(christmasDate.getTime()).toLocalDate()));
+ }
+
+ @Test
+ void assertConvertDateValueToLocalDateWithCurrentDate() throws
SQLException {
+ Date now = new Date();
+ LocalDate result = (LocalDate) ResultSetUtils.convertValue(now,
LocalDate.class);
+ java.sql.Date sqlDate = new java.sql.Date(now.getTime());
+ assertThat(result, is(sqlDate.toLocalDate()));
+ }
}