This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 07fa397 Revise #15115 (#15320)
07fa397 is described below
commit 07fa397c2c3cf1462610eae32d0cfd46187f0a00
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Feb 9 18:26:24 2022 +0800
Revise #15115 (#15320)
---
... => TransactionConfigurationFileGenerator.java} | 10 +--
...nsactionConfigurationFileGeneratorFactory.java} | 21 +++----
...ava => NarayanaConfigurationFileGenerator.java} | 72 ++++++++++------------
...tion.spi.TransactionConfigurationFileGenerator} | 2 +-
.../cluster/ClusterContextManagerBuilder.java | 20 +++---
.../memory/MemoryContextManagerBuilder.java | 20 +++---
.../StandaloneContextManagerBuilder.java | 26 ++++----
7 files changed, 88 insertions(+), 83 deletions(-)
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFacade.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigurationFileGenerator.java
similarity index 81%
rename from
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFacade.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigurationFileGenerator.java
index fd975c3..79636cf 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFacade.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigurationFileGenerator.java
@@ -21,15 +21,15 @@ import org.apache.shardingsphere.spi.typed.TypedSPI;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
/**
- * Transaction config facade.
+ * Transaction configuration file generator.
*/
-public interface TransactionConfigFacade extends TypedSPI {
-
+public interface TransactionConfigurationFileGenerator extends TypedSPI {
+
/**
- * Generate transaction config.
+ * Generate transaction configuration file.
*
* @param transactionRule transaction rule
* @param instanceId instance id
*/
- void generate(TransactionRule transactionRule, String instanceId);
+ void generateFile(TransactionRule transactionRule, String instanceId);
}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigurationFileGeneratorFactory.java
similarity index 63%
rename from
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigurationFileGeneratorFactory.java
index aa4704d..37b9540 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigurationFileGeneratorFactory.java
@@ -24,24 +24,21 @@ import java.util.Optional;
import java.util.Properties;
/**
- * Transaction config factory.
+ * Transaction configuration file generator factory.
*/
-public final class TransactionConfigFactory {
-
+public final class TransactionConfigurationFileGeneratorFactory {
+
static {
- ShardingSphereServiceLoader.register(TransactionConfigFacade.class);
+
ShardingSphereServiceLoader.register(TransactionConfigurationFileGenerator.class);
}
-
+
/**
- * Get transaction config facade instance.
+ * Create new instance of transaction configuration file generator.
*
* @param transactionProviderType transaction provider type
- * @return transaction config facade
+ * @return new instance of transaction configuration file generator
*/
- public static Optional<TransactionConfigFacade> newInstance(final String
transactionProviderType) {
- if (null != transactionProviderType) {
- return
TypedSPIRegistry.findRegisteredService(TransactionConfigFacade.class,
transactionProviderType, new Properties());
- }
- return Optional.empty();
+ public static Optional<TransactionConfigurationFileGenerator>
newInstance(final String transactionProviderType) {
+ return null == transactionProviderType ? Optional.empty() :
TypedSPIRegistry.findRegisteredService(TransactionConfigurationFileGenerator.class,
transactionProviderType, new Properties());
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/m
[...]
similarity index 95%
rename from
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigurationFileGenerator.java
index 257d24f..1dfb712 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigurationFileGenerator.java
@@ -27,7 +27,7 @@ import
com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResour
import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGenerator;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -40,18 +40,14 @@ import java.util.List;
import java.util.Map;
/**
- * Narayana config facade.
+ * Narayana transaction configuration file generator.
*/
@Slf4j
-public final class NarayanaConfigFacade implements TransactionConfigFacade {
-
+public final class NarayanaConfigurationFileGenerator implements
TransactionConfigurationFileGenerator {
+
@Override
- public void generate(final TransactionRule transactionRule, final String
instanceId) {
- if (null == transactionRule) {
- return;
- }
- Map<Object, Object> content;
- content = generateDefaultNarayanaConfig(instanceId);
+ public void generateFile(final TransactionRule transactionRule, final
String instanceId) {
+ Map<Object, Object> content =
generateDefaultNarayanaConfig(instanceId);
if (null != transactionRule.getProps()) {
swapJdbcStore(transactionRule, content);
}
@@ -64,32 +60,7 @@ public final class NarayanaConfigFacade implements
TransactionConfigFacade {
log.error("generate narayana config file failed.");
}
}
-
- private static void swapJdbcStore(final TransactionRule transactionRule,
final Map<Object, Object> config) {
- Object host = transactionRule.getProps().get("host");
- Object port = transactionRule.getProps().get("port");
- Object user = transactionRule.getProps().getProperty("user");
- Object password = transactionRule.getProps().getProperty("password");
- Object databaseName =
transactionRule.getProps().getProperty("databaseName");
- if (null != host && null != port && null != user && null != password
&& null != databaseName) {
- String jdbcAccessPatten =
DynamicDataSourceJDBCAccess.class.getName()
- +
";ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s";
- String jdbcAccess = String.format(jdbcAccessPatten, host, port,
databaseName, user, password);
- config.put("ObjectStoreEnvironmentBean.objectStoreType",
JDBCStore.class.getName());
- config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
- config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
- config.put("ObjectStoreEnvironmentBean.dropTable", true);
-
config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType",
JDBCStore.class.getName());
- config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess",
jdbcAccess);
- config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix",
"stateStore");
- config.put("ObjectStoreEnvironmentBean.stateStore.dropTable",
true);
-
config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType",
JDBCStore.class.getName());
-
config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess",
jdbcAccess);
-
config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix",
"Communication");
-
config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
- }
- }
-
+
private static Map<Object, Object> generateDefaultNarayanaConfig(final
String instanceId) {
Map<Object, Object> result = new LinkedHashMap<>(32, 1);
result.put("CoordinatorEnvironmentBean.commitOnePhase", "YES");
@@ -115,7 +86,32 @@ public final class NarayanaConfigFacade implements
TransactionConfigFacade {
result.put("RecoveryEnvironmentBean.recoveryBackoffPeriod", 1);
return result;
}
-
+
+ private static void swapJdbcStore(final TransactionRule transactionRule,
final Map<Object, Object> config) {
+ Object host = transactionRule.getProps().get("host");
+ Object port = transactionRule.getProps().get("port");
+ Object user = transactionRule.getProps().getProperty("user");
+ Object password = transactionRule.getProps().getProperty("password");
+ Object databaseName =
transactionRule.getProps().getProperty("databaseName");
+ if (null != host && null != port && null != user && null != password
&& null != databaseName) {
+ String jdbcAccessPatten =
DynamicDataSourceJDBCAccess.class.getName()
+ +
";ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s";
+ String jdbcAccess = String.format(jdbcAccessPatten, host, port,
databaseName, user, password);
+ config.put("ObjectStoreEnvironmentBean.objectStoreType",
JDBCStore.class.getName());
+ config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
+ config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
+ config.put("ObjectStoreEnvironmentBean.dropTable", true);
+
config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType",
JDBCStore.class.getName());
+ config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess",
jdbcAccess);
+ config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix",
"stateStore");
+ config.put("ObjectStoreEnvironmentBean.stateStore.dropTable",
true);
+
config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType",
JDBCStore.class.getName());
+
config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess",
jdbcAccess);
+
config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix",
"Communication");
+
config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
+ }
+ }
+
private static String narayanaConfigMapToXml(final Map<Object, Object>
config) {
StringBuilder result = new StringBuilder("<properties>");
for (Object each : config.keySet()) {
@@ -139,7 +135,7 @@ public final class NarayanaConfigFacade implements
TransactionConfigFacade {
result.append("</properties>");
return result.toString();
}
-
+
@Override
public String getType() {
return "Narayana";
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.TransactionConfigFacade
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-naraya
[...]
similarity index 97%
rename from
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.TransactionConfigFacade
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGenerator
index ff43fe1..fef27c8 100644
---
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.TransactionConfigFacade
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/resources/META-INF/services/org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGenerator
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.transaction.xa.narayana.util.NarayanaConfigFacade
+org.apache.shardingsphere.transaction.xa.narayana.util.NarayanaConfigurationFileGenerator
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 0578ab6..bfed130 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -40,8 +40,8 @@ import
org.apache.shardingsphere.schedule.core.api.ModeScheduleContextFactory;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import
org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFactory;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGenerator;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGeneratorFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -65,12 +65,7 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
MetaDataContextsBuilder metaDataContextsBuilder =
createMetaDataContextsBuilder(metaDataPersistService, parameter);
persistMetaData(metaDataPersistService,
metaDataContextsBuilder.getSchemaMap());
MetaDataContexts metaDataContexts =
metaDataContextsBuilder.build(metaDataPersistService);
- Optional<TransactionRule> transactionRule =
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each ->
each instanceof TransactionRule).map(each -> (TransactionRule) each)
- .findFirst();
- if (transactionRule.isPresent()) {
- Optional<TransactionConfigFacade> transactionConfigFacade =
TransactionConfigFactory.newInstance(transactionRule.get().getProviderType());
- transactionConfigFacade.ifPresent(configFacade ->
configFacade.generate(transactionRule.get(),
parameter.getInstanceDefinition().getInstanceId().getId()));
- }
+
generateTransactionConfigurationFile(parameter.getInstanceDefinition().getInstanceId().getId(),
metaDataContexts);
ContextManager result = createContextManager(repository,
metaDataPersistService,
parameter.getInstanceDefinition(), metaDataContexts,
parameter.getModeConfig());
registerOnline(repository, metaDataPersistService,
parameter.getInstanceDefinition(), result);
@@ -105,6 +100,15 @@ public final class ClusterContextManagerBuilder implements
ContextManagerBuilder
}
}
+ private void generateTransactionConfigurationFile(final String instanceId,
final MetaDataContexts metaDataContexts) {
+ Optional<TransactionRule> transactionRule =
+
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each ->
each instanceof TransactionRule).map(each -> (TransactionRule)
each).findFirst();
+ if (transactionRule.isPresent()) {
+ Optional<TransactionConfigurationFileGenerator> fileGenerator =
TransactionConfigurationFileGeneratorFactory.newInstance(transactionRule.get().getProviderType());
+ fileGenerator.ifPresent(optional ->
optional.generateFile(transactionRule.get(), instanceId));
+ }
+ }
+
private ContextManager createContextManager(final ClusterPersistRepository
repository,
final MetaDataPersistService
metaDataPersistService, final InstanceDefinition instanceDefinition, final
MetaDataContexts metaDataContexts,
final ModeConfiguration
modeConfiguration) {
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
index 8b4ab0c..e9a8eef 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-memory-mode/shardingsphere-memory-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/memory/MemoryContextManagerBuilder.java
@@ -31,8 +31,8 @@ import
org.apache.shardingsphere.mode.metadata.MetaDataContextsBuilder;
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import
org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFactory;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGenerator;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGeneratorFactory;
import java.sql.SQLException;
import java.util.Map.Entry;
@@ -50,12 +50,7 @@ public final class MemoryContextManagerBuilder implements
ContextManagerBuilder
metaDataContextsBuilder.addSchema(entry.getKey(),
entry.getValue(), parameter.getProps());
}
MetaDataContexts metaDataContexts =
metaDataContextsBuilder.build(null);
- Optional<TransactionRule> transactionRule =
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each ->
each instanceof TransactionRule).map(each -> (TransactionRule) each)
- .findFirst();
- if (transactionRule.isPresent()) {
- Optional<TransactionConfigFacade> transactionConfigFacade =
TransactionConfigFactory.newInstance(transactionRule.get().getProviderType());
- transactionConfigFacade.ifPresent(configFacade ->
configFacade.generate(transactionRule.get(),
parameter.getInstanceDefinition().getInstanceId().getId()));
- }
+
generateTransactionConfigurationFile(parameter.getInstanceDefinition().getInstanceId().getId(),
metaDataContexts);
TransactionContexts transactionContexts = new
TransactionContextsBuilder(metaDataContexts.getMetaDataMap(),
metaDataContexts.getGlobalRuleMetaData().getRules()).build();
ContextManager result = new ContextManager();
result.init(metaDataContexts, transactionContexts,
buildInstanceContext(parameter));
@@ -63,6 +58,15 @@ public final class MemoryContextManagerBuilder implements
ContextManagerBuilder
return result;
}
+ private void generateTransactionConfigurationFile(final String instanceId,
final MetaDataContexts metaDataContexts) {
+ Optional<TransactionRule> transactionRule =
+
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each ->
each instanceof TransactionRule).map(each -> (TransactionRule)
each).findFirst();
+ if (transactionRule.isPresent()) {
+ Optional<TransactionConfigurationFileGenerator> fileGenerator =
TransactionConfigurationFileGeneratorFactory.newInstance(transactionRule.get().getProviderType());
+ fileGenerator.ifPresent(optional ->
optional.generateFile(transactionRule.get(), instanceId));
+ }
+ }
+
private InstanceContext buildInstanceContext(final
ContextManagerBuilderParameter parameter) {
ComputeNodeInstance instance = new ComputeNodeInstance();
instance.setInstanceDefinition(parameter.getInstanceDefinition());
diff --git
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
index ab8e017..a4a2dfc 100644
---
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
+++
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-standalone-mode/shardingsphere-standalone-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/StandaloneContextManagerBuilder.java
@@ -33,8 +33,8 @@ import
org.apache.shardingsphere.mode.repository.standalone.StandalonePersistRep
import org.apache.shardingsphere.transaction.context.TransactionContexts;
import
org.apache.shardingsphere.transaction.context.TransactionContextsBuilder;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
-import org.apache.shardingsphere.transaction.spi.TransactionConfigFactory;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGenerator;
+import
org.apache.shardingsphere.transaction.spi.TransactionConfigurationFileGeneratorFactory;
import javax.sql.DataSource;
import java.sql.SQLException;
@@ -53,15 +53,16 @@ public final class StandaloneContextManagerBuilder
implements ContextManagerBuil
MetaDataPersistService metaDataPersistService = new
MetaDataPersistService(StandalonePersistRepositoryFactory.newInstance(parameter.getModeConfig().getRepository()));
persistConfigurations(metaDataPersistService, parameter);
MetaDataContexts metaDataContexts =
createMetaDataContexts(metaDataPersistService, parameter);
- Optional<TransactionRule> transactionRule =
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each ->
each instanceof TransactionRule).map(each -> (TransactionRule) each)
- .findFirst();
- if (transactionRule.isPresent()) {
- Optional<TransactionConfigFacade> transactionConfigFacade =
TransactionConfigFactory.newInstance(transactionRule.get().getProviderType());
- transactionConfigFacade.ifPresent(configFacade ->
configFacade.generate(transactionRule.get(),
parameter.getInstanceDefinition().getInstanceId().getId()));
- }
+
generateTransactionConfigurationFile(parameter.getInstanceDefinition().getInstanceId().getId(),
metaDataContexts);
return createContextManager(metaDataPersistService, parameter,
metaDataContexts);
}
+ private void persistConfigurations(final MetaDataPersistService
metaDataPersistService, final ContextManagerBuilderParameter parameter) {
+ if (!parameter.isEmpty()) {
+
metaDataPersistService.persistConfigurations(parameter.getSchemaConfigs(),
parameter.getGlobalRuleConfigs(), parameter.getProps(),
parameter.getModeConfig().isOverwrite());
+ }
+ }
+
private MetaDataContexts createMetaDataContexts(final
MetaDataPersistService metaDataPersistService, final
ContextManagerBuilderParameter parameter) throws SQLException {
Collection<RuleConfiguration> globalRuleConfigs =
metaDataPersistService.getGlobalRuleService().load();
Properties props = metaDataPersistService.getPropsService().load();
@@ -76,9 +77,12 @@ public final class StandaloneContextManagerBuilder
implements ContextManagerBuil
return builder.build(metaDataPersistService);
}
- private void persistConfigurations(final MetaDataPersistService
metaDataPersistService, final ContextManagerBuilderParameter parameter) {
- if (!parameter.isEmpty()) {
-
metaDataPersistService.persistConfigurations(parameter.getSchemaConfigs(),
parameter.getGlobalRuleConfigs(), parameter.getProps(),
parameter.getModeConfig().isOverwrite());
+ private void generateTransactionConfigurationFile(final String instanceId,
final MetaDataContexts metaDataContexts) {
+ Optional<TransactionRule> transactionRule =
+
metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each ->
each instanceof TransactionRule).map(each -> (TransactionRule)
each).findFirst();
+ if (transactionRule.isPresent()) {
+ Optional<TransactionConfigurationFileGenerator> fileGenerator =
TransactionConfigurationFileGeneratorFactory.newInstance(transactionRule.get().getProviderType());
+ fileGenerator.ifPresent(optional ->
optional.generateFile(transactionRule.get(), instanceId));
}
}