From e5f4ce20a9daa4d0af254142f5203c4a13879496 Mon Sep 17 00:00:00 2001 From: terrymanu Date: Tue, 25 Sep 2018 17:27:39 +0800 Subject: [PATCH] for #1172, simplify spi loader --- .../core/bootstrap/ShardingBootstrap.java | 10 ++++++++++ .../spi/connection/close/SPICloseConnectionHook.java | 6 +----- .../core/spi/connection/get/SPIGetConnectionHook.java | 6 +----- .../core/spi/executor/SPISQLExecutionHook.java | 6 +----- .../core/spi/parsing/SPIParsingHook.java | 6 +----- .../core/spi/root/SPIRootInvokeHook.java | 6 +----- 6 files changed, 15 insertions(+), 25 deletions(-) diff --git a/sharding-core/src/main/java/io/shardingsphere/core/bootstrap/ShardingBootstrap.java b/sharding-core/src/main/java/io/shardingsphere/core/bootstrap/ShardingBootstrap.java index 3c8acaa6ceccd..9bb2920bc6e5f 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/bootstrap/ShardingBootstrap.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/bootstrap/ShardingBootstrap.java @@ -18,6 +18,11 @@ package io.shardingsphere.core.bootstrap; import io.shardingsphere.core.event.ShardingEventListenerRegistrySPILoader; +import io.shardingsphere.core.spi.connection.close.SPICloseConnectionHook; +import io.shardingsphere.core.spi.connection.get.SPIGetConnectionHook; +import io.shardingsphere.core.spi.executor.SPISQLExecutionHook; +import io.shardingsphere.core.spi.parsing.SPIParsingHook; +import io.shardingsphere.core.spi.root.SPIRootInvokeHook; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -34,5 +39,10 @@ public final class ShardingBootstrap { */ public static void init() { ShardingEventListenerRegistrySPILoader.registerListeners(); + new SPIRootInvokeHook(); + new SPIParsingHook(); + new SPIGetConnectionHook(); + new SPISQLExecutionHook(); + new SPICloseConnectionHook(); } } diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java index d79b8a803f12d..3a08a6e230c55 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/close/SPICloseConnectionHook.java @@ -28,11 +28,7 @@ */ public final class SPICloseConnectionHook implements CloseConnectionHook { - private static final ServiceLoader SERVICE_LOADER; - - static { - SERVICE_LOADER = ServiceLoader.load(CloseConnectionHook.class); - } + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(CloseConnectionHook.class); @Override public void start(final String dataSourceName, final DataSourceMetaData dataSourceMetaData) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java index ec691dd38288d..e68944d965eea 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/connection/get/SPIGetConnectionHook.java @@ -28,11 +28,7 @@ */ public final class SPIGetConnectionHook implements GetConnectionHook { - private static final ServiceLoader SERVICE_LOADER; - - static { - SERVICE_LOADER = ServiceLoader.load(GetConnectionHook.class); - } + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(GetConnectionHook.class); @Override public void start(final String dataSourceName) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SPISQLExecutionHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SPISQLExecutionHook.java index ed59132a041dc..a7f99058e61c2 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SPISQLExecutionHook.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/executor/SPISQLExecutionHook.java @@ -30,11 +30,7 @@ */ public final class SPISQLExecutionHook implements SQLExecutionHook { - private static final ServiceLoader SERVICE_LOADER; - - static { - SERVICE_LOADER = ServiceLoader.load(SQLExecutionHook.class); - } + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(SQLExecutionHook.class); @Override public void start(final RouteUnit routeUnit, final List parameters, final DataSourceMetaData dataSourceMetaData) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/SPIParsingHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/SPIParsingHook.java index 117b03e80111b..b84afcff1c6a5 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/SPIParsingHook.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/parsing/SPIParsingHook.java @@ -26,11 +26,7 @@ */ public final class SPIParsingHook implements ParsingHook { - private static final ServiceLoader SERVICE_LOADER; - - static { - SERVICE_LOADER = ServiceLoader.load(ParsingHook.class); - } + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(ParsingHook.class); @Override public void start(final String sql) { diff --git a/sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java b/sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java index ac38e9f66da41..2175f30bbd1b7 100644 --- a/sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java +++ b/sharding-core/src/main/java/io/shardingsphere/core/spi/root/SPIRootInvokeHook.java @@ -26,11 +26,7 @@ */ public final class SPIRootInvokeHook implements RootInvokeHook { - private static final ServiceLoader SERVICE_LOADER; - - static { - SERVICE_LOADER = ServiceLoader.load(RootInvokeHook.class); - } + private static final ServiceLoader SERVICE_LOADER = ServiceLoader.load(RootInvokeHook.class); @Override public void start() {