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 d1ae41ddb78 Refactor TypedSPILoader (#26867)
d1ae41ddb78 is described below
commit d1ae41ddb78ac5c848033663b5878ee07971cf28
Author: ChenJiaHao <[email protected]>
AuthorDate: Mon Jul 10 12:41:40 2023 +0800
Refactor TypedSPILoader (#26867)
* Refactor TypedSPILoader
---
.../infra/util/spi/type/typed/TypedSPILoader.java | 12 +++++-------
kernel/data-pipeline/dialect/h2/pom.xml | 5 ++---
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
index 550f287e61c..e338cb7ee6e 100644
---
a/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
+++
b/infra/util/src/main/java/org/apache/shardingsphere/infra/util/spi/type/typed/TypedSPILoader.java
@@ -22,7 +22,6 @@ import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.util.spi.ShardingSphereServiceLoader;
import
org.apache.shardingsphere.infra.util.spi.exception.ServiceProviderNotFoundServerException;
-import java.util.Collection;
import java.util.Optional;
import java.util.Properties;
@@ -67,7 +66,7 @@ public final class TypedSPILoader {
*/
public static <T extends TypedSPI> Optional<T> findService(final Class<T>
spiClass, final String type, final Properties props) {
if (null == type) {
- return findService(spiClass);
+ return findDefaultService(spiClass);
}
for (T each :
ShardingSphereServiceLoader.getServiceInstances(spiClass)) {
if (matchesType(type, each)) {
@@ -75,10 +74,10 @@ public final class TypedSPILoader {
return Optional.of(each);
}
}
- return findService(spiClass);
+ return findDefaultService(spiClass);
}
- private static <T extends TypedSPI> Optional<T> findService(final Class<T>
spiClass) {
+ private static <T extends TypedSPI> Optional<T> findDefaultService(final
Class<T> spiClass) {
for (T each :
ShardingSphereServiceLoader.getServiceInstances(spiClass)) {
if (!each.isDefault()) {
continue;
@@ -120,7 +119,7 @@ public final class TypedSPILoader {
* @return service
*/
public static <T extends TypedSPI> T getService(final Class<T> spiClass,
final String type, final Properties props) {
- return findService(spiClass, type, props).orElseGet(() ->
findService(spiClass).orElseThrow(() -> new
ServiceProviderNotFoundServerException(spiClass, type)));
+ return findService(spiClass, type, props).orElseGet(() ->
findDefaultService(spiClass).orElseThrow(() -> new
ServiceProviderNotFoundServerException(spiClass, type)));
}
/**
@@ -134,8 +133,7 @@ public final class TypedSPILoader {
* @throws ServiceProviderNotFoundServerException service provider not
found server exception
*/
public static <T extends TypedSPI> boolean checkService(final Class<T>
spiClass, final String type, final Properties props) {
- Collection<T> serviceInstances =
ShardingSphereServiceLoader.getServiceInstances(spiClass);
- for (T each : serviceInstances) {
+ for (T each :
ShardingSphereServiceLoader.getServiceInstances(spiClass)) {
if (matchesType(type, each)) {
each.init(null == props ? new Properties() :
convertToStringTypedProperties(props));
return true;
diff --git a/kernel/data-pipeline/dialect/h2/pom.xml
b/kernel/data-pipeline/dialect/h2/pom.xml
index cec7829bd17..5a6f9ee4cca 100644
--- a/kernel/data-pipeline/dialect/h2/pom.xml
+++ b/kernel/data-pipeline/dialect/h2/pom.xml
@@ -16,13 +16,12 @@
~ limitations under the License.
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-data-pipeline-dialect</artifactId>
- <version>5.3.3-SNAPSHOT</version>
+ <version>5.4.1-SNAPSHOT</version>
</parent>
<artifactId>shardingsphere-data-pipeline-h2</artifactId>
<name>${project.artifactId}</name>