You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2021/12/28 15:48:50 UTC
[shardingsphere] branch master updated: Reuse TypedSPI on DataSourcePoolParameterDecorator (#14393)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 51fc1a9 Reuse TypedSPI on DataSourcePoolParameterDecorator (#14393)
51fc1a9 is described below
commit 51fc1a92bd48ad03a98ba3df893afd6e58ae08bc
Author: Liang Zhang <te...@163.com>
AuthorDate: Tue Dec 28 23:48:07 2021 +0800
Reuse TypedSPI on DataSourcePoolParameterDecorator (#14393)
---
.../config/datasource/DataSourcePoolParameterDecorator.java | 11 +++--------
.../datasource/DataSourcePoolParameterDecoratorHelper.java | 2 +-
.../jdbc/datasource/decorator/HikariParameterDecorator.java | 4 ++--
.../datasource/decorator/HikariParameterDecoratorTest.java | 10 ++--------
4 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecorator.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecorator.java
index a15c91b..b9e6520 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecorator.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecorator.java
@@ -17,6 +17,8 @@
package org.apache.shardingsphere.infra.config.datasource;
+import org.apache.shardingsphere.spi.typed.TypedSPI;
+
import javax.sql.DataSource;
/**
@@ -24,7 +26,7 @@ import javax.sql.DataSource;
*
* @param <T> type of data source
*/
-public interface DataSourcePoolParameterDecorator<T extends DataSource> {
+public interface DataSourcePoolParameterDecorator<T extends DataSource> extends TypedSPI {
/**
* Decorate data source.
@@ -33,11 +35,4 @@ public interface DataSourcePoolParameterDecorator<T extends DataSource> {
* @return decorated data source
*/
T decorate(T dataSource);
-
- /**
- * Get data source type.
- *
- * @return data source type
- */
- Class<T> getType();
}
diff --git a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecoratorHelper.java b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecoratorHelper.java
index d881a5d..1191b27 100644
--- a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecoratorHelper.java
+++ b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/datasource/DataSourcePoolParameterDecoratorHelper.java
@@ -41,7 +41,7 @@ public final class DataSourcePoolParameterDecoratorHelper {
Optional<DataSourcePoolParameterDecorator> decorator = ShardingSphereServiceLoader
.getSingletonServiceInstances(DataSourcePoolParameterDecorator.class)
.stream()
- .filter(each -> each.getType() == dataSource.getClass()).findFirst();
+ .filter(each -> each.getType().equals(dataSource.getClass().getCanonicalName())).findFirst();
return decorator.isPresent() ? decorator.get().decorate(dataSource) : dataSource;
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecorator.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecorator.java
index e1990a6..26eab6b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecorator.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecorator.java
@@ -58,7 +58,7 @@ public final class HikariParameterDecorator implements DataSourcePoolParameterDe
}
@Override
- public Class<HikariDataSource> getType() {
- return HikariDataSource.class;
+ public String getType() {
+ return HikariDataSource.class.getCanonicalName();
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecoratorTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecoratorTest.java
index a53ab6d..c97c64d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecoratorTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/decorator/HikariParameterDecoratorTest.java
@@ -25,18 +25,12 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
public final class HikariParameterDecoratorTest {
@Test
- public void assertGetTypeResultIsHikariDataSource() {
- assertSame(HikariDataSource.class, new HikariParameterDecorator().getType());
- }
-
- @Test
- public void assertDecoratedHikariDataSource() {
+ public void assertDecorate() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName(MockedDriver.class.getName());
dataSource.setJdbcUrl("mock:jdbc");
@@ -59,7 +53,7 @@ public final class HikariParameterDecoratorTest {
}
@Test
- public void assertDecoratedHikariDataSourceWithExistedParam() {
+ public void assertDecorateWithExistedParam() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName(MockedDriver.class.getName());
dataSource.setJdbcUrl("mock:jdbc://127.0.0.1:3306/test0?tinyInt1isBit=true&useSSL=false");