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 c2df055  Use SPI for DriverStateContext (#11905)
c2df055 is described below

commit c2df0553596ccd24646fafe1ab11b63baa81c8d3
Author: Liang Zhang <[email protected]>
AuthorDate: Thu Aug 19 20:45:22 2021 +0800

    Use SPI for DriverStateContext (#11905)
    
    * private ShardingSphereDataSource.getDataSourceMap()
    
    * private ShardingSphereDataSource.getDataSourceMap()
    
    * Remove StateType
    
    * Use SPI for DriverStateContext
    
    * Use SPI for DriverStateContext
    
    * Unify ShardingSphereDataSource and GovernanceShardingSphereDataSource
---
 .../prometheus/collector/ProxyInfoCollector.java   |  7 ++--
 .../state/watcher/TerminalStateChangedWatcher.java |  5 ++-
 .../shardingsphere/infra/state/StateContext.java   |  8 ++---
 .../shardingsphere/infra/state/StateEvent.java     |  2 +-
 .../shardingsphere/infra/state/StateType.java      | 26 ---------------
 .../infra/state/StateContextTest.java              | 20 ++++++------
 .../core/datasource/ShardingSphereDataSource.java  | 38 ++++++++++------------
 .../shardingsphere/driver}/state/DriverState.java  |  5 +--
 .../driver}/state/DriverStateContext.java          | 22 +++++++------
 .../driver/state}/OKDriverState.java               |  8 +++--
 ....apache.shardingsphere.driver.state.DriverState | 18 ++++++++++
 ...ractShardingSphereDataSourceForEncryptTest.java |  7 ++--
 ...actShardingSphereDataSourceForFederateTest.java |  2 +-
 ...actShardingSphereDataSourceForShardingTest.java |  8 ++---
 .../datasource/ShardingSphereDataSourceTest.java   |  8 ++---
 .../driver/state}/OKDriverStateTest.java           |  2 +-
 .../GovernanceShardingSphereDataSource.java        | 34 +++++++++++--------
 .../state/{impl => }/CircuitBreakDriverState.java  |  9 +++--
 .../internal/state/{impl => }/LockDriverState.java |  9 +++--
 ....apache.shardingsphere.driver.state.DriverState | 19 +++++++++++
 .../{impl => }/CircuitBreakDriverStateTest.java    |  2 +-
 .../internal/state/DriverStateContextTest.java     |  4 +--
 .../proxy/frontend/state/ProxyStateContext.java    |  9 +++--
 23 files changed, 153 insertions(+), 119 deletions(-)

diff --git 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
index a133160..664de21 100644
--- 
a/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
+++ 
b/shardingsphere-agent/shardingsphere-agent-plugins/shardingsphere-agent-plugin-metrics/shardingsphere-agent-metrics-prometheus/src/main/java/org/apache/shardingsphere/agent/metrics/prometheus/collector/ProxyInfoCollector.java
@@ -22,7 +22,6 @@ import io.prometheus.client.GaugeMetricFamily;
 import org.apache.shardingsphere.agent.metrics.api.constant.MetricIds;
 import org.apache.shardingsphere.agent.metrics.api.util.MetricsUtil;
 import 
org.apache.shardingsphere.agent.metrics.prometheus.wrapper.PrometheusWrapperFactory;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 
 import java.util.Collections;
 import java.util.LinkedList;
@@ -47,8 +46,10 @@ public final class ProxyInfoCollector extends Collector {
             return result;
         }
         Optional<GaugeMetricFamily> proxyInfo = 
FACTORY.createGaugeMetricFamily(MetricIds.PROXY_INFO);
-        proxyInfo.ifPresent(m -> 
-                m.addMetric(Collections.singletonList(PROXY_STATE), 
ProxyContext.getInstance().getStateContext().getCurrentState().ordinal()));
+        // TODO use digital instead of zero 
+//        proxyInfo.ifPresent(m -> 
+//                m.addMetric(Collections.singletonList(PROXY_STATE), 
ProxyContext.getInstance().getStateContext().getCurrentState().ordinal()));
+        proxyInfo.ifPresent(optional -> 
optional.addMetric(Collections.singletonList(PROXY_STATE), 0));
         proxyInfo.ifPresent(result::add);
         return result;
     }
diff --git 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/state/watcher/TerminalStateChangedWatcher.java
 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/state/watcher/TerminalStateChangedWatcher.java
index 7596305..68acf6d 100644
--- 
a/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/state/watcher/TerminalStateChangedWatcher.java
+++ 
b/shardingsphere-governance/shardingsphere-governance-core/src/main/java/org/apache/shardingsphere/governance/core/registry/state/watcher/TerminalStateChangedWatcher.java
@@ -17,14 +17,13 @@
 
 package org.apache.shardingsphere.governance.core.registry.state.watcher;
 
-import org.apache.shardingsphere.governance.core.registry.state.ResourceState;
 import org.apache.shardingsphere.governance.core.GovernanceInstance;
 import org.apache.shardingsphere.governance.core.registry.GovernanceWatcher;
+import org.apache.shardingsphere.governance.core.registry.state.ResourceState;
 import 
org.apache.shardingsphere.governance.core.registry.state.node.StatesNode;
 import 
org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent;
 import 
org.apache.shardingsphere.governance.repository.api.listener.DataChangedEvent.Type;
 import org.apache.shardingsphere.infra.state.StateEvent;
-import org.apache.shardingsphere.infra.state.StateType;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -47,6 +46,6 @@ public final class TerminalStateChangedWatcher implements 
GovernanceWatcher<Stat
     
     @Override
     public Optional<StateEvent> createGovernanceEvent(final DataChangedEvent 
event) {
-        return Optional.of(new StateEvent(StateType.CIRCUIT_BREAK, 
ResourceState.DISABLED.toString().equalsIgnoreCase(event.getValue())));
+        return Optional.of(new StateEvent("CIRCUIT_BREAK", 
ResourceState.DISABLED.toString().equalsIgnoreCase(event.getValue())));
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java
index 00b3d92..1beafe7 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateContext.java
@@ -30,7 +30,7 @@ import java.util.concurrent.ConcurrentLinkedDeque;
  */
 public final class StateContext {
     
-    private final Deque<StateType> currentState = new 
ConcurrentLinkedDeque<>(Collections.singleton(StateType.OK));
+    private final Deque<String> currentState = new 
ConcurrentLinkedDeque<>(Collections.singleton("OK"));
     
     public StateContext() {
         ShardingSphereEventBus.getInstance().register(this);
@@ -46,7 +46,7 @@ public final class StateContext {
         if (event.isOn()) {
             currentState.push(event.getType());
         } else {
-            if (getCurrentState() == event.getType()) {
+            if (getCurrentState().equals(event.getType())) {
                 recoverState();
             }
         }
@@ -61,7 +61,7 @@ public final class StateContext {
      * 
      * @return current state
      */
-    public StateType getCurrentState() {
-        return Optional.ofNullable(currentState.peek()).orElse(StateType.OK);
+    public String getCurrentState() {
+        return Optional.ofNullable(currentState.peek()).orElse("OK");
     }
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateEvent.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateEvent.java
index d58e49a..29153fd 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateEvent.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateEvent.java
@@ -27,7 +27,7 @@ import lombok.RequiredArgsConstructor;
 @Getter
 public final class StateEvent {
     
-    private final StateType type;
+    private final String type;
     
     private final boolean on;
 }
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateType.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateType.java
deleted file mode 100644
index 8c842f8..0000000
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/state/StateType.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.infra.state;
-
-/**
- * State type.
- */
-public enum StateType {
-    
-    OK, LOCK, CIRCUIT_BREAK
-}
diff --git 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/state/StateContextTest.java
 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/state/StateContextTest.java
index 78f652b..d534cb1 100644
--- 
a/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/state/StateContextTest.java
+++ 
b/shardingsphere-infra/shardingsphere-infra-common/src/test/java/org/apache/shardingsphere/infra/state/StateContextTest.java
@@ -28,23 +28,23 @@ public final class StateContextTest {
     
     @Test
     public void assertSwitchStateWithCircuitBreakOn() {
-        stateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, 
true));
-        assertThat(stateContext.getCurrentState(), 
is(StateType.CIRCUIT_BREAK));
-        stateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, 
false));
+        stateContext.switchState(new StateEvent("CIRCUIT_BREAK", true));
+        assertThat(stateContext.getCurrentState(), is("CIRCUIT_BREAK"));
+        stateContext.switchState(new StateEvent("CIRCUIT_BREAK", false));
     }
     
     @Test
     public void assertSwitchStateWithCircuitBreakOff() {
-        stateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, 
false));
-        assertThat(stateContext.getCurrentState(), is(StateType.OK));
+        stateContext.switchState(new StateEvent("CIRCUIT_BREAK", false));
+        assertThat(stateContext.getCurrentState(), is("OK"));
     }
     
     @Test
     public void assertSwitchStateWithMultiState() {
-        stateContext.switchState(new StateEvent(StateType.CIRCUIT_BREAK, 
true));
-        stateContext.switchState(new StateEvent(StateType.LOCK, true));
-        assertThat(stateContext.getCurrentState(), is(StateType.LOCK));
-        stateContext.switchState(new StateEvent(StateType.LOCK, false));
-        assertThat(stateContext.getCurrentState(), 
is(StateType.CIRCUIT_BREAK));
+        stateContext.switchState(new StateEvent("CIRCUIT_BREAK", true));
+        stateContext.switchState(new StateEvent("LOCK", true));
+        assertThat(stateContext.getCurrentState(), is("LOCK"));
+        stateContext.switchState(new StateEvent("LOCK", false));
+        assertThat(stateContext.getCurrentState(), is("CIRCUIT_BREAK"));
     }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
index 34553dc..fc07d12 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSource.java
@@ -18,8 +18,8 @@
 package org.apache.shardingsphere.driver.jdbc.core.datasource;
 
 import lombok.Getter;
-import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import 
org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
+import org.apache.shardingsphere.driver.state.DriverStateContext;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.scope.GlobalRuleConfiguration;
 import org.apache.shardingsphere.infra.config.scope.SchemaRuleConfiguration;
@@ -33,6 +33,7 @@ import 
org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
 
 import javax.sql.DataSource;
+import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collection;
 import java.util.Collections;
@@ -64,40 +65,32 @@ public final class ShardingSphereDataSource extends 
AbstractUnsupportedOperation
     private ContextManager createContextManager(final String schemaName, final 
ModeConfiguration modeConfig, 
                                                 final Map<String, DataSource> 
dataSourceMap, final Collection<RuleConfiguration> ruleConfigs, final 
Properties props) throws SQLException {
         ShardingSphereMode mode = ModeBuilderEngine.build(modeConfig);
-        Collection<RuleConfiguration> schemaRuleConfigs = 
ruleConfigs.stream().filter(each -> each instanceof 
SchemaRuleConfiguration).collect(Collectors.toList());
+        Map<String, Map<String, DataSource>> dataSourcesMap = 
Collections.singletonMap(schemaName, dataSourceMap);
+        Map<String, Collection<RuleConfiguration>> schemaRuleConfigs = 
Collections.singletonMap(
+                schemaName, ruleConfigs.stream().filter(each -> each 
instanceof SchemaRuleConfiguration).collect(Collectors.toList()));
         Collection<RuleConfiguration> globalRuleConfigs = 
ruleConfigs.stream().filter(each -> each instanceof 
GlobalRuleConfiguration).collect(Collectors.toList());
         ContextManagerBuilder builder = 
TypedSPIRegistry.getRegisteredService(ContextManagerBuilder.class, 
modeConfig.getType(), new Properties());
-        return builder.build(mode, Collections.singletonMap(schemaName, 
dataSourceMap), Collections.singletonMap(schemaName, schemaRuleConfigs), 
globalRuleConfigs, props, modeConfig.isOverwrite());
+        return builder.build(mode, dataSourcesMap, schemaRuleConfigs, 
globalRuleConfigs, props, modeConfig.isOverwrite());
     }
     
     @Override
-    public ShardingSphereConnection getConnection() {
-        return new ShardingSphereConnection(schemaName, getDataSourceMap(), 
contextManager, TransactionTypeHolder.get());
+    public Connection getConnection() {
+        return DriverStateContext.getConnection(schemaName, 
getDataSourceMap(), contextManager, TransactionTypeHolder.get());
     }
     
     @Override
-    public ShardingSphereConnection getConnection(final String username, final 
String password) {
+    public Connection getConnection(final String username, final String 
password) {
         return getConnection();
     }
     
-    /**
-     * Get data sources.
-     * 
-     * @return data sources
-     */
-    public Map<String, DataSource> getDataSourceMap() {
+    private Map<String, DataSource> getDataSourceMap() {
         return 
contextManager.getMetaDataContexts().getMetaData(schemaName).getResource().getDataSources();
     }
     
-    @Override
-    public void close() throws Exception {
-        close(getDataSourceMap().keySet());
-    }
-    
     /**
-     * Close dataSources.
-     * 
-     * @param dataSourceNames data source names
+     * Close data sources.
+     *
+     * @param dataSourceNames data source names to be closed
      * @throws Exception exception
      */
     public void close(final Collection<String> dataSourceNames) throws 
Exception {
@@ -112,4 +105,9 @@ public final class ShardingSphereDataSource extends 
AbstractUnsupportedOperation
             ((AutoCloseable) dataSource).close();
         }
     }
+    
+    @Override
+    public void close() throws Exception {
+        close(getDataSourceMap().keySet());
+    }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverState.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/DriverState.java
similarity index 90%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverState.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/DriverState.java
index 2642be7..3492bb6 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverState.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/DriverState.java
@@ -15,9 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state;
+package org.apache.shardingsphere.driver.state;
 
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
+import org.apache.shardingsphere.infra.spi.typed.TypedSPI;
 import org.apache.shardingsphere.transaction.core.TransactionType;
 
 import javax.sql.DataSource;
@@ -27,7 +28,7 @@ import java.util.Map;
 /**
  * Driver state.
  */
-public interface DriverState {
+public interface DriverState extends TypedSPI {
     
     /**
      * Get connection.
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/DriverStateContext.java
similarity index 71%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/DriverStateContext.java
index d0cb95d..bfa9246 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContext.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/DriverStateContext.java
@@ -15,21 +15,19 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state;
+package org.apache.shardingsphere.driver.state;
 
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import 
org.apache.shardingsphere.driver.governance.internal.state.impl.CircuitBreakDriverState;
-import 
org.apache.shardingsphere.driver.governance.internal.state.impl.LockDriverState;
-import 
org.apache.shardingsphere.driver.governance.internal.state.impl.OKDriverState;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
-import org.apache.shardingsphere.infra.state.StateType;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
 import org.apache.shardingsphere.transaction.core.TransactionType;
 
 import javax.sql.DataSource;
 import java.sql.Connection;
+import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 /**
  * Driver state context.
@@ -37,12 +35,16 @@ import java.util.concurrent.ConcurrentHashMap;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class DriverStateContext {
     
-    private static final Map<StateType, DriverState> STATES = new 
ConcurrentHashMap<>(3, 1);
+    private static final Map<String, DriverState> STATES;
     
     static {
-        STATES.put(StateType.OK, new OKDriverState());
-        STATES.put(StateType.LOCK, new LockDriverState());
-        STATES.put(StateType.CIRCUIT_BREAK, new CircuitBreakDriverState());
+        // TODO add singleton cache with TypedSPI init
+        ShardingSphereServiceLoader.register(DriverState.class);
+        Collection<DriverState> driverStates = 
ShardingSphereServiceLoader.getSingletonServiceInstances(DriverState.class);
+        STATES = new HashMap<>();
+        for (DriverState each : driverStates) {
+            STATES.put(each.getType(), each);
+        }
     }
     
     /**
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverState.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/OKDriverState.java
similarity index 91%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverState.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/OKDriverState.java
index 8271499..172cdf4 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverState.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/state/OKDriverState.java
@@ -15,9 +15,8 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state.impl;
+package org.apache.shardingsphere.driver.state;
 
-import org.apache.shardingsphere.driver.governance.internal.state.DriverState;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
 import org.apache.shardingsphere.transaction.core.TransactionType;
@@ -36,4 +35,9 @@ public final class OKDriverState implements DriverState {
     public Connection getConnection(final String schemaName, final Map<String, 
DataSource> dataSourceMap, final ContextManager contextManager, final 
TransactionType transactionType) {
         return new ShardingSphereConnection(schemaName, dataSourceMap, 
contextManager, TransactionTypeHolder.get());
     }
+    
+    @Override
+    public String getType() {
+        return "OK";
+    }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.state.DriverState
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.state.DriverState
new file mode 100644
index 0000000..afb72a2
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.state.DriverState
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.driver.state.OKDriverState
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
index 00ed597..e40f6c7 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForEncryptTest.java
@@ -31,6 +31,7 @@ import javax.sql.DataSource;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collections;
 import java.util.List;
@@ -70,19 +71,19 @@ public abstract class 
AbstractShardingSphereDataSourceForEncryptTest extends Abs
     
     @Before
     public void initTable() {
-        try (ShardingSphereConnection connection = 
queryWithPlainDataSource.getConnection()) {
+        try (Connection connection = queryWithPlainDataSource.getConnection()) 
{
             RunScript.execute(connection, new 
InputStreamReader(Objects.requireNonNull(AbstractSQLTest.class.getClassLoader().getResourceAsStream("sql/encrypt_data.sql"))));
         } catch (final SQLException ex) {
             throw new RuntimeException(ex);
         }
     }
     
-    protected final ShardingSphereConnection getEncryptConnection() {
+    protected final Connection getEncryptConnection() {
         return queryWithPlainDataSource.getConnection();
     }
     
     protected final ShardingSphereConnection getEncryptConnectionWithProps() {
-        return queryWithCipherDataSource.getConnection();
+        return (ShardingSphereConnection) 
queryWithCipherDataSource.getConnection();
     }
     
     @AfterClass
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
index 8a39d0a..9b65e89 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForFederateTest.java
@@ -64,7 +64,7 @@ public abstract class 
AbstractShardingSphereDataSourceForFederateTest extends Ab
     @Before
     public void initTable() {
         try {
-            ShardingSphereConnection conn = dataSource.getConnection();
+            ShardingSphereConnection conn = (ShardingSphereConnection) 
dataSource.getConnection();
             Map<String, DataSource> dataSourceMap = conn.getDataSourceMap();
             Connection database0 = 
dataSourceMap.get("federate_jdbc_0").getConnection();
             Connection database1 = 
dataSourceMap.get("federate_jdbc_1").getConnection();
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
index 80f635b..2ab45fd 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/base/AbstractShardingSphereDataSourceForShardingTest.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.driver.jdbc.base;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.Maps;
 import 
org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
-import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import 
org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
 import org.h2.tools.RunScript;
 import org.junit.AfterClass;
@@ -28,9 +27,10 @@ import org.junit.Before;
 import org.junit.BeforeClass;
 
 import javax.sql.DataSource;
-import java.io.InputStreamReader;
-import java.io.IOException;
 import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.List;
@@ -65,7 +65,7 @@ public abstract class 
AbstractShardingSphereDataSourceForShardingTest extends Ab
     @Before
     public void initTable() {
         try {
-            ShardingSphereConnection conn = dataSource.getConnection();
+            Connection conn = dataSource.getConnection();
             RunScript.execute(conn, new 
InputStreamReader(Objects.requireNonNull(AbstractSQLTest.class.getClassLoader().getResourceAsStream("sql/jdbc_data.sql"))));
             conn.close();
         } catch (final SQLException ex) {
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
index 1364b5e..f6262fa 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/datasource/ShardingSphereDataSourceTest.java
@@ -147,7 +147,7 @@ public final class ShardingSphereDataSourceTest {
         DataSource dataSource = 
mockDataSource(DatabaseTypeRegistry.getActualDatabaseType("H2"));
         Map<String, DataSource> dataSourceMap = new HashMap<>(1, 1);
         dataSourceMap.put("ds", dataSource);
-        
assertThat(createShardingSphereDataSource(dataSourceMap).getConnection().getConnection("ds"),
 is(dataSource.getConnection()));
+        assertThat(((ShardingSphereConnection) 
createShardingSphereDataSource(dataSourceMap).getConnection()).getConnection("ds"),
 is(dataSource.getConnection()));
     }
     
     @Test
@@ -158,7 +158,7 @@ public final class ShardingSphereDataSourceTest {
         TransactionTypeHolder.set(TransactionType.XA);
         ShardingSphereDataSource shardingSphereDataSource = 
createShardingSphereDataSource(dataSourceMap);
         
assertThat(shardingSphereDataSource.getContextManager().getMetaDataContexts().getMetaData(DefaultSchema.LOGIC_NAME).getResource().getDataSources().size(),
 is(1));
-        ShardingSphereConnection connection = 
shardingSphereDataSource.getConnection();
+        ShardingSphereConnection connection = (ShardingSphereConnection) 
shardingSphereDataSource.getConnection();
         assertThat(connection.getDataSourceMap().size(), is(1));
     }
     
@@ -169,12 +169,12 @@ public final class ShardingSphereDataSourceTest {
         dataSourceMap.put("ds", dataSource);
         TransactionTypeHolder.set(TransactionType.XA);
         ShardingSphereDataSource shardingSphereDataSource = 
createShardingSphereDataSource(dataSourceMap);
-        ShardingSphereConnection connection = 
shardingSphereDataSource.getConnection();
+        ShardingSphereConnection connection = (ShardingSphereConnection) 
shardingSphereDataSource.getConnection();
         assertThat(connection.getDataSourceMap().size(), is(1));
         assertThat(connection.getTransactionType(), is(TransactionType.XA));
         assertThat(connection.getShardingTransactionManager(), 
instanceOf(XAShardingTransactionManagerFixture.class));
         TransactionTypeHolder.set(TransactionType.LOCAL);
-        connection = shardingSphereDataSource.getConnection();
+        connection = (ShardingSphereConnection) 
shardingSphereDataSource.getConnection();
         assertThat(connection.getConnection("ds"), 
is(dataSource.getConnection()));
         assertThat(connection.getDataSourceMap(), is(dataSourceMap));
         assertThat(connection.getTransactionType(), is(TransactionType.LOCAL));
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverStateTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/OKDriverStateTest.java
similarity index 96%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverStateTest.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/OKDriverStateTest.java
index a933af7..4d45d31 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/OKDriverStateTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/state/OKDriverStateTest.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state.impl;
+package org.apache.shardingsphere.driver.state;
 
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
index b20881e..ec60058 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/datasource/GovernanceShardingSphereDataSource.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.driver.governance.internal.datasource;
 
 import lombok.Getter;
-import 
org.apache.shardingsphere.driver.governance.internal.state.DriverStateContext;
+import org.apache.shardingsphere.driver.state.DriverStateContext;
 import 
org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.config.scope.GlobalRuleConfiguration;
@@ -33,7 +33,6 @@ import 
org.apache.shardingsphere.infra.spi.typed.TypedSPIRegistry;
 import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
 
 import javax.sql.DataSource;
-import java.lang.reflect.Method;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Collection;
@@ -98,22 +97,31 @@ public final class GovernanceShardingSphereDataSource 
extends AbstractUnsupporte
         return getConnection();
     }
     
-    @Override
-    public void close() throws Exception {
-        getDataSourceMap().forEach((key, value) -> close(value));
+    private Map<String, DataSource> getDataSourceMap() {
+        return 
contextManager.getMetaDataContexts().getMetaData(schemaName).getResource().getDataSources();
+    }
+    
+    /**
+     * Close data sources.
+     *
+     * @param dataSourceNames data source names to be closed
+     * @throws Exception exception
+     */
+    public void close(final Collection<String> dataSourceNames) throws 
Exception {
+        for (String each : dataSourceNames) {
+            close(getDataSourceMap().get(each));
+        }
         contextManager.close();
     }
     
-    private void close(final DataSource dataSource) {
-        try {
-            Method method = dataSource.getClass().getDeclaredMethod("close");
-            method.setAccessible(true);
-            method.invoke(dataSource);
-        } catch (final ReflectiveOperationException ignored) {
+    private void close(final DataSource dataSource) throws Exception {
+        if (dataSource instanceof AutoCloseable) {
+            ((AutoCloseable) dataSource).close();
         }
     }
     
-    private Map<String, DataSource> getDataSourceMap() {
-        return 
contextManager.getMetaDataContexts().getMetaData(schemaName).getResource().getDataSources();
+    @Override
+    public void close() throws Exception {
+        close(getDataSourceMap().keySet());
     }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverState.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/CircuitBreakDriverState.java
similarity index 91%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverState.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/CircuitBreakDriverState.java
index a174626..be810b4 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverState.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/CircuitBreakDriverState.java
@@ -15,10 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state.impl;
+package org.apache.shardingsphere.driver.governance.internal.state;
 
 import 
org.apache.shardingsphere.driver.governance.internal.circuit.datasource.CircuitBreakerDataSource;
-import org.apache.shardingsphere.driver.governance.internal.state.DriverState;
+import org.apache.shardingsphere.driver.state.DriverState;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
 import org.apache.shardingsphere.transaction.core.TransactionType;
 
@@ -35,4 +35,9 @@ public final class CircuitBreakDriverState implements 
DriverState {
     public Connection getConnection(final String schemaName, final Map<String, 
DataSource> dataSourceMap, final ContextManager contextManager, final 
TransactionType transactionType) {
         return new CircuitBreakerDataSource().getConnection();
     }
+    
+    @Override
+    public String getType() {
+        return "CIRCUIT_BREAK";
+    }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/LockDriverState.java
similarity index 91%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/LockDriverState.java
index c940423..ddbb39b 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/impl/LockDriverState.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/java/org/apache/shardingsphere/driver/governance/internal/state/LockDriverState.java
@@ -15,9 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state.impl;
+package org.apache.shardingsphere.driver.governance.internal.state;
 
-import org.apache.shardingsphere.driver.governance.internal.state.DriverState;
+import org.apache.shardingsphere.driver.state.DriverState;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
 import org.apache.shardingsphere.transaction.core.TransactionType;
 
@@ -35,4 +35,9 @@ public final class LockDriverState implements DriverState {
         // TODO
         throw new UnsupportedOperationException("LockDriverState");
     }
+    
+    @Override
+    public String getType() {
+        return "LOCK";
+    }
 }
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.state.DriverState
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.state.DriverState
new file mode 100644
index 0000000..dfd9095
--- /dev/null
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/main/resources/META-INF/services/org.apache.shardingsphere.driver.state.DriverState
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.driver.governance.internal.state.CircuitBreakDriverState
+org.apache.shardingsphere.driver.governance.internal.state.LockDriverState
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverStateTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/CircuitBreakDriverStateTest.java
similarity index 99%
rename from 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverStateTest.java
rename to 
shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/CircuitBreakDriverStateTest.java
index 92cdebb..6403c36 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/impl/CircuitBreakDriverStateTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/CircuitBreakDriverStateTest.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.driver.governance.internal.state.impl;
+package org.apache.shardingsphere.driver.governance.internal.state;
 
 import 
org.apache.shardingsphere.driver.governance.internal.circuit.connection.CircuitBreakerConnection;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
diff --git 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
index 514e12b..bdabdca 100644
--- 
a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
+++ 
b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/state/DriverStateContextTest.java
@@ -19,12 +19,12 @@ package 
org.apache.shardingsphere.driver.governance.internal.state;
 
 import 
org.apache.shardingsphere.driver.governance.internal.circuit.connection.CircuitBreakerConnection;
 import 
org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.apache.shardingsphere.driver.state.DriverStateContext;
 import org.apache.shardingsphere.infra.context.manager.ContextManager;
 import org.apache.shardingsphere.infra.context.metadata.MetaDataContexts;
 import org.apache.shardingsphere.infra.database.DefaultSchema;
 import org.apache.shardingsphere.infra.persist.DistMetaDataPersistService;
 import org.apache.shardingsphere.infra.state.StateEvent;
-import org.apache.shardingsphere.infra.state.StateType;
 import org.apache.shardingsphere.transaction.core.TransactionType;
 import org.junit.Before;
 import org.junit.Test;
@@ -63,7 +63,7 @@ public final class DriverStateContextTest {
     
     @Test
     public void assertGetConnectionWithCircuitBreakState() {
-        contextManager.getMetaDataContexts().getStateContext().switchState(new 
StateEvent(StateType.CIRCUIT_BREAK, true));
+        contextManager.getMetaDataContexts().getStateContext().switchState(new 
StateEvent("CIRCUIT_BREAK", true));
         Connection actual = DriverStateContext.getConnection(
                 DefaultSchema.LOGIC_NAME, Collections.singletonMap("ds", 
mock(DataSource.class, RETURNS_DEEP_STUBS)), contextManager, 
TransactionType.LOCAL);
         assertThat(actual, instanceOf(CircuitBreakerConnection.class));
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
index 238c602..36a2451 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/ProxyStateContext.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.proxy.frontend.state;
 import io.netty.channel.ChannelHandlerContext;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
-import org.apache.shardingsphere.infra.state.StateType;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
 import 
org.apache.shardingsphere.proxy.frontend.spi.DatabaseProtocolFrontendEngine;
@@ -37,12 +36,12 @@ import java.util.concurrent.ConcurrentHashMap;
 @NoArgsConstructor(access = AccessLevel.PRIVATE)
 public final class ProxyStateContext {
     
-    private static final Map<StateType, ProxyState> STATES = new 
ConcurrentHashMap<>(3, 1);
+    private static final Map<String, ProxyState> STATES = new 
ConcurrentHashMap<>(3, 1);
     
     static {
-        STATES.put(StateType.OK, new OKProxyState());
-        STATES.put(StateType.LOCK, new LockProxyState());
-        STATES.put(StateType.CIRCUIT_BREAK, new CircuitBreakProxyState());
+        STATES.put("OK", new OKProxyState());
+        STATES.put("LOCK", new LockProxyState());
+        STATES.put("CIRCUIT_BREAK", new CircuitBreakProxyState());
     }
     
     /**

Reply via email to