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 4a921a2ac21 Support set datasource properties type with 
java.time.Duration (#34667) (#35241)
4a921a2ac21 is described below

commit 4a921a2ac21fdcbde2f86c416b0d4ee8b80d7c4c
Author: null <[email protected]>
AuthorDate: Sun May 25 22:50:03 2025 +0800

    Support set datasource properties type with java.time.Duration (#34667) 
(#35241)
---
 .../infra/datasource/pool/creator/DataSourcePoolReflection.java        | 3 +++
 .../infra/datasource/pool/creator/DataSourcePoolCreatorTest.java       | 3 +++
 .../org/apache/shardingsphere/test/fixture/jdbc/MockedDataSource.java  | 3 +++
 3 files changed, 9 insertions(+)

diff --git 
a/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolReflection.java
 
b/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolReflection.java
index 092729105a8..abdc02ca227 100644
--- 
a/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolReflection.java
+++ 
b/infra/data-source-pool/core/src/main/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolReflection.java
@@ -30,6 +30,7 @@ import 
org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
 
 import javax.sql.DataSource;
 import java.lang.reflect.Method;
+import java.time.Duration;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -146,6 +147,8 @@ public final class DataSourcePoolReflection {
             Properties props = new Properties();
             props.putAll((Map) fieldValue);
             method.invoke(dataSource, props);
+        } else if (Duration.class == paramType) {
+            method.invoke(dataSource, 
Duration.ofSeconds(Long.parseLong(fieldValue.toString())));
         } else {
             method.invoke(dataSource, fieldValue);
         }
diff --git 
a/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
 
b/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
index 57c56229639..0d4a1d86307 100644
--- 
a/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
+++ 
b/infra/data-source-pool/core/src/test/java/org/apache/shardingsphere/infra/datasource/pool/creator/DataSourcePoolCreatorTest.java
@@ -22,6 +22,7 @@ import 
org.apache.shardingsphere.test.fixture.jdbc.MockedDataSource;
 import org.junit.jupiter.api.Test;
 
 import javax.sql.DataSource;
+import java.time.Duration;
 import java.util.Collections;
 import java.util.LinkedHashMap;
 import java.util.Map;
@@ -50,6 +51,7 @@ class DataSourcePoolCreatorTest {
         result.put("username", "root");
         result.put("password", "root");
         result.put("driverClassName", MockedDataSource.class.getName());
+        result.put("connectionTimeout", "120");
         return result;
     }
     
@@ -60,5 +62,6 @@ class DataSourcePoolCreatorTest {
         assertThat(actual.getMaxPoolSize(), is(100));
         assertNull(actual.getMinPoolSize());
         assertThat(actual.getDriverClassName(), 
is(MockedDataSource.class.getName()));
+        assertThat(actual.getConnectionTimeout(), is(Duration.ofSeconds(120)));
     }
 }
diff --git 
a/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/jdbc/MockedDataSource.java
 
b/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/jdbc/MockedDataSource.java
index fbd3c023b97..3fdc1f6b1b7 100644
--- 
a/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/jdbc/MockedDataSource.java
+++ 
b/test/fixture/database/src/main/java/org/apache/shardingsphere/test/fixture/jdbc/MockedDataSource.java
@@ -26,6 +26,7 @@ import javax.sql.DataSource;
 import java.io.PrintWriter;
 import java.sql.Connection;
 import java.sql.SQLException;
+import java.time.Duration;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.List;
@@ -58,6 +59,8 @@ public final class MockedDataSource implements DataSource, 
AutoCloseable {
     
     private Integer minPoolSize;
     
+    private Duration connectionTimeout;
+    
     private List<String> connectionInitSqls;
     
     private Properties jdbcUrlProperties;

Reply via email to