You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ni...@apache.org on 2020/08/30 05:52:58 UTC
[shardingsphere] branch master updated: Remove transaction
dependency for kernel module (#7145)
This is an automated email from the ASF dual-hosted git repository.
nicholasjiang 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 5b0d98c Remove transaction dependency for kernel module (#7145)
5b0d98c is described below
commit 5b0d98cb697d4b02fbab09716a55b434244a33e6
Author: Liang Zhang <te...@163.com>
AuthorDate: Sun Aug 30 13:52:37 2020 +0800
Remove transaction dependency for kernel module (#7145)
* Add DataSourceChangeCompletedEvent
* Add TransactionManagerEngineContexts
* Use TransactionManagerEngineContexts
* Rename TransactionContexts
* Use TransactionContexts
* Remove transaction dependency for kernel module
* Add transaction dependency for orche schema module
---
.../raw/jdbc/YamlConfigurationExampleMain.java | 4 +-
.../config/cloud/CloudEncryptConfiguration.java | 2 +-
.../cloud/CloudMasterSlaveConfiguration.java | 2 +-
.../config/cloud/CloudShadowConfiguration.java | 2 +-
...oudShardingDatabasesAndTablesConfiguration.java | 2 +-
.../config/local/LocalEncryptConfiguration.java | 2 +-
.../local/LocalMasterSlaveConfiguration.java | 2 +-
.../config/local/LocalShadowConfiguration.java | 2 +-
...calShardingDatabasesAndTablesConfiguration.java | 2 +-
.../local/LocalShardingDatabasesConfiguration.java | 2 +-
.../LocalShardingMasterSlaveConfiguration.java | 2 +-
.../local/LocalShardingTablesConfiguration.java | 2 +-
.../datasource/DataSourceChangeCompletedEvent.java | 22 +++----
.../shardingsphere-governance-core-schema/pom.xml | 6 ++
.../core/schema/GovernanceSchemaContexts.java | 33 +++++-----
.../transaction/GovernanceTransactionContexts.java | 71 ++++++++++++++++++++++
.../core/schema/GovernanceSchemaContextsTest.java | 37 +++++------
.../core/connection/ShardingSphereConnection.java | 6 +-
.../core/datasource/ShardingSphereDataSource.java | 18 +++++-
.../driver/executor/AbstractBaseExecutorTest.java | 8 ++-
.../driver/executor/StatementExecutorTest.java | 56 ++++++++---------
.../batch/BatchPreparedStatementExecutorTest.java | 6 +-
.../connection/ShardingSphereConnectionTest.java | 17 +++---
.../GovernanceShardingSphereDataSource.java | 41 +++++++------
.../schema/JDBCGovernanceSchemaContextsTest.java | 8 +--
.../shardingsphere-kernel-context/pom.xml | 7 +--
.../kernel/context/SchemaContextsBuilder.java | 11 +---
.../context/impl/StandardSchemaContexts.java | 3 +-
.../kernel/context/runtime/RuntimeContext.java | 3 -
.../jdbc/connection/BackendTransactionManager.java | 7 +--
.../proxy/backend/schema/ProxySchemaContexts.java | 11 +++-
.../TextProtocolBackendHandlerFactoryTest.java | 36 +++++------
.../jdbc/connection/BackendConnectionTest.java | 28 +++++++--
.../connection/BackendTransactionManagerTest.java | 38 +++++-------
.../jdbc/datasource/JDBCBackendDataSourceTest.java | 29 ++++++---
.../ShardingCTLExplainBackendHandlerTest.java | 2 +-
.../org/apache/shardingsphere/proxy/Bootstrap.java | 25 +++++++-
.../auth/PostgreSQLAuthenticationEngineTest.java | 8 ++-
.../shardingsphere-proxy-governance/pom.xml | 2 +-
.../transaction/context/TransactionContexts.java | 32 +++++-----
.../context/impl/StandardTransactionContexts.java | 31 +++++++---
41 files changed, 386 insertions(+), 242 deletions(-)
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExampleMain.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExampleMain.java
index 0ba7bc9..4f7cb4d 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExampleMain.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/YamlConfigurationExampleMain.java
@@ -17,13 +17,13 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc;
+import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
+import org.apache.shardingsphere.driver.orchestration.api.yaml.YamlOrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.core.api.ExampleExecuteTemplate;
import org.apache.shardingsphere.example.core.api.service.ExampleService;
import org.apache.shardingsphere.example.core.jdbc.service.OrderServiceImpl;
import org.apache.shardingsphere.example.type.RegistryCenterType;
import org.apache.shardingsphere.example.type.ShardingType;
-import org.apache.shardingsphere.driver.jdbc.core.datasource.ShardingSphereDataSource;
-import org.apache.shardingsphere.driver.governance.api.yaml.YamlOrchestrationShardingSphereDataSourceFactory;
import javax.sql.DataSource;
import java.io.File;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudEncryptConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudEncryptConfiguration.java
index b243ad1..70f1b30 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudEncryptConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudEncryptConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudMasterSlaveConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudMasterSlaveConfiguration.java
index e698460..e4c0a03 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudMasterSlaveConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudMasterSlaveConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShadowConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShadowConfiguration.java
index fac00e0..9794470 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShadowConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShadowConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShardingDatabasesAndTablesConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShardingDatabasesAndTablesConfiguration.java
index 96eac55..06c786e 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShardingDatabasesAndTablesConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/cloud/CloudShardingDatabasesAndTablesConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.cloud;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java
index ce0b424..d85b56c 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalEncryptConfiguration.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
import com.google.common.collect.ImmutableMap;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptColumnRuleConfiguration;
import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalMasterSlaveConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalMasterSlaveConfiguration.java
index 7e2e555..01de62e 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalMasterSlaveConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalMasterSlaveConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.masterslave.api.config.MasterSlaveRuleConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShadowConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShadowConfiguration.java
index 7758bc6..1a08e04 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShadowConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShadowConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.orchestration.repository.api.config.OrchestrationConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesAndTablesConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesAndTablesConfiguration.java
index 176c7b0..14adcf7 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesAndTablesConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesAndTablesConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesConfiguration.java
index de5988c..2fc7611 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingDatabasesConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingMasterSlaveConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingMasterSlaveConfiguration.java
index 12bc174..9a6f830 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingMasterSlaveConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingMasterSlaveConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
diff --git a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingTablesConfiguration.java b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingTablesConfiguration.java
index 1a0f885..01f39ac 100644
--- a/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingTablesConfiguration.java
+++ b/examples/shardingsphere-jdbc-example/orchestration-example/orchestration-raw-jdbc-example/src/main/java/org/apache/shardingsphere/example/orchestration/raw/jdbc/config/local/LocalShardingTablesConfiguration.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.example.orchestration.raw.jdbc.config.local;
-import org.apache.shardingsphere.driver.governance.api.OrchestrationShardingSphereDataSourceFactory;
+import org.apache.shardingsphere.driver.orchestration.api.OrchestrationShardingSphereDataSourceFactory;
import org.apache.shardingsphere.example.config.ExampleConfiguration;
import org.apache.shardingsphere.example.core.api.DataSourceUtil;
import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/src/main/java/org/apache/shardingsphere/governance/core/common/event/datasource/DataSourceChangeCompletedEvent.java
similarity index 60%
copy from shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
copy to shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/src/main/java/org/apache/shardingsphere/governance/core/common/event/datasource/DataSourceChangeCompletedEvent.java
index 5e849de..b1f20c0 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-common/src/main/java/org/apache/shardingsphere/governance/core/common/event/datasource/DataSourceChangeCompletedEvent.java
@@ -15,26 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.kernel.context.runtime;
+package org.apache.shardingsphere.governance.core.common.event.datasource;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
-import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
-import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.governance.core.common.event.GovernanceEvent;
+import org.apache.shardingsphere.infra.database.type.DatabaseType;
+
+import javax.sql.DataSource;
+import java.util.Map;
/**
- * Runtime context.
+ * Data source change completed event.
*/
@RequiredArgsConstructor
@Getter
-public final class RuntimeContext {
-
- private final CachedDatabaseMetaData cachedDatabaseMetaData;
+public final class DataSourceChangeCompletedEvent implements GovernanceEvent {
- private final ExecutorKernel executorKernel;
+ private final String schemaName;
- private final ShardingSphereSQLParserEngine sqlParserEngine;
+ private final DatabaseType databaseType;
- private final ShardingTransactionManagerEngine transactionManagerEngine;
+ private final Map<String, DataSource> dataSources;
}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/pom.xml b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/pom.xml
index 206552e..0b9a831 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/pom.xml
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/pom.xml
@@ -45,6 +45,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContexts.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContexts.java
index 10ce612..daa0e12 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContexts.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContexts.java
@@ -18,6 +18,19 @@
package org.apache.shardingsphere.governance.core.schema;
import com.google.common.eventbus.Subscribe;
+import org.apache.shardingsphere.governance.core.common.event.auth.AuthenticationChangedEvent;
+import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangeCompletedEvent;
+import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangedEvent;
+import org.apache.shardingsphere.governance.core.common.event.props.PropertiesChangedEvent;
+import org.apache.shardingsphere.governance.core.common.event.rule.RuleConfigurationsChangedEvent;
+import org.apache.shardingsphere.governance.core.common.event.schema.SchemaAddedEvent;
+import org.apache.shardingsphere.governance.core.common.event.schema.SchemaDeletedEvent;
+import org.apache.shardingsphere.governance.core.common.eventbus.GovernanceEventBus;
+import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
+import org.apache.shardingsphere.governance.core.metadata.event.MetaDataChangedEvent;
+import org.apache.shardingsphere.governance.core.registry.event.CircuitStateChangedEvent;
+import org.apache.shardingsphere.governance.core.registry.event.DisabledStateChangedEvent;
+import org.apache.shardingsphere.governance.core.registry.schema.GovernanceSchema;
import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -37,18 +50,6 @@ import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.governance.core.common.event.auth.AuthenticationChangedEvent;
-import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangedEvent;
-import org.apache.shardingsphere.governance.core.common.event.props.PropertiesChangedEvent;
-import org.apache.shardingsphere.governance.core.common.event.rule.RuleConfigurationsChangedEvent;
-import org.apache.shardingsphere.governance.core.common.event.schema.SchemaAddedEvent;
-import org.apache.shardingsphere.governance.core.common.event.schema.SchemaDeletedEvent;
-import org.apache.shardingsphere.governance.core.common.eventbus.GovernanceEventBus;
-import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
-import org.apache.shardingsphere.governance.core.metadata.event.MetaDataChangedEvent;
-import org.apache.shardingsphere.governance.core.registry.event.CircuitStateChangedEvent;
-import org.apache.shardingsphere.governance.core.registry.event.DisabledStateChangedEvent;
-import org.apache.shardingsphere.governance.core.registry.schema.GovernanceSchema;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -156,6 +157,9 @@ public abstract class GovernanceSchemaContexts implements SchemaContexts {
schemas.put(event.getSchemaName(), createAddedSchemaContext(event));
schemaContexts = new StandardSchemaContexts(schemas, schemaContexts.getAuthentication(), schemaContexts.getProps(), schemaContexts.getDatabaseType());
governanceFacade.getMetaDataCenter().persistMetaDataCenterNode(event.getSchemaName(), schemaContexts.getSchemaContexts().get(event.getSchemaName()).getSchema().getMetaData().getSchema());
+ governanceFacade.getMetaDataCenter().persistMetaDataCenterNode(event.getSchemaName(), schemaContexts.getSchemaContexts().get(event.getSchemaName()).getSchema().getMetaData().getSchema());
+ GovernanceEventBus.getInstance().post(
+ new DataSourceChangeCompletedEvent(event.getSchemaName(), schemaContexts.getDatabaseType(), schemas.get(event.getSchemaName()).getSchema().getDataSources()));
}
/**
@@ -239,6 +243,8 @@ public abstract class GovernanceSchemaContexts implements SchemaContexts {
newSchemaContexts.remove(schemaName);
newSchemaContexts.put(schemaName, getChangedSchemaContext(schemaContexts.getSchemaContexts().get(schemaName), event.getDataSourceConfigurations()));
schemaContexts = new StandardSchemaContexts(newSchemaContexts, schemaContexts.getAuthentication(), schemaContexts.getProps(), schemaContexts.getDatabaseType());
+ GovernanceEventBus.getInstance().post(
+ new DataSourceChangeCompletedEvent(event.getSchemaName(), schemaContexts.getDatabaseType(), newSchemaContexts.get(event.getSchemaName()).getSchema().getDataSources()));
}
/**
@@ -282,7 +288,7 @@ public abstract class GovernanceSchemaContexts implements SchemaContexts {
for (Entry<String, SchemaContext> entry : schemaContexts.getSchemaContexts().entrySet()) {
RuntimeContext runtimeContext = entry.getValue().getRuntimeContext();
result.put(entry.getKey(), new SchemaContext(entry.getValue().getName(), entry.getValue().getSchema(), new RuntimeContext(runtimeContext.getCachedDatabaseMetaData(),
- new ExecutorKernel(props.<Integer>getValue(ConfigurationPropertyKey.EXECUTOR_SIZE)), runtimeContext.getSqlParserEngine(), runtimeContext.getTransactionManagerEngine())));
+ new ExecutorKernel(props.<Integer>getValue(ConfigurationPropertyKey.EXECUTOR_SIZE)), runtimeContext.getSqlParserEngine())));
}
return result;
}
@@ -304,7 +310,6 @@ public abstract class GovernanceSchemaContexts implements SchemaContexts {
Map<String, DataSource> modifiedDataSources = getModifiedDataSources(oldSchemaContext, newDataSources);
oldSchemaContext.getSchema().closeDataSources(deletedDataSources);
oldSchemaContext.getSchema().closeDataSources(modifiedDataSources.keySet());
- oldSchemaContext.getRuntimeContext().getTransactionManagerEngine().close();
Map<String, Map<String, DataSource>> dataSourcesMap = Collections.singletonMap(oldSchemaContext.getName(),
getNewDataSources(oldSchemaContext.getSchema().getDataSources(), getAddedDataSources(oldSchemaContext, newDataSources), modifiedDataSources, deletedDataSources));
return new SchemaContextsBuilder(schemaContexts.getDatabaseType(), dataSourcesMap,
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/transaction/GovernanceTransactionContexts.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/transaction/GovernanceTransactionContexts.java
new file mode 100644
index 0000000..15cdef5
--- /dev/null
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/main/java/org/apache/shardingsphere/governance/core/transaction/GovernanceTransactionContexts.java
@@ -0,0 +1,71 @@
+/*
+ * 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.governance.core.transaction;
+
+import com.google.common.eventbus.Subscribe;
+import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangeCompletedEvent;
+import org.apache.shardingsphere.governance.core.common.eventbus.GovernanceEventBus;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+
+import java.util.Map;
+
+/**
+ * Governance transaction contexts.
+ */
+public final class GovernanceTransactionContexts implements TransactionContexts {
+
+ private volatile TransactionContexts contexts;
+
+ public GovernanceTransactionContexts(final TransactionContexts contexts) {
+ this.contexts = contexts;
+ GovernanceEventBus.getInstance().register(this);
+ }
+
+ @Override
+ public Map<String, ShardingTransactionManagerEngine> getEngines() {
+ return contexts.getEngines();
+ }
+
+ @Override
+ public ShardingTransactionManagerEngine getDefaultTransactionManagerEngine() {
+ return contexts.getDefaultTransactionManagerEngine();
+ }
+
+ @Override
+ public void close() throws Exception {
+ contexts.close();
+ }
+
+ /**
+ * Renew transaction manager engine contexts.
+ *
+ * @param event data source change completed event
+ * @throws Exception exception
+ */
+ @Subscribe
+ public synchronized void renew(final DataSourceChangeCompletedEvent event) throws Exception {
+ ShardingTransactionManagerEngine oldEngine = contexts.getEngines().remove(event.getSchemaName());
+ if (null != oldEngine) {
+ oldEngine.close();
+ }
+ ShardingTransactionManagerEngine newEngine = new ShardingTransactionManagerEngine();
+ newEngine.init(event.getDatabaseType(), event.getDataSources());
+ contexts.getEngines().put(event.getSchemaName(), newEngine);
+ }
+}
diff --git a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/test/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContextsTest.java b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/test/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContextsTest.java
index c688bc7..65f55d9 100644
--- a/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/test/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContextsTest.java
+++ b/shardingsphere-governance/shardingsphere-governance-core/shardingsphere-governance-core-schema/src/test/java/org/apache/shardingsphere/governance/core/schema/GovernanceSchemaContextsTest.java
@@ -19,18 +19,6 @@ package org.apache.shardingsphere.governance.core.schema;
import lombok.SneakyThrows;
import org.apache.commons.dbcp2.BasicDataSource;
-import org.apache.shardingsphere.infra.auth.Authentication;
-import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
-import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
-import org.apache.shardingsphere.infra.metadata.schema.RuleSchemaMetaData;
-import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
-import org.apache.shardingsphere.kernel.context.SchemaContext;
-import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
-import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
-import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
import org.apache.shardingsphere.governance.core.common.event.auth.AuthenticationChangedEvent;
import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangedEvent;
import org.apache.shardingsphere.governance.core.common.event.props.PropertiesChangedEvent;
@@ -45,7 +33,18 @@ import org.apache.shardingsphere.governance.core.registry.event.CircuitStateChan
import org.apache.shardingsphere.governance.core.registry.event.DisabledStateChangedEvent;
import org.apache.shardingsphere.governance.core.registry.schema.GovernanceSchema;
import org.apache.shardingsphere.governance.core.schema.fixture.TestGovernanceSchemaContexts;
-import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.infra.auth.Authentication;
+import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
+import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
+import org.apache.shardingsphere.infra.database.type.dialect.H2DatabaseType;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.metadata.schema.RuleSchemaMetaData;
+import org.apache.shardingsphere.infra.rule.event.RuleChangedEvent;
+import org.apache.shardingsphere.kernel.context.SchemaContext;
+import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
+import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
+import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
+import org.apache.shardingsphere.masterslave.rule.MasterSlaveRule;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,12 +61,11 @@ import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -100,7 +98,7 @@ public final class GovernanceSchemaContextsTest {
@Before
public void setUp() {
when(governanceFacade.getRegistryCenter()).thenReturn(registryCenter);
- when(registryCenter.loadDisabledDataSources()).thenReturn(Arrays.asList("schema.ds_1"));
+ when(registryCenter.loadDisabledDataSources()).thenReturn(Collections.singletonList("schema.ds_1"));
when(governanceFacade.getMetaDataCenter()).thenReturn(metaDataCenter);
governanceSchemaContexts = new TestGovernanceSchemaContexts(new StandardSchemaContexts(getSchemaContextMap(),
authentication, configurationProperties, new H2DatabaseType()), governanceFacade);
@@ -111,14 +109,11 @@ public final class GovernanceSchemaContextsTest {
ShardingSphereSchema shardingSphereSchema = mock(ShardingSphereSchema.class);
ShardingSphereMetaData shardingSphereMetaData = mock(ShardingSphereMetaData.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
- ShardingTransactionManagerEngine shardingTransactionManagerEngine = mock(ShardingTransactionManagerEngine.class);
when(schemaContext.getName()).thenReturn("schema");
when(schemaContext.getSchema()).thenReturn(shardingSphereSchema);
when(schemaContext.getRuntimeContext()).thenReturn(runtimeContext);
when(shardingSphereSchema.getMetaData()).thenReturn(shardingSphereMetaData);
- when(shardingSphereSchema.getRules()).thenReturn(Arrays.asList(masterSlaveRule));
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(shardingTransactionManagerEngine);
- doNothing().when(shardingTransactionManagerEngine).close();
+ when(shardingSphereSchema.getRules()).thenReturn(Collections.singletonList(masterSlaveRule));
return Collections.singletonMap("schema", schemaContext);
}
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
index 5c39704..67523a4 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/main/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnection.java
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.driver.jdbc.core.datasource.metadata.ShardingSp
import org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement;
import org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSphereStatement;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.spi.ShardingTransactionManager;
@@ -44,10 +45,11 @@ public final class ShardingSphereConnection extends AbstractConnectionAdapter {
private final ShardingTransactionManager shardingTransactionManager;
- public ShardingSphereConnection(final Map<String, DataSource> dataSourceMap, final SchemaContexts schemaContexts, final TransactionType transactionType) {
+ public ShardingSphereConnection(final Map<String, DataSource> dataSourceMap,
+ final SchemaContexts schemaContexts, final TransactionContexts transactionContexts, final TransactionType transactionType) {
super(dataSourceMap, schemaContexts);
this.transactionType = transactionType;
- shardingTransactionManager = schemaContexts.getDefaultSchemaContext().getRuntimeContext().getTransactionManagerEngine().getTransactionManager(transactionType);
+ shardingTransactionManager = transactionContexts.getDefaultTransactionManagerEngine().getTransactionManager(transactionType);
}
/**
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 c7b9000..fa4f893 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
@@ -29,6 +29,9 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.context.impl.StandardTransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
import javax.sql.DataSource;
@@ -51,14 +54,17 @@ public final class ShardingSphereDataSource extends AbstractUnsupportedOperation
private final SchemaContexts schemaContexts;
+ private final TransactionContexts transactionContexts;
+
@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Setter
private PrintWriter logWriter = new PrintWriter(System.out);
public ShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> configurations, final Properties props) throws SQLException {
DatabaseType databaseType = createDatabaseType(dataSourceMap);
- schemaContexts = new SchemaContextsBuilder(databaseType, Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceMap),
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, configurations), props).build();
+ schemaContexts = new SchemaContextsBuilder(
+ databaseType, Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceMap), Collections.singletonMap(DefaultSchema.LOGIC_NAME, configurations), props).build();
+ transactionContexts = createTransactionContexts(databaseType, dataSourceMap);
}
private DatabaseType createDatabaseType(final Map<String, DataSource> dataSourceMap) throws SQLException {
@@ -80,6 +86,12 @@ public final class ShardingSphereDataSource extends AbstractUnsupportedOperation
}
}
+ private TransactionContexts createTransactionContexts(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap) {
+ ShardingTransactionManagerEngine engine = new ShardingTransactionManagerEngine();
+ engine.init(databaseType, dataSourceMap);
+ return new StandardTransactionContexts(Collections.singletonMap(DefaultSchema.LOGIC_NAME, engine));
+ }
+
@Override
public Logger getParentLogger() {
return Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);
@@ -87,7 +99,7 @@ public final class ShardingSphereDataSource extends AbstractUnsupportedOperation
@Override
public ShardingSphereConnection getConnection() {
- return new ShardingSphereConnection(getDataSourceMap(), schemaContexts, TransactionTypeHolder.get());
+ return new ShardingSphereConnection(getDataSourceMap(), schemaContexts, transactionContexts, TransactionTypeHolder.get());
}
@Override
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java
index ebd18c4..1d63274 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/AbstractBaseExecutorTest.java
@@ -34,6 +34,7 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import org.apache.shardingsphere.sql.parser.binder.segment.table.TablesContext;
import org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.After;
import org.junit.Before;
@@ -80,13 +81,14 @@ public abstract class AbstractBaseExecutorTest {
when(schemaContexts.getDatabaseType()).thenReturn(DatabaseTypes.getActualDatabaseType("H2"));
ShardingRule shardingRule = getShardingRule();
when(schema.getRules()).thenReturn(Collections.singletonList(shardingRule));
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(new ShardingTransactionManagerEngine());
+ TransactionContexts transactionContexts = mock(TransactionContexts.class);
+ when(transactionContexts.getDefaultTransactionManagerEngine()).thenReturn(new ShardingTransactionManagerEngine());
DataSource dataSource = mock(DataSource.class);
when(dataSource.getConnection()).thenReturn(mock(Connection.class));
Map<String, DataSource> dataSourceSourceMap = new LinkedHashMap<>(2, 1);
dataSourceSourceMap.put("ds_0", dataSource);
dataSourceSourceMap.put("ds_1", dataSource);
- connection = new ShardingSphereConnection(dataSourceSourceMap, schemaContexts, TransactionType.LOCAL);
+ connection = new ShardingSphereConnection(dataSourceSourceMap, schemaContexts, transactionContexts, TransactionType.LOCAL);
}
private ShardingRule getShardingRule() {
@@ -95,7 +97,7 @@ public abstract class AbstractBaseExecutorTest {
when(result.isNeedAccumulate(any())).thenReturn(true);
return result;
}
-
+
protected final SQLStatementContext<?> getSQLStatementContext() {
SQLStatementContext<?> result = mock(SQLStatementContext.class);
TablesContext tablesContext = mock(TablesContext.class);
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
index 23e2da7..acc1b72 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/StatementExecutorTest.java
@@ -71,7 +71,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertThat(actual.executeUpdate(Collections.emptyList(), getSQLStatementContext()), is(0));
assertThat(actual.executeQuery(Collections.emptyList()).size(), is(0));
}
-
+
@Test
public void assertExecuteQueryForSingleStatementSuccess() throws SQLException {
Statement statement = getStatement();
@@ -88,7 +88,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertThat(actual.executeQuery(getExecuteGroups(Collections.singletonList(statement), true)).iterator().next().getValue(1, String.class), is("value"));
verify(statement).executeQuery(DQL_SQL);
}
-
+
@Test
public void assertExecuteQueryForMultipleStatementsSuccess() throws SQLException {
Statement statement1 = getStatement();
@@ -113,21 +113,21 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
verify(statement1).executeQuery(DQL_SQL);
verify(statement2).executeQuery(DQL_SQL);
}
-
+
@Test
public void assertExecuteQueryForSingleStatementFailure() throws SQLException {
Statement statement = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement.executeQuery(DQL_SQL)).thenThrow(exp);
assertThat(actual.executeQuery(getExecuteGroups(Collections.singletonList(statement), true)), is(Collections.singletonList((QueryResult) null)));
verify(statement).executeQuery(DQL_SQL);
}
-
+
@Test
public void assertExecuteQueryForMultipleStatementsFailure() throws SQLException {
Statement statement1 = getStatement();
Statement statement2 = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement1.executeQuery(DQL_SQL)).thenThrow(exp);
when(statement2.executeQuery(DQL_SQL)).thenThrow(exp);
List<QueryResult> actualResultSets = actual.executeQuery(getExecuteGroups(Arrays.asList(statement1, statement2), true));
@@ -135,7 +135,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
verify(statement1).executeQuery(DQL_SQL);
verify(statement2).executeQuery(DQL_SQL);
}
-
+
@Test
public void assertExecuteUpdateForSingleStatementSuccess() throws SQLException {
Statement statement = getStatement();
@@ -143,7 +143,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext()), is(10));
verify(statement).executeUpdate(DML_SQL);
}
-
+
@Test
public void assertExecuteUpdateForMultipleStatementsSuccess() throws SQLException {
Statement statement1 = getStatement();
@@ -154,28 +154,28 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
verify(statement1).executeUpdate(DML_SQL);
verify(statement2).executeUpdate(DML_SQL);
}
-
+
@Test
public void assertExecuteUpdateForSingleStatementFailure() throws SQLException {
Statement statement = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement.executeUpdate(DML_SQL)).thenThrow(exp);
assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext()), is(0));
verify(statement).executeUpdate(DML_SQL);
}
-
+
@Test
public void assertExecuteUpdateForMultipleStatementsFailure() throws SQLException {
Statement statement1 = getStatement();
Statement statement2 = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement1.executeUpdate(DML_SQL)).thenThrow(exp);
when(statement2.executeUpdate(DML_SQL)).thenThrow(exp);
assertThat(actual.executeUpdate(getExecuteGroups(Arrays.asList(statement1, statement2), false), getSQLStatementContext()), is(0));
verify(statement1).executeUpdate(DML_SQL);
verify(statement2).executeUpdate(DML_SQL);
}
-
+
@Test
public void assertExecuteUpdateWithAutoGeneratedKeys() throws SQLException {
Statement statement = getStatement();
@@ -183,7 +183,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext(), Statement.NO_GENERATED_KEYS), is(10));
verify(statement).executeUpdate(DML_SQL, Statement.NO_GENERATED_KEYS);
}
-
+
@Test
public void assertExecuteUpdateWithColumnIndexes() throws SQLException {
Statement statement = getStatement();
@@ -191,7 +191,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext(), new int[] {1}), is(10));
verify(statement).executeUpdate(DML_SQL, new int[] {1});
}
-
+
private Statement getStatement() throws SQLException {
Statement statement = mock(Statement.class);
Connection connection = mock(Connection.class);
@@ -201,7 +201,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
when(statement.getConnection()).thenReturn(connection);
return statement;
}
-
+
@Test
public void assertExecuteUpdateWithColumnNames() throws SQLException {
Statement statement = getStatement();
@@ -209,7 +209,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertThat(actual.executeUpdate(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext(), new String[] {"col"}), is(10));
verify(statement).executeUpdate(DML_SQL, new String[] {"col"});
}
-
+
@Test
public void assertExecuteForSingleStatementSuccessWithDML() throws SQLException {
Statement statement = getStatement();
@@ -217,7 +217,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext()));
verify(statement).execute(DML_SQL);
}
-
+
@Test
public void assertExecuteForMultipleStatementsSuccessWithDML() throws SQLException {
Statement statement1 = getStatement();
@@ -228,28 +228,28 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
verify(statement1).execute(DML_SQL);
verify(statement2).execute(DML_SQL);
}
-
+
@Test
public void assertExecuteForSingleStatementFailureWithDML() throws SQLException {
Statement statement = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement.execute(DML_SQL)).thenThrow(exp);
assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext()));
verify(statement).execute(DML_SQL);
}
-
+
@Test
public void assertExecuteForMultipleStatementsFailureWithDML() throws SQLException {
Statement statement1 = getStatement();
Statement statement2 = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement1.execute(DML_SQL)).thenThrow(exp);
when(statement2.execute(DML_SQL)).thenThrow(exp);
assertFalse(actual.execute(getExecuteGroups(Arrays.asList(statement1, statement2), false), getSQLStatementContext()));
verify(statement1).execute(DML_SQL);
verify(statement2).execute(DML_SQL);
}
-
+
@Test
public void assertExecuteForSingleStatementWithDQL() throws SQLException {
Statement statement = getStatement();
@@ -257,7 +257,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertTrue(actual.execute(getExecuteGroups(Collections.singletonList(statement), true), getSQLStatementContext()));
verify(statement).execute(DQL_SQL);
}
-
+
@Test
public void assertExecuteForMultipleStatements() throws SQLException {
Statement statement1 = getStatement();
@@ -268,7 +268,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
verify(statement1).execute(DQL_SQL);
verify(statement2).execute(DQL_SQL);
}
-
+
@Test
public void assertExecuteWithAutoGeneratedKeys() throws SQLException {
Statement statement = getStatement();
@@ -284,7 +284,7 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext(), new int[] {1}));
verify(statement).execute(DML_SQL, new int[] {1});
}
-
+
@Test
public void assertExecuteWithColumnNames() throws SQLException {
Statement statement = getStatement();
@@ -292,12 +292,12 @@ public final class StatementExecutorTest extends AbstractBaseExecutorTest {
assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext(), new String[] {"col"}));
verify(statement).execute(DML_SQL, new String[] {"col"});
}
-
+
@Test
public void assertOverallExceptionFailure() throws SQLException {
ExecutorExceptionHandler.setExceptionThrown(true);
Statement statement = getStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(statement.execute(DML_SQL)).thenThrow(exp);
try {
assertFalse(actual.execute(getExecuteGroups(Collections.singletonList(statement), false), getSQLStatementContext()));
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
index 9b7498b..5946936 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/executor/batch/BatchPreparedStatementExecutorTest.java
@@ -55,7 +55,7 @@ public final class BatchPreparedStatementExecutorTest extends AbstractBaseExecut
private BatchPreparedStatementExecutor actual;
@Mock
- private SQLStatementContext sqlStatementContext;
+ private SQLStatementContext<?> sqlStatementContext;
@Override
public void setUp() throws SQLException {
@@ -106,7 +106,7 @@ public final class BatchPreparedStatementExecutorTest extends AbstractBaseExecut
@Test
public void assertExecuteBatchForSinglePreparedStatementFailure() throws SQLException {
PreparedStatement preparedStatement = getPreparedStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(preparedStatement.executeBatch()).thenThrow(exp);
setExecuteGroups(Collections.singletonList(preparedStatement));
assertThat(actual.executeBatch(sqlStatementContext), is(new int[] {0, 0}));
@@ -117,7 +117,7 @@ public final class BatchPreparedStatementExecutorTest extends AbstractBaseExecut
public void assertExecuteBatchForMultiplePreparedStatementsFailure() throws SQLException {
PreparedStatement preparedStatement1 = getPreparedStatement();
PreparedStatement preparedStatement2 = getPreparedStatement();
- SQLException exp = new SQLException();
+ SQLException exp = new SQLException("");
when(preparedStatement1.executeBatch()).thenThrow(exp);
when(preparedStatement2.executeBatch()).thenThrow(exp);
setExecuteGroups(Arrays.asList(preparedStatement1, preparedStatement2));
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
index b030276..0475f5b 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-core/src/test/java/org/apache/shardingsphere/driver/jdbc/core/connection/ShardingSphereConnectionTest.java
@@ -28,6 +28,7 @@ import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionOperationType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
@@ -58,6 +59,8 @@ public final class ShardingSphereConnectionTest {
private SchemaContexts schemaContexts;
+ private TransactionContexts transactionContexts;
+
@BeforeClass
public static void init() throws SQLException {
DataSource masterDataSource = mockDataSource();
@@ -83,10 +86,11 @@ public final class ShardingSphereConnectionTest {
when(schemaContext.getSchema()).thenReturn(schema);
when(schemaContexts.getDatabaseType()).thenReturn(DatabaseTypes.getActualDatabaseType("H2"));
when(schemaContext.getRuntimeContext()).thenReturn(runtimeContext);
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(new ShardingTransactionManagerEngine());
+ transactionContexts = mock(TransactionContexts.class);
+ when(transactionContexts.getDefaultTransactionManagerEngine()).thenReturn(new ShardingTransactionManagerEngine());
ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
shardingRuleConfig.getTables().add(new ShardingTableRuleConfiguration("test"));
- connection = new ShardingSphereConnection(dataSourceMap, schemaContexts, TransactionType.LOCAL);
+ connection = new ShardingSphereConnection(dataSourceMap, schemaContexts, transactionContexts, TransactionType.LOCAL);
}
@After
@@ -112,7 +116,7 @@ public final class ShardingSphereConnectionTest {
@Test
public void assertXATransactionOperation() throws SQLException {
- connection = new ShardingSphereConnection(dataSourceMap, schemaContexts, TransactionType.XA);
+ connection = new ShardingSphereConnection(dataSourceMap, schemaContexts, transactionContexts, TransactionType.XA);
connection.setAutoCommit(false);
assertTrue(XAShardingTransactionManagerFixture.getINVOCATIONS().contains(TransactionOperationType.BEGIN));
connection.commit();
@@ -123,7 +127,7 @@ public final class ShardingSphereConnectionTest {
@Test
public void assertBASETransactionOperation() throws SQLException {
- connection = new ShardingSphereConnection(dataSourceMap, schemaContexts, TransactionType.BASE);
+ connection = new ShardingSphereConnection(dataSourceMap, schemaContexts, transactionContexts, TransactionType.BASE);
connection.setAutoCommit(false);
assertTrue(BASEShardingTransactionManagerFixture.getINVOCATIONS().contains(TransactionOperationType.BEGIN));
connection.commit();
@@ -131,21 +135,18 @@ public final class ShardingSphereConnectionTest {
connection.rollback();
assertTrue(BASEShardingTransactionManagerFixture.getINVOCATIONS().contains(TransactionOperationType.ROLLBACK));
}
-
+
@Test
public void assertIsValid() throws SQLException {
Connection masterConnection = mock(Connection.class);
Connection upSlaveConnection = mock(Connection.class);
Connection downSlaveConnection = mock(Connection.class);
-
when(masterConnection.isValid(anyInt())).thenReturn(true);
when(upSlaveConnection.isValid(anyInt())).thenReturn(true);
when(downSlaveConnection.isValid(anyInt())).thenReturn(false);
-
connection.getCachedConnections().put("test_master", masterConnection);
connection.getCachedConnections().put("test_slave_up", upSlaveConnection);
assertTrue(connection.isValid(0));
-
connection.getCachedConnections().put("test_slave_down", downSlaveConnection);
assertFalse(connection.isValid(0));
}
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 c6ae176..8705702 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
@@ -20,11 +20,14 @@ package org.apache.shardingsphere.driver.governance.internal.datasource;
import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
-import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
-import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
import org.apache.shardingsphere.driver.governance.internal.circuit.datasource.CircuitBreakerDataSource;
import org.apache.shardingsphere.driver.governance.internal.schema.JDBCGovernanceSchemaContexts;
import org.apache.shardingsphere.driver.governance.internal.util.DataSourceConverter;
+import org.apache.shardingsphere.driver.jdbc.core.connection.ShardingSphereConnection;
+import org.apache.shardingsphere.driver.jdbc.unsupported.AbstractUnsupportedOperationDataSource;
+import org.apache.shardingsphere.governance.core.config.ConfigCenter;
+import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
+import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.RuleConfiguration;
@@ -33,9 +36,9 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
-import org.apache.shardingsphere.governance.core.config.ConfigCenter;
-import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
-import org.apache.shardingsphere.governance.repository.api.config.GovernanceConfiguration;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.context.impl.StandardTransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionTypeHolder;
import javax.sql.DataSource;
@@ -61,15 +64,19 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
private final SchemaContexts schemaContexts;
+ private final TransactionContexts transactionContexts;
+
public GovernanceShardingSphereDataSource(final GovernanceConfiguration governanceConfig) throws SQLException {
GovernanceFacade governanceFacade = createGovernanceFacade(governanceConfig);
schemaContexts = new JDBCGovernanceSchemaContexts(createSchemaContexts(governanceFacade), governanceFacade);
+ transactionContexts = createTransactionContexts(schemaContexts.getDatabaseType(), schemaContexts.getDefaultSchemaContext().getSchema().getDataSources());
}
public GovernanceShardingSphereDataSource(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
final Properties props, final GovernanceConfiguration governanceConfig) throws SQLException {
GovernanceFacade governanceFacade = createGovernanceFacade(governanceConfig);
schemaContexts = new JDBCGovernanceSchemaContexts(createSchemaContexts(dataSourceMap, ruleConfigurations, props), governanceFacade);
+ transactionContexts = createTransactionContexts(schemaContexts.getDatabaseType(), schemaContexts.getDefaultSchemaContext().getSchema().getDataSources());
uploadLocalConfiguration(governanceFacade);
}
@@ -85,19 +92,15 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
Map<String, DataSourceConfiguration> dataSourceConfigs = configCenter.loadDataSourceConfigurations(DefaultSchema.LOGIC_NAME);
Collection<RuleConfiguration> ruleConfigurations = configCenter.loadRuleConfigurations(DefaultSchema.LOGIC_NAME);
Map<String, DataSource> dataSourceMap = DataSourceConverter.getDataSourceMap(dataSourceConfigs);
- SchemaContextsBuilder schemaContextsBuilder = new SchemaContextsBuilder(createDatabaseType(dataSourceMap),
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceMap),
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, ruleConfigurations),
- new Authentication(), configCenter.loadProperties());
+ SchemaContextsBuilder schemaContextsBuilder = new SchemaContextsBuilder(createDatabaseType(dataSourceMap), Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceMap),
+ Collections.singletonMap(DefaultSchema.LOGIC_NAME, ruleConfigurations), new Authentication(), configCenter.loadProperties());
return schemaContextsBuilder.build();
}
private SchemaContexts createSchemaContexts(final Map<String, DataSource> dataSourceMap, final Collection<RuleConfiguration> ruleConfigurations,
final Properties props) throws SQLException {
- SchemaContextsBuilder schemaContextsBuilder = new SchemaContextsBuilder(createDatabaseType(dataSourceMap),
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceMap),
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, ruleConfigurations),
- new Authentication(), props);
+ SchemaContextsBuilder schemaContextsBuilder = new SchemaContextsBuilder(createDatabaseType(dataSourceMap), Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceMap),
+ Collections.singletonMap(DefaultSchema.LOGIC_NAME, ruleConfigurations), new Authentication(), props);
return schemaContextsBuilder.build();
}
@@ -117,19 +120,23 @@ public final class GovernanceShardingSphereDataSource extends AbstractUnsupporte
}
}
+ private TransactionContexts createTransactionContexts(final DatabaseType databaseType, final Map<String, DataSource> dataSourceMap) {
+ ShardingTransactionManagerEngine engine = new ShardingTransactionManagerEngine();
+ engine.init(databaseType, dataSourceMap);
+ return new StandardTransactionContexts(Collections.singletonMap(DefaultSchema.LOGIC_NAME, engine));
+ }
+
private void uploadLocalConfiguration(final GovernanceFacade governanceFacade) {
Map<String, DataSourceConfiguration> dataSourceConfigs = DataSourceConverter.getDataSourceConfigurationMap(schemaContexts.getDefaultSchemaContext().getSchema().getDataSources());
Collection<RuleConfiguration> ruleConfigurations = schemaContexts.getDefaultSchemaContext().getSchema().getConfigurations();
Properties props = schemaContexts.getProps().getProps();
- governanceFacade.onlineInstance(
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceConfigs),
- Collections.singletonMap(DefaultSchema.LOGIC_NAME, ruleConfigurations), null, props);
+ governanceFacade.onlineInstance(Collections.singletonMap(DefaultSchema.LOGIC_NAME, dataSourceConfigs), Collections.singletonMap(DefaultSchema.LOGIC_NAME, ruleConfigurations), null, props);
}
@Override
public Connection getConnection() {
return schemaContexts.isCircuitBreak() ? new CircuitBreakerDataSource().getConnection()
- : new ShardingSphereConnection(getDataSourceMap(), schemaContexts, TransactionTypeHolder.get());
+ : new ShardingSphereConnection(getDataSourceMap(), schemaContexts, transactionContexts, TransactionTypeHolder.get());
}
@Override
diff --git a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/schema/JDBCGovernanceSchemaContextsTest.java b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/schema/JDBCGovernanceSchemaContextsTest.java
index d4ccd4a..54e269d 100644
--- a/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/schema/JDBCGovernanceSchemaContextsTest.java
+++ b/shardingsphere-jdbc/shardingsphere-jdbc-governance/src/test/java/org/apache/shardingsphere/driver/governance/internal/schema/JDBCGovernanceSchemaContextsTest.java
@@ -20,6 +20,9 @@ package org.apache.shardingsphere.driver.governance.internal.schema;
import org.apache.commons.collections4.map.LinkedMap;
import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.shardingsphere.driver.governance.internal.util.DataSourceConverter;
+import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangedEvent;
+import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
+import org.apache.shardingsphere.governance.core.registry.RegistryCenter;
import org.apache.shardingsphere.infra.auth.Authentication;
import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
@@ -29,10 +32,6 @@ import org.apache.shardingsphere.kernel.context.SchemaContext;
import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
-import org.apache.shardingsphere.governance.core.common.event.datasource.DataSourceChangedEvent;
-import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
-import org.apache.shardingsphere.governance.core.registry.RegistryCenter;
-import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -70,7 +69,6 @@ public final class JDBCGovernanceSchemaContextsTest {
ShardingSphereSchema schema = mock(ShardingSphereSchema.class);
when(schema.getDataSources()).thenReturn(getDataSources());
RuntimeContext runtimeContext = mock(RuntimeContext.class);
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(new ShardingTransactionManagerEngine());
SchemaContext result = new SchemaContext(DefaultSchema.LOGIC_NAME, schema, runtimeContext);
return Collections.singletonMap(DefaultSchema.LOGIC_NAME, result);
}
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/pom.xml b/shardingsphere-kernel/shardingsphere-kernel-context/pom.xml
index 7c2554a..7e7330f 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/pom.xml
+++ b/shardingsphere-kernel/shardingsphere-kernel-context/pom.xml
@@ -44,12 +44,7 @@
<artifactId>shardingsphere-rdl-parser-engine</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-transaction-core</artifactId>
- <version>${project.version}</version>
- </dependency>
-
+
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test</artifactId>
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/SchemaContextsBuilder.java b/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/SchemaContextsBuilder.java
index e025727..7f6ff79 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/SchemaContextsBuilder.java
+++ b/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/SchemaContextsBuilder.java
@@ -37,7 +37,6 @@ import org.apache.shardingsphere.kernel.context.runtime.CachedDatabaseMetaData;
import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngineFactory;
-import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
import javax.sql.DataSource;
import java.sql.Connection;
@@ -99,8 +98,8 @@ public final class SchemaContextsBuilder {
private SchemaContext createSchemaContext(final String schemaName) throws SQLException {
Map<String, DataSource> dataSources = this.dataSources.get(schemaName);
- RuntimeContext runtimeContext = new RuntimeContext(createCachedDatabaseMetaData(dataSources).orElse(null),
- executorKernel, ShardingSphereSQLParserEngineFactory.getSQLParserEngine(DatabaseTypes.getTrunkDatabaseTypeName(databaseType)), createShardingTransactionManagerEngine(dataSources));
+ RuntimeContext runtimeContext = new RuntimeContext(createCachedDatabaseMetaData(dataSources).orElse(null),
+ executorKernel, ShardingSphereSQLParserEngineFactory.getSQLParserEngine(DatabaseTypes.getTrunkDatabaseTypeName(databaseType)));
return new SchemaContext(schemaName, createShardingSphereSchema(schemaName), runtimeContext);
}
@@ -113,12 +112,6 @@ public final class SchemaContextsBuilder {
}
}
- private ShardingTransactionManagerEngine createShardingTransactionManagerEngine(final Map<String, DataSource> dataSources) {
- ShardingTransactionManagerEngine result = new ShardingTransactionManagerEngine();
- result.init(databaseType, dataSources);
- return result;
- }
-
private ShardingSphereSchema createShardingSphereSchema(final String schemaName) throws SQLException {
Map<String, DataSource> dataSources = this.dataSources.get(schemaName);
Collection<RuleConfiguration> ruleConfigs = this.ruleConfigs.get(schemaName);
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/impl/StandardSchemaContexts.java b/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/impl/StandardSchemaContexts.java
index 9cce691..083fcb5 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/impl/StandardSchemaContexts.java
+++ b/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/impl/StandardSchemaContexts.java
@@ -53,8 +53,7 @@ public final class StandardSchemaContexts implements SchemaContexts {
this(new HashMap<>(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType(), false);
}
- public StandardSchemaContexts(final Map<String, SchemaContext> schemaContexts,
- final Authentication authentication, final ConfigurationProperties props, final DatabaseType databaseType) {
+ public StandardSchemaContexts(final Map<String, SchemaContext> schemaContexts, final Authentication authentication, final ConfigurationProperties props, final DatabaseType databaseType) {
this(schemaContexts, authentication, props, databaseType, false);
}
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java b/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
index 5e849de..a43783f 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
+++ b/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
@@ -21,7 +21,6 @@ import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
-import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
/**
* Runtime context.
@@ -35,6 +34,4 @@ public final class RuntimeContext {
private final ExecutorKernel executorKernel;
private final ShardingSphereSQLParserEngine sqlParserEngine;
-
- private final ShardingTransactionManagerEngine transactionManagerEngine;
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java
index ff83002..dac2c9e 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManager.java
@@ -17,8 +17,8 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.connection;
-import org.apache.shardingsphere.kernel.context.SchemaContext;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.spi.ShardingTransactionManager;
@@ -41,9 +41,8 @@ public final class BackendTransactionManager implements TransactionManager {
connection = backendConnection;
transactionType = connection.getTransactionType();
localTransactionManager = new LocalTransactionManager(backendConnection);
- SchemaContext context = ProxySchemaContexts.getInstance().getSchema(connection.getSchema());
- shardingTransactionManager = null == context ? null
- : context.getRuntimeContext().getTransactionManagerEngine().getTransactionManager(transactionType);
+ ShardingTransactionManagerEngine engine = ProxySchemaContexts.getInstance().getTransactionContexts().getEngines().get(connection.getSchema());
+ shardingTransactionManager = null == engine ? null : engine.getTransactionManager(transactionType);
}
@Override
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxySchemaContexts.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxySchemaContexts.java
index c2a93df..77dc19f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxySchemaContexts.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/schema/ProxySchemaContexts.java
@@ -25,6 +25,8 @@ import org.apache.shardingsphere.kernel.context.SchemaContext;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
import org.apache.shardingsphere.proxy.backend.BackendDataSource;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.context.impl.StandardTransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.spi.ShardingTransactionManager;
@@ -49,6 +51,8 @@ public final class ProxySchemaContexts {
private SchemaContexts schemaContexts = new StandardSchemaContexts();
+ private TransactionContexts transactionContexts = new StandardTransactionContexts();
+
private final JDBCBackendDataSource backendDataSource = new JDBCBackendDataSource();
private ProxySchemaContexts() { }
@@ -66,9 +70,11 @@ public final class ProxySchemaContexts {
* Initialize proxy schema contexts.
*
* @param schemaContexts schema contexts
+ * @param transactionContexts transaction manager engine contexts
*/
- public void init(final SchemaContexts schemaContexts) {
+ public void init(final SchemaContexts schemaContexts, final TransactionContexts transactionContexts) {
this.schemaContexts = schemaContexts;
+ this.transactionContexts = transactionContexts;
}
/**
@@ -186,8 +192,7 @@ public final class ProxySchemaContexts {
}
private Connection createConnection(final String schemaName, final String dataSourceName, final DataSource dataSource, final TransactionType transactionType) throws SQLException {
- ShardingTransactionManager shardingTransactionManager =
- schemaContexts.getSchemaContexts().get(schemaName).getRuntimeContext().getTransactionManagerEngine().getTransactionManager(transactionType);
+ ShardingTransactionManager shardingTransactionManager = transactionContexts.getEngines().get(schemaName).getTransactionManager(transactionType);
return isInShardingTransaction(shardingTransactionManager) ? shardingTransactionManager.getConnection(dataSourceName) : dataSource.getConnection();
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
index 4eb3441..4668642 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/TextProtocolBackendHandlerFactoryTest.java
@@ -18,14 +18,8 @@
package org.apache.shardingsphere.proxy.backend;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.auth.Authentication;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
import org.apache.shardingsphere.infra.database.type.DatabaseType;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.kernel.context.SchemaContext;
-import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
-import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.ConnectionStateHandler;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
@@ -41,6 +35,7 @@ import org.apache.shardingsphere.proxy.backend.text.sctl.show.ShardingCTLShowBac
import org.apache.shardingsphere.proxy.backend.text.transaction.SkipBackendHandler;
import org.apache.shardingsphere.proxy.backend.text.transaction.TransactionBackendHandler;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.Before;
import org.junit.Ignore;
@@ -50,12 +45,10 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -68,22 +61,23 @@ public final class TextProtocolBackendHandlerFactoryTest {
private BackendConnection backendConnection;
@Before
- @SneakyThrows(ReflectiveOperationException.class)
public void setUp() {
when(backendConnection.getTransactionType()).thenReturn(TransactionType.LOCAL);
- Field schemaContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
- schemaContexts.setAccessible(true);
- schemaContexts.set(ProxySchemaContexts.getInstance(),
- new StandardSchemaContexts(getSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType()));
+ setTransactionContexts();
when(backendConnection.getSchema()).thenReturn("schema");
}
- private Map<String, SchemaContext> getSchemaContextMap() {
- SchemaContext result = mock(SchemaContext.class);
- RuntimeContext runtimeContext = mock(RuntimeContext.class);
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(mock(ShardingTransactionManagerEngine.class));
- when(result.getRuntimeContext()).thenReturn(runtimeContext);
- return Collections.singletonMap("schema", result);
+ @SneakyThrows(ReflectiveOperationException.class)
+ private void setTransactionContexts() {
+ Field transactionContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField("transactionContexts");
+ transactionContexts.setAccessible(true);
+ transactionContexts.set(ProxySchemaContexts.getInstance(), createSchemaContext());
+ }
+
+ private TransactionContexts createSchemaContext() {
+ TransactionContexts result = mock(TransactionContexts.class, RETURNS_DEEP_STUBS);
+ when(result.getEngines().get("schema")).thenReturn(new ShardingTransactionManagerEngine());
+ return result;
}
@Test
@@ -92,7 +86,7 @@ public final class TextProtocolBackendHandlerFactoryTest {
TextProtocolBackendHandler actual = TextProtocolBackendHandlerFactory.newInstance(databaseType, sql, backendConnection);
assertThat(actual, instanceOf(ShardingCTLSetBackendHandler.class));
}
-
+
@Test
public void assertNewInstanceSCTLWithComment() {
String sql = "/*ApplicationName=DataGrip 2018.1.4*/ sctl:show cached_connections;";
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
index d4a0e59..2ec3895 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendConnectionTest.java
@@ -30,6 +30,7 @@ import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts.JDBCBackendDataSource;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.junit.After;
import org.junit.Before;
@@ -58,6 +59,7 @@ import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@@ -73,26 +75,26 @@ public final class BackendConnectionTest {
private final BackendConnection backendConnection = new BackendConnection(TransactionType.LOCAL);
@Before
- @SneakyThrows(ReflectiveOperationException.class)
public void setUp() {
setSchemaContexts();
+ setTransactionContexts();
setBackendDataSource();
backendConnection.setCurrentSchema("schema_0");
}
- private void setSchemaContexts() throws NoSuchFieldException, IllegalAccessException {
+ @SneakyThrows(ReflectiveOperationException.class)
+ private void setSchemaContexts() {
Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
field.setAccessible(true);
field.set(ProxySchemaContexts.getInstance(),
- new StandardSchemaContexts(getSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType()));
+ new StandardSchemaContexts(createSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType()));
}
- private Map<String, SchemaContext> getSchemaContextMap() {
+ private Map<String, SchemaContext> createSchemaContextMap() {
Map<String, SchemaContext> result = new HashMap<>(10);
for (int i = 0; i < 10; i++) {
String name = "schema_" + i;
RuntimeContext runtimeContext = mock(RuntimeContext.class);
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(mock(ShardingTransactionManagerEngine.class));
SchemaContext schemaContext = new SchemaContext(name, mock(ShardingSphereSchema.class), runtimeContext);
result.put(name, schemaContext);
}
@@ -100,6 +102,22 @@ public final class BackendConnectionTest {
}
@SneakyThrows(ReflectiveOperationException.class)
+ private void setTransactionContexts() {
+ Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("transactionContexts");
+ field.setAccessible(true);
+ field.set(ProxySchemaContexts.getInstance(), createTransactionContexts());
+ }
+
+ private TransactionContexts createTransactionContexts() {
+ TransactionContexts result = mock(TransactionContexts.class, RETURNS_DEEP_STUBS);
+ for (int i = 0; i < 10; i++) {
+ String name = "schema_" + i;
+ when(result.getEngines().get(name)).thenReturn(new ShardingTransactionManagerEngine());
+ }
+ return result;
+ }
+
+ @SneakyThrows(ReflectiveOperationException.class)
private void setBackendDataSource() {
Field field = ProxySchemaContexts.getInstance().getClass().getDeclaredField("backendDataSource");
field.setAccessible(true);
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManagerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManagerTest.java
index 6e32944..3564e95 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManagerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/connection/BackendTransactionManagerTest.java
@@ -18,14 +18,9 @@
package org.apache.shardingsphere.proxy.backend.communication.jdbc.connection;
import lombok.SneakyThrows;
-import org.apache.shardingsphere.infra.auth.Authentication;
-import org.apache.shardingsphere.infra.config.properties.ConfigurationProperties;
-import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
-import org.apache.shardingsphere.kernel.context.SchemaContext;
-import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
-import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.apache.shardingsphere.transaction.spi.ShardingTransactionManager;
import org.junit.Before;
@@ -36,10 +31,8 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.lang.reflect.Field;
import java.sql.SQLException;
-import java.util.Collections;
-import java.util.Map;
-import java.util.Properties;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -63,24 +56,25 @@ public final class BackendTransactionManagerTest {
private BackendTransactionManager backendTransactionManager;
@Before
- @SneakyThrows(ReflectiveOperationException.class)
public void setUp() {
- Field schemaContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
- schemaContexts.setAccessible(true);
- schemaContexts.set(ProxySchemaContexts.getInstance(),
- new StandardSchemaContexts(getSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType()));
+ setTransactionContexts();
when(backendConnection.getSchema()).thenReturn("schema");
when(backendConnection.getStateHandler()).thenReturn(stateHandler);
}
- private Map<String, SchemaContext> getSchemaContextMap() {
- SchemaContext result = mock(SchemaContext.class);
- RuntimeContext runtimeContext = mock(RuntimeContext.class);
- ShardingTransactionManagerEngine shardingTransactionManagerEngine = mock(ShardingTransactionManagerEngine.class);
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(shardingTransactionManagerEngine);
- when(shardingTransactionManagerEngine.getTransactionManager(TransactionType.XA)).thenReturn(shardingTransactionManager);
- when(result.getRuntimeContext()).thenReturn(runtimeContext);
- return Collections.singletonMap("schema", result);
+ @SneakyThrows(ReflectiveOperationException.class)
+ private void setTransactionContexts() {
+ Field transactionContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField("transactionContexts");
+ transactionContexts.setAccessible(true);
+ transactionContexts.set(ProxySchemaContexts.getInstance(), getTransactionContexts());
+ }
+
+ private TransactionContexts getTransactionContexts() {
+ TransactionContexts result = mock(TransactionContexts.class, RETURNS_DEEP_STUBS);
+ ShardingTransactionManagerEngine transactionManagerEngine = mock(ShardingTransactionManagerEngine.class);
+ when(result.getEngines().get("schema")).thenReturn(transactionManagerEngine);
+ when(transactionManagerEngine.getTransactionManager(TransactionType.XA)).thenReturn(shardingTransactionManager);
+ return result;
}
@Test
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
index 65f5679..8cd1a58 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/datasource/JDBCBackendDataSourceTest.java
@@ -29,7 +29,7 @@ import org.apache.shardingsphere.kernel.context.runtime.RuntimeContext;
import org.apache.shardingsphere.kernel.context.schema.ShardingSphereSchema;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
-import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Before;
import org.junit.Test;
@@ -55,6 +55,7 @@ import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -62,24 +63,22 @@ public final class JDBCBackendDataSourceTest {
@Before
public void setUp() {
- setDataSource();
+ setSchemaContexts();
+ setTransactionContexts();
}
@SneakyThrows(ReflectiveOperationException.class)
- private void setDataSource() {
+ private void setSchemaContexts() {
Field schemaContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField("schemaContexts");
schemaContexts.setAccessible(true);
schemaContexts.set(ProxySchemaContexts.getInstance(),
- new StandardSchemaContexts(getSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType()));
+ new StandardSchemaContexts(createSchemaContextMap(), new Authentication(), new ConfigurationProperties(new Properties()), new MySQLDatabaseType()));
}
- private Map<String, SchemaContext> getSchemaContextMap() {
+ private Map<String, SchemaContext> createSchemaContextMap() {
SchemaContext schemaContext = mock(SchemaContext.class);
ShardingSphereSchema shardingSphereSchema = mock(ShardingSphereSchema.class);
RuntimeContext runtimeContext = mock(RuntimeContext.class);
- ShardingTransactionManagerEngine transactionManagerEngine = mock(ShardingTransactionManagerEngine.class);
- when(transactionManagerEngine.getTransactionManager(TransactionType.LOCAL)).thenReturn(null);
- when(runtimeContext.getTransactionManagerEngine()).thenReturn(transactionManagerEngine);
when(shardingSphereSchema.getDataSources()).thenReturn(mockDataSources(2));
when(schemaContext.getName()).thenReturn("schema");
when(schemaContext.getSchema()).thenReturn(shardingSphereSchema);
@@ -87,6 +86,20 @@ public final class JDBCBackendDataSourceTest {
return Collections.singletonMap("schema", schemaContext);
}
+ @SneakyThrows(ReflectiveOperationException.class)
+ private void setTransactionContexts() {
+ Field transactionContexts = ProxySchemaContexts.getInstance().getClass().getDeclaredField("transactionContexts");
+ transactionContexts.setAccessible(true);
+ transactionContexts.set(ProxySchemaContexts.getInstance(), createTransactionContexts());
+ }
+
+ private TransactionContexts createTransactionContexts() {
+ TransactionContexts result = mock(TransactionContexts.class, RETURNS_DEEP_STUBS);
+ ShardingTransactionManagerEngine transactionManagerEngine = mock(ShardingTransactionManagerEngine.class);
+ when(result.getEngines().get("schema")).thenReturn(transactionManagerEngine);
+ return result;
+ }
+
private Map<String, DataSource> mockDataSources(final int size) {
Map<String, DataSource> result = new HashMap<>(size, 1);
for (int i = 0; i < size; i++) {
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
index cf3df37..d47a93d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/sctl/explain/ShardingCTLExplainBackendHandlerTest.java
@@ -61,7 +61,7 @@ public final class ShardingCTLExplainBackendHandlerTest {
}
private Map<String, SchemaContext> getSchemaContextMap() {
- RuntimeContext runtimeContext = new RuntimeContext(null, null, new ShardingSphereSQLParserEngine(new StandardSQLParserEngine("MySQL")), null);
+ RuntimeContext runtimeContext = new RuntimeContext(null, null, new ShardingSphereSQLParserEngine(new StandardSQLParserEngine("MySQL")));
ShardingSphereSchema schema = new ShardingSphereSchema(Collections.emptyList(),
Collections.emptyList(), Collections.singletonMap("ds0", mock(DataSource.class)), null);
return Collections.singletonMap("schema", new SchemaContext("schema", schema, runtimeContext));
diff --git a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
index 0f1879d..cd39fc3 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/java/org/apache/shardingsphere/proxy/Bootstrap.java
@@ -21,10 +21,12 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerInfo;
+import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
+import org.apache.shardingsphere.governance.core.transaction.GovernanceTransactionContexts;
import org.apache.shardingsphere.infra.config.properties.ConfigurationPropertyKey;
+import org.apache.shardingsphere.kernel.context.SchemaContext;
import org.apache.shardingsphere.kernel.context.SchemaContexts;
import org.apache.shardingsphere.kernel.context.SchemaContextsBuilder;
-import org.apache.shardingsphere.governance.core.facade.GovernanceFacade;
import org.apache.shardingsphere.proxy.arg.BootstrapArguments;
import org.apache.shardingsphere.proxy.backend.schema.ProxyDataSourceContext;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
@@ -37,10 +39,16 @@ import org.apache.shardingsphere.proxy.frontend.bootstrap.ShardingSphereProxy;
import org.apache.shardingsphere.proxy.governance.GovernanceBootstrap;
import org.apache.shardingsphere.proxy.governance.schema.ProxyGovernanceSchemaContexts;
import org.apache.shardingsphere.tracing.opentracing.OpenTracingTracer;
+import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+import org.apache.shardingsphere.transaction.context.impl.StandardTransactionContexts;
import javax.sql.DataSource;
import java.io.IOException;
import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
/**
@@ -81,13 +89,26 @@ public final class Bootstrap {
ProxyDataSourceContext dataSourceContext = new ProxyDataSourceContext(proxyConfig.getSchemaDataSources());
SchemaContextsBuilder schemaContextsBuilder = new SchemaContextsBuilder(
dataSourceContext.getDatabaseType(), dataSourceContext.getDataSourcesMap(), proxyConfig.getSchemaRules(), proxyConfig.getAuthentication(), proxyConfig.getProps());
- ProxySchemaContexts.getInstance().init(createSchemaContexts(schemaContextsBuilder.build(), governanceEnabled));
+ SchemaContexts schemaContexts = createSchemaContexts(schemaContextsBuilder.build(), governanceEnabled);
+ TransactionContexts transactionContexts = createTransactionContexts(schemaContexts, governanceEnabled);
+ ProxySchemaContexts.getInstance().init(schemaContexts, transactionContexts);
}
private static SchemaContexts createSchemaContexts(final SchemaContexts schemaContexts, final boolean governanceEnabled) {
return governanceEnabled ? new ProxyGovernanceSchemaContexts(schemaContexts, GovernanceFacade.getInstance()) : schemaContexts;
}
+ private static TransactionContexts createTransactionContexts(final SchemaContexts schemaContexts, final boolean orchestrationEnabled) {
+ Map<String, ShardingTransactionManagerEngine> transactionManagerEngines = new HashMap<>(schemaContexts.getSchemaContexts().size(), 1);
+ for (Entry<String, SchemaContext> entry : schemaContexts.getSchemaContexts().entrySet()) {
+ ShardingTransactionManagerEngine engine = new ShardingTransactionManagerEngine();
+ engine.init(schemaContexts.getDatabaseType(), entry.getValue().getSchema().getDataSources());
+ transactionManagerEngines.put(entry.getKey(), engine);
+ }
+ TransactionContexts contexts = new StandardTransactionContexts(transactionManagerEngines);
+ return orchestrationEnabled ? new GovernanceTransactionContexts(contexts) : contexts;
+ }
+
private static void initOpenTracing() {
if (ProxySchemaContexts.getInstance().getSchemaContexts().getProps().<Boolean>getValue(ConfigurationPropertyKey.PROXY_OPENTRACING_ENABLED)) {
OpenTracingTracer.init();
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
index ca3841f..bd5560b 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/auth/PostgreSQLAuthenticationEngineTest.java
@@ -21,8 +21,6 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.UnpooledByteBufAllocator;
import io.netty.buffer.UnpooledHeapByteBuf;
import io.netty.channel.ChannelHandlerContext;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
import lombok.SneakyThrows;
import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.BinaryStatementRegistry;
@@ -32,9 +30,13 @@ import org.apache.shardingsphere.infra.auth.ProxyUser;
import org.apache.shardingsphere.kernel.context.impl.StandardSchemaContexts;
import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
import org.apache.shardingsphere.proxy.frontend.engine.AuthenticationResult;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@@ -124,7 +126,7 @@ public final class PostgreSQLAuthenticationEngineTest {
ProxySchemaContexts proxySchemaContexts = ProxySchemaContexts.getInstance();
StandardSchemaContexts standardSchemaContexts = new StandardSchemaContexts();
standardSchemaContexts.getAuthentication().getUsers().put(username, new ProxyUser(password, null));
- proxySchemaContexts.init(standardSchemaContexts);
+ proxySchemaContexts.init(standardSchemaContexts, mock(TransactionContexts.class));
actual = engine.auth(channelHandlerContext, payload);
assertThat(actual.isFinished(), is(password.equals(inputPassword)));
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-governance/pom.xml b/shardingsphere-proxy/shardingsphere-proxy-governance/pom.xml
index 39bc23d..7a0859d 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-governance/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-governance/pom.xml
@@ -55,4 +55,4 @@
<version>${project.parent.version}</version>
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java b/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContexts.java
similarity index 59%
copy from shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
copy to shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContexts.java
index 5e849de..6ca81fd 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
+++ b/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContexts.java
@@ -15,26 +15,28 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.kernel.context.runtime;
+package org.apache.shardingsphere.transaction.context;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
-import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import java.util.Map;
+
/**
- * Runtime context.
+ * Transaction contexts.
*/
-@RequiredArgsConstructor
-@Getter
-public final class RuntimeContext {
-
- private final CachedDatabaseMetaData cachedDatabaseMetaData;
-
- private final ExecutorKernel executorKernel;
+public interface TransactionContexts extends AutoCloseable {
- private final ShardingSphereSQLParserEngine sqlParserEngine;
+ /**
+ * Get transaction manager engines.
+ *
+ * @return transaction manager engines
+ */
+ Map<String, ShardingTransactionManagerEngine> getEngines();
- private final ShardingTransactionManagerEngine transactionManagerEngine;
+ /**
+ * Get default transaction manager engine.
+ *
+ * @return default transaction manager engine
+ */
+ ShardingTransactionManagerEngine getDefaultTransactionManagerEngine();
}
diff --git a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java b/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContexts.java
similarity index 54%
copy from shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
copy to shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContexts.java
index 5e849de..adf0306 100644
--- a/shardingsphere-kernel/shardingsphere-kernel-context/src/main/java/org/apache/shardingsphere/kernel/context/runtime/RuntimeContext.java
+++ b/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/impl/StandardTransactionContexts.java
@@ -15,26 +15,39 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.kernel.context.runtime;
+package org.apache.shardingsphere.transaction.context.impl;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.infra.executor.kernel.ExecutorKernel;
-import org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
+import org.apache.shardingsphere.infra.database.DefaultSchema;
import org.apache.shardingsphere.transaction.ShardingTransactionManagerEngine;
+import org.apache.shardingsphere.transaction.context.TransactionContexts;
+
+import java.util.HashMap;
+import java.util.Map;
/**
- * Runtime context.
+ * Standard transaction contexts.
*/
@RequiredArgsConstructor
@Getter
-public final class RuntimeContext {
+public final class StandardTransactionContexts implements TransactionContexts {
- private final CachedDatabaseMetaData cachedDatabaseMetaData;
+ private final Map<String, ShardingTransactionManagerEngine> engines;
- private final ExecutorKernel executorKernel;
+ public StandardTransactionContexts() {
+ this(new HashMap<>());
+ }
- private final ShardingSphereSQLParserEngine sqlParserEngine;
+ @Override
+ public ShardingTransactionManagerEngine getDefaultTransactionManagerEngine() {
+ return engines.get(DefaultSchema.LOGIC_NAME);
+ }
- private final ShardingTransactionManagerEngine transactionManagerEngine;
+ @Override
+ public void close() throws Exception {
+ for (ShardingTransactionManagerEngine each : engines.values()) {
+ each.close();
+ }
+ }
}