This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 7a30e9aa815 Migrate global rule (TransactionRule) to
shardingsphere-transaction-distsql module. (#20698)
7a30e9aa815 is described below
commit 7a30e9aa81548d9afc3fb4e55926057cefa90b79
Author: yx9o <[email protected]>
AuthorDate: Fri Sep 2 09:51:18 2022 +0800
Migrate global rule (TransactionRule) to shardingsphere-transaction-distsql
module. (#20698)
* Migrate global rule (TransactionRule) to
shardingsphere-transaction-distsql module.
* Remove useless imports.
* Update.
* Update test.
---
.../src/main/antlr4/imports/RALStatement.g4 | 24 ------
.../parser/autogen/KernelDistSQLStatement.g4 | 2 -
.../core/kernel/KernelDistSQLStatementVisitor.java | 32 --------
.../infra/distsql/update/GlobalRuleRALUpdater.java | 6 +-
.../handler/query/TrafficRulesQueryResultSet.java | 3 +-
.../update/AlterTrafficRuleStatementUpdater.java | 7 +-
.../update/CreateTrafficRuleStatementUpdater.java | 7 +-
.../update/DropTrafficRuleStatementUpdater.java | 7 +-
.../AlterTrafficRuleStatementUpdaterTest.java | 28 ++++---
.../CreateTrafficRuleStatementUpdaterTest.java | 28 ++++---
.../DropTrafficRuleStatementUpdaterTest.java | 23 +++---
.../shardingsphere-transaction/pom.xml | 1 +
.../pom.xml | 10 +--
.../pom.xml | 27 +++++--
.../query/TransactionRuleQueryResultSet.java | 74 ++++++++++++++++++
.../AlterTransactionRuleStatementUpdater.java | 54 +++++++++++++
...dingsphere.infra.distsql.query.DistSQLResultSet | 18 +++++
...phere.infra.distsql.update.GlobalRuleRALUpdater | 18 +++++
.../query/TransactionRuleQueryResultSetTest.java | 76 ++++++++++++++++++
.../AlterTransactionRuleStatementUpdaterTest.java | 70 +++++++++--------
.../pom.xml | 69 ++++++++++++++++
.../main/antlr4/imports/transaction/Alphabet.g4 | 36 +++++++--
.../src/main/antlr4/imports/transaction/Keyword.g4 | 44 +++++++++--
.../main/antlr4/imports/transaction/Literals.g4 | 18 +++--
.../antlr4/imports/transaction/RALStatement.g4 | 52 +++++++++----
.../src/main/antlr4/imports/transaction/Symbol.g4 | 62 +++++++++++++++
.../parser/autogen/TransactionDistSQLStatement.g4 | 14 ++--
.../parser/core/TransactionDistSQLLexer.java | 22 +++---
.../parser/core/TransactionDistSQLParser.java | 26 ++++---
.../core/TransactionDistSQLStatementVisitor.java | 81 +++++++++++++++++++
.../TransactionDistSQLStatementParserFacade.java | 52 +++++++++++++
...engine.spi.FeaturedDistSQLStatementParserFacade | 18 +++++
.../pom.xml | 17 ++--
.../parser/segment/TransactionProviderSegment.java | 2 +-
.../queryable/ShowTransactionRuleStatement.java | 6 +-
.../updatable/AlterTransactionRuleStatement.java | 10 +--
.../shardingsphere-proxy-backend/pom.xml | 5 ++
.../distsql/ral/RALBackendHandlerFactory.java | 6 --
.../ral/UpdatableGlobalRuleRALBackendHandler.java | 2 +-
.../ral/queryable/ShowTransactionRuleHandler.java | 54 -------------
.../ral/updatable/AlterTransactionRuleHandler.java | 63 ---------------
.../distsql/ral/updatable/ApplyDistSQLHandler.java | 4 +-
.../ral/updatable/DiscardDistSQLHandler.java | 4 +-
.../ral/updatable/PrepareDistSQLHandler.java | 4 +-
.../handler/ProxyBackendHandlerFactoryTest.java | 3 +-
.../queryable/ShowTransactionRuleHandlerTest.java | 91 ----------------------
.../shardingsphere-parser-test/pom.xml | 5 ++
.../ral/impl/QueryableRALStatementAssert.java | 2 +-
.../ral/impl/UpdatableRALStatementAssert.java | 4 +
.../ShowTransactionRuleStatementAssert.java | 2 +-
.../AlterTransactionRuleStatementAssert.java} | 21 +++--
51 files changed, 841 insertions(+), 473 deletions(-)
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
index 6c03e0037c6..61825fc545b 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
@@ -59,14 +59,6 @@ showTableMetadata
: SHOW TABLE METADATA tableName (COMMA tableName*)? (FROM databaseName)?
;
-showTransactionRule
- : SHOW TRANSACTION RULE
- ;
-
-alterTransactionRule
- : ALTER TRANSACTION RULE transactionRuleDefinition
- ;
-
showSQLParserRule
: SHOW SQL_PARSER RULE
;
@@ -163,22 +155,6 @@ filePath
: STRING
;
-transactionRuleDefinition
- : LP DEFAULT EQ defaultType (COMMA providerDefinition)?
- ;
-
-providerDefinition
- : TYPE LP NAME EQ providerName (COMMA propertiesDefinition)? RP
- ;
-
-defaultType
- : STRING
- ;
-
-providerName
- : STRING
- ;
-
sqlParserRuleDefinition
: SQL_COMMENT_PARSE_ENABLE EQ sqlCommentParseEnable (COMMA
PARSE_TREE_CACHE LP parseTreeCache RP)? (COMMA SQL_STATEMENT_CACHE LP
sqlStatementCache RP)?
;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
index 46843eb5283..c4b2b79b4a4 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
@@ -51,8 +51,6 @@ execute
| showTableMetadata
| showSQLParserRule
| alterSQLParserRule
- | showTransactionRule
- | alterTransactionRule
| exportDatabaseConfiguration
| showRulesUsedResource
| importDatabaseConfiguration
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
index dc2c99e32a3..fcfc88d2575 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
@@ -27,7 +27,6 @@ import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterMigrationProcessConfigurationContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterResourceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterSQLParserRuleContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterTransactionRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ApplyDistSQLContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.BatchSizeContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.CacheOptionContext;
@@ -53,7 +52,6 @@ import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.PrepareDistSQLContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.PropertiesDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.PropertyContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ProviderDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.RateLimiterContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ReadDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.RefreshTableMetadataContext;
@@ -72,12 +70,10 @@ import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSingleTableContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSingleTableRulesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowTableMetadataContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowTransactionRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowUnusedResourcesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowVariableContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.SqlParserRuleDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.StreamChannelContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.TransactionRuleDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.UnlabelInstanceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.WorkerThreadContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.WriteDefinitionContext;
@@ -87,7 +83,6 @@ import
org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.segment.HostnameAndPortBasedDataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.segment.MigrationProcessConfigurationSegment;
import org.apache.shardingsphere.distsql.parser.segment.ReadOrWriteSegment;
-import
org.apache.shardingsphere.distsql.parser.segment.TransactionProviderSegment;
import
org.apache.shardingsphere.distsql.parser.segment.URLBasedDataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.statement.ral.hint.ClearHintStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
@@ -100,12 +95,10 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowMode
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLTranslatorRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetadataStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterInstanceStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterMigrationProcessConfigurationStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ApplyDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.CreateMigrationProcessConfigurationStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.DiscardDistSQLStatement;
@@ -330,31 +323,6 @@ public final class KernelDistSQLStatementVisitor extends
KernelDistSQLStatementB
return new RefreshTableMetadataStatement(tableName, resourceName,
schemaName);
}
- @Override
- public ASTNode visitShowTransactionRule(final ShowTransactionRuleContext
ctx) {
- return new ShowTransactionRuleStatement();
- }
-
- @Override
- public ASTNode visitAlterTransactionRule(final AlterTransactionRuleContext
ctx) {
- return visit(ctx.transactionRuleDefinition());
- }
-
- @Override
- public ASTNode visitTransactionRuleDefinition(final
TransactionRuleDefinitionContext ctx) {
- String defaultType = getIdentifierValue(ctx.defaultType());
- if (null != ctx.providerDefinition()) {
- TransactionProviderSegment provider = (TransactionProviderSegment)
visit(ctx.providerDefinition());
- return new AlterTransactionRuleStatement(defaultType, provider);
- }
- return new AlterTransactionRuleStatement(defaultType, new
TransactionProviderSegment(null, null));
- }
-
- @Override
- public ASTNode visitProviderDefinition(final ProviderDefinitionContext
ctx) {
- return new
TransactionProviderSegment(getIdentifierValue(ctx.providerName()),
getProperties(ctx.propertiesDefinition()));
- }
-
@Override
public ASTNode visitShowSQLParserRule(final ShowSQLParserRuleContext ctx) {
return new ShowSQLParserRuleStatement();
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/GlobalRuleRALUpdater.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/GlobalRuleRALUpdater.java
index 3333132b599..e74cd58bdd6 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/GlobalRuleRALUpdater.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/distsql/update/GlobalRuleRALUpdater.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.infra.distsql.update;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
-import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import org.apache.shardingsphere.infra.util.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.util.spi.type.typed.TypedSPI;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -32,9 +32,9 @@ public interface GlobalRuleRALUpdater extends TypedSPI {
/**
* Execute update.
*
- * @param ruleMetaData rule meta data
+ * @param metaData meta data
* @param sqlStatement SQL statement
* @throws DistSQLException definition violation exception
*/
- void executeUpdate(ShardingSphereRuleMetaData ruleMetaData, SQLStatement
sqlStatement) throws DistSQLException;
+ void executeUpdate(ShardingSphereMetaData metaData, SQLStatement
sqlStatement) throws DistSQLException;
}
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRulesQueryResultSet.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRulesQueryResultSet.java
index 55dae5ef47e..ecbbbd6a75b 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRulesQueryResultSet.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/query/TrafficRulesQueryResultSet.java
@@ -55,10 +55,9 @@ public final class TrafficRulesQueryResultSet implements
GlobalRuleDistSQLResult
@Override
public void init(final ShardingSphereRuleMetaData ruleMetaData, final
SQLStatement sqlStatement) {
- Optional<TrafficRule> rule =
ruleMetaData.findSingleRule(TrafficRule.class);
ShowTrafficRulesStatement statement = (ShowTrafficRulesStatement)
sqlStatement;
Optional<String> ruleName =
Optional.ofNullable(statement.getRuleName());
- rule.ifPresent(optional -> data =
buildData(optional.getConfiguration(), ruleName).iterator());
+ ruleMetaData.findSingleRule(TrafficRule.class).ifPresent(optional ->
data = buildData(optional.getConfiguration(), ruleName).iterator());
}
private Collection<Collection<Object>> buildData(final
TrafficRuleConfiguration ruleConfig, final Optional<String> ruleName) {
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
index 703cfd05621..b6da1fddcd4 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdater.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -47,10 +48,10 @@ import java.util.stream.Collectors;
public final class AlterTrafficRuleStatementUpdater implements
GlobalRuleRALUpdater {
@Override
- public void executeUpdate(final ShardingSphereRuleMetaData ruleMetaData,
final SQLStatement sqlStatement) throws DistSQLException {
+ public void executeUpdate(final ShardingSphereMetaData metaData, final
SQLStatement sqlStatement) throws DistSQLException {
AlterTrafficRuleStatement statement = (AlterTrafficRuleStatement)
sqlStatement;
- check(ruleMetaData, statement);
- replaceNewRule(ruleMetaData, statement);
+ check(metaData.getGlobalRuleMetaData(), statement);
+ replaceNewRule(metaData.getGlobalRuleMetaData(), statement);
}
private void check(final ShardingSphereRuleMetaData ruleMetaData, final
AlterTrafficRuleStatement sqlStatement) throws DistSQLException {
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdater.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdater.java
index 2eb2e2a1a81..c733edb8ef6 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdater.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdater.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
import org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -47,10 +48,10 @@ import java.util.stream.Collectors;
public final class CreateTrafficRuleStatementUpdater implements
GlobalRuleRALUpdater {
@Override
- public void executeUpdate(final ShardingSphereRuleMetaData ruleMetaData,
final SQLStatement sqlStatement) throws DistSQLException {
+ public void executeUpdate(final ShardingSphereMetaData metaData, final
SQLStatement sqlStatement) throws DistSQLException {
CreateTrafficRuleStatement statement = (CreateTrafficRuleStatement)
sqlStatement;
- check(ruleMetaData, statement);
- replaceNewRule(ruleMetaData, statement);
+ check(metaData.getGlobalRuleMetaData(), statement);
+ replaceNewRule(metaData.getGlobalRuleMetaData(), statement);
}
private void check(final ShardingSphereRuleMetaData ruleMetaData, final
CreateTrafficRuleStatement sqlStatement) throws DistSQLException {
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdater.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdater.java
index ceb52d6ad15..796f87c609b 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdater.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/main/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdater.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
import org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -40,10 +41,10 @@ import java.util.stream.Collectors;
public final class DropTrafficRuleStatementUpdater implements
GlobalRuleRALUpdater {
@Override
- public void executeUpdate(final ShardingSphereRuleMetaData ruleMetaData,
final SQLStatement sqlStatement) throws DistSQLException {
+ public void executeUpdate(final ShardingSphereMetaData metaData, final
SQLStatement sqlStatement) throws DistSQLException {
DropTrafficRuleStatement statement = (DropTrafficRuleStatement)
sqlStatement;
- check(ruleMetaData, statement);
- replaceNewRule(ruleMetaData, statement);
+ check(metaData.getGlobalRuleMetaData(), statement);
+ replaceNewRule(metaData.getGlobalRuleMetaData(), statement);
}
private void check(final ShardingSphereRuleMetaData ruleMetaData, final
DropTrafficRuleStatement sqlStatement) throws DistSQLException {
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
index f69ad80fc75..b39afff2977 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/AlterTrafficRuleStatementUpdaterTest.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import
org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration;
@@ -46,32 +47,32 @@ public final class AlterTrafficRuleStatementUpdaterTest {
@Test(expected = RequiredRuleMissedException.class)
public void assertExecuteWithNotExistRuleName() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
"rule_name_3", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
AlterTrafficRuleStatementUpdater updater = new
AlterTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+ updater.executeUpdate(metaData, new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
}
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertExecuteWithInvalidAlgorithmType() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
"rule_name_1", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("invalid", new Properties()), new AlgorithmSegment("invalid",
new Properties()));
AlterTrafficRuleStatementUpdater updater = new
AlterTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+ updater.executeUpdate(metaData, new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
}
@Test(expected = IllegalStateException.class)
public void assertExecuteWithLoadBalancerCannotBeNull() throws
SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment = new
TrafficRuleSegment("rule_name_1", Arrays.asList("olap", "order_by"),
new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()),
null);
AlterTrafficRuleStatementUpdater updater = new
AlterTrafficRuleStatementUpdater();
try {
- updater.executeUpdate(ruleMetaData, new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+ updater.executeUpdate(metaData, new
AlterTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
} catch (final IllegalStateException ex) {
- TrafficRule currentRule =
ruleMetaData.getSingleRule(TrafficRule.class);
+ TrafficRule currentRule =
metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class);
assertNotNull(currentRule);
throw ex;
}
@@ -79,14 +80,14 @@ public final class AlterTrafficRuleStatementUpdaterTest {
@Test
public void assertExecute() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment1 = new TrafficRuleSegment(
"rule_name_1", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
TrafficRuleSegment trafficRuleSegment2 = new TrafficRuleSegment(
"rule_name_2", Collections.emptyList(), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
AlterTrafficRuleStatementUpdater updater = new
AlterTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
AlterTrafficRuleStatement(Arrays.asList(trafficRuleSegment1,
trafficRuleSegment2)));
- TrafficRuleConfiguration alteredConfig =
ruleMetaData.getSingleRule(TrafficRule.class).getConfiguration();
+ updater.executeUpdate(metaData, new
AlterTrafficRuleStatement(Arrays.asList(trafficRuleSegment1,
trafficRuleSegment2)));
+ TrafficRuleConfiguration alteredConfig =
metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class).getConfiguration();
assertThat(alteredConfig.getTrafficStrategies().size(), is(2));
assertThat(alteredConfig.getLoadBalancers().size(), is(2));
assertThat(alteredConfig.getTrafficAlgorithms().size(), is(2));
@@ -95,8 +96,11 @@ public final class AlterTrafficRuleStatementUpdaterTest {
assertNotNull(alteredConfig.getLoadBalancers().get("rule_name_2_distsql.fixture"));
}
- private ShardingSphereRuleMetaData createRuleMetaData() {
- return new ShardingSphereRuleMetaData(new
LinkedList<>(Collections.singleton(mockTrafficRule())));
+ private ShardingSphereMetaData createMetaData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ ShardingSphereRuleMetaData ruleMetaData = new
ShardingSphereRuleMetaData(new
LinkedList<>(Collections.singleton(mockTrafficRule())));
+ when(metaData.getGlobalRuleMetaData()).thenReturn(ruleMetaData);
+ return metaData;
}
private TrafficRule mockTrafficRule() {
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java
index 39cf17c27f9..7f506b7b009 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/CreateTrafficRuleStatementUpdaterTest.java
@@ -21,6 +21,7 @@ import
org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.distsql.exception.rule.DuplicateRuleException;
import
org.apache.shardingsphere.infra.distsql.exception.rule.InvalidAlgorithmConfigurationException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import
org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration;
@@ -47,32 +48,32 @@ public final class CreateTrafficRuleStatementUpdaterTest {
@Test(expected = DuplicateRuleException.class)
public void assertExecuteWithInUsedRuleName() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment = new TrafficRuleSegment(
"rule_name_1", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
CreateTrafficRuleStatementUpdater updater = new
CreateTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
CreateTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+ updater.executeUpdate(metaData, new
CreateTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
}
@Test(expected = InvalidAlgorithmConfigurationException.class)
public void assertExecuteWithInvalidAlgorithmType() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment = new
TrafficRuleSegment("input_rule_name", Arrays.asList("olap", "order_by"),
new AlgorithmSegment("invalid", new Properties()), new
AlgorithmSegment("invalid", new Properties()));
CreateTrafficRuleStatementUpdater updater = new
CreateTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
CreateTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+ updater.executeUpdate(metaData, new
CreateTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
}
@Test(expected = IllegalStateException.class)
public void assertExecuteWithLoadBalancerCannotBeNull() throws
SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment = new
TrafficRuleSegment("input_rule_name", Arrays.asList("olap", "order_by"),
new AlgorithmSegment("DISTSQL.FIXTURE", new Properties()),
null);
CreateTrafficRuleStatementUpdater updater = new
CreateTrafficRuleStatementUpdater();
try {
- updater.executeUpdate(ruleMetaData, new
CreateTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
+ updater.executeUpdate(metaData, new
CreateTrafficRuleStatement(Collections.singleton(trafficRuleSegment)));
} catch (final IllegalStateException ex) {
- TrafficRule currentRule =
ruleMetaData.getSingleRule(TrafficRule.class);
+ TrafficRule currentRule =
metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class);
assertNotNull(currentRule);
throw ex;
}
@@ -80,14 +81,14 @@ public final class CreateTrafficRuleStatementUpdaterTest {
@Test
public void assertExecute() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
TrafficRuleSegment trafficRuleSegment1 = new TrafficRuleSegment(
"rule_name_3", Arrays.asList("olap", "order_by"), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
TrafficRuleSegment trafficRuleSegment2 = new TrafficRuleSegment(
"rule_name_4", Collections.emptyList(), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()), new
AlgorithmSegment("DISTSQL.FIXTURE", new Properties()));
CreateTrafficRuleStatementUpdater updater = new
CreateTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
CreateTrafficRuleStatement(Arrays.asList(trafficRuleSegment1,
trafficRuleSegment2)));
- TrafficRuleConfiguration addedConfig =
ruleMetaData.getSingleRule(TrafficRule.class).getConfiguration();
+ updater.executeUpdate(metaData, new
CreateTrafficRuleStatement(Arrays.asList(trafficRuleSegment1,
trafficRuleSegment2)));
+ TrafficRuleConfiguration addedConfig =
metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class).getConfiguration();
assertThat(addedConfig.getTrafficStrategies().size(), is(4));
assertThat(addedConfig.getLoadBalancers().size(), is(4));
assertThat(addedConfig.getTrafficAlgorithms().size(), is(4));
@@ -99,8 +100,11 @@ public final class CreateTrafficRuleStatementUpdaterTest {
assertNotNull(addedConfig.getLoadBalancers().get("rule_name_4_distsql.fixture"));
}
- private ShardingSphereRuleMetaData createRuleMetaData() {
- return new ShardingSphereRuleMetaData(new
LinkedList<>(Collections.singleton(mockTrafficRule())));
+ private ShardingSphereMetaData createMetaData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ ShardingSphereRuleMetaData ruleMetaData = new
ShardingSphereRuleMetaData(new
LinkedList<>(Collections.singleton(mockTrafficRule())));
+ when(metaData.getGlobalRuleMetaData()).thenReturn(ruleMetaData);
+ return metaData;
}
private TrafficRule mockTrafficRule() {
diff --git
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java
index 6be63b66f74..75a8a7abe7d 100644
---
a/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java
+++
b/shardingsphere-kernel/shardingsphere-traffic/shardingsphere-traffic-distsql/shardingsphere-traffic-distsql-handler/src/test/java/org/apache/shardingsphere/traffic/distsql/handler/update/DropTrafficRuleStatementUpdaterTest.java
@@ -19,6 +19,7 @@ package
org.apache.shardingsphere.traffic.distsql.handler.update;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import
org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.traffic.api.config.TrafficRuleConfiguration;
import
org.apache.shardingsphere.traffic.api.config.TrafficStrategyConfiguration;
@@ -43,17 +44,17 @@ public final class DropTrafficRuleStatementUpdaterTest {
@Test(expected = RequiredRuleMissedException.class)
public void assertExecuteForNotExistedRuleWithoutIfExists() throws
SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
DropTrafficRuleStatementUpdater updater = new
DropTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
DropTrafficRuleStatement(false, Collections.singleton("not_existed_rule")));
+ updater.executeUpdate(metaData, new DropTrafficRuleStatement(false,
Collections.singleton("not_existed_rule")));
}
@Test
public void assertExecuteForNotExistedRuleWithIfExists() throws
SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
DropTrafficRuleStatementUpdater updater = new
DropTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new DropTrafficRuleStatement(true,
Collections.singleton("rule_name_3")));
- TrafficRuleConfiguration updatedConfig =
ruleMetaData.getSingleRule(TrafficRule.class).getConfiguration();
+ updater.executeUpdate(metaData, new DropTrafficRuleStatement(true,
Collections.singleton("rule_name_3")));
+ TrafficRuleConfiguration updatedConfig =
metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class).getConfiguration();
assertThat(updatedConfig.getTrafficStrategies().size(), is(2));
assertThat(updatedConfig.getLoadBalancers().size(), is(2));
assertThat(updatedConfig.getTrafficAlgorithms().size(), is(2));
@@ -61,10 +62,10 @@ public final class DropTrafficRuleStatementUpdaterTest {
@Test
public void assertExecute() throws SQLException {
- ShardingSphereRuleMetaData ruleMetaData = createRuleMetaData();
+ ShardingSphereMetaData metaData = createMetaData();
DropTrafficRuleStatementUpdater updater = new
DropTrafficRuleStatementUpdater();
- updater.executeUpdate(ruleMetaData, new
DropTrafficRuleStatement(false, Collections.singleton("rule_name_1")));
- TrafficRuleConfiguration updatedConfig =
ruleMetaData.getSingleRule(TrafficRule.class).getConfiguration();
+ updater.executeUpdate(metaData, new DropTrafficRuleStatement(false,
Collections.singleton("rule_name_1")));
+ TrafficRuleConfiguration updatedConfig =
metaData.getGlobalRuleMetaData().getSingleRule(TrafficRule.class).getConfiguration();
assertThat(updatedConfig.getTrafficStrategies().size(), is(1));
assertThat(updatedConfig.getLoadBalancers().size(), is(1));
assertThat(updatedConfig.getTrafficAlgorithms().size(), is(1));
@@ -73,10 +74,12 @@ public final class DropTrafficRuleStatementUpdaterTest {
assertNotNull(updatedConfig.getLoadBalancers().get("load_balancer_2"));
}
- private ShardingSphereRuleMetaData createRuleMetaData() {
+ private ShardingSphereMetaData createMetaData() {
TrafficRule trafficRule = mock(TrafficRule.class);
when(trafficRule.getConfiguration()).thenReturn(createTrafficRuleConfiguration());
- return new ShardingSphereRuleMetaData(new
LinkedList<>(Collections.singleton(trafficRule)));
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class);
+ when(metaData.getGlobalRuleMetaData()).thenReturn(new
ShardingSphereRuleMetaData(new
LinkedList<>(Collections.singleton(trafficRule))));
+ return metaData;
}
private TrafficRuleConfiguration createTrafficRuleConfiguration() {
diff --git a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/pom.xml
index 1cd096cf3ef..e06a4e8b704 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
+++ b/shardingsphere-kernel/shardingsphere-transaction/pom.xml
@@ -32,5 +32,6 @@
<module>shardingsphere-transaction-api</module>
<module>shardingsphere-transaction-core</module>
<module>shardingsphere-transaction-type</module>
+ <module>shardingsphere-transaction-distsql</module>
</modules>
</project>
diff --git a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/pom.xml
similarity index 80%
copy from shardingsphere-kernel/shardingsphere-transaction/pom.xml
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/pom.xml
index 1cd096cf3ef..76c7ca070ef 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/pom.xml
@@ -21,16 +21,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-kernel</artifactId>
+ <artifactId>shardingsphere-transaction</artifactId>
<version>5.1.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-transaction</artifactId>
+ <artifactId>shardingsphere-transaction-distsql</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
- <module>shardingsphere-transaction-api</module>
- <module>shardingsphere-transaction-core</module>
- <module>shardingsphere-transaction-type</module>
+ <module>shardingsphere-transaction-distsql-statement</module>
+ <module>shardingsphere-transaction-distsql-parser</module>
+ <module>shardingsphere-transaction-distsql-handler</module>
</modules>
</project>
diff --git a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/pom.xml
similarity index 60%
copy from shardingsphere-kernel/shardingsphere-transaction/pom.xml
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/pom.xml
index 1cd096cf3ef..32a9b714fbd 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/pom.xml
@@ -21,16 +21,27 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-kernel</artifactId>
+ <artifactId>shardingsphere-transaction-distsql</artifactId>
<version>5.1.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-transaction</artifactId>
- <packaging>pom</packaging>
+ <artifactId>shardingsphere-transaction-distsql-handler</artifactId>
<name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-transaction-api</module>
- <module>shardingsphere-transaction-core</module>
- <module>shardingsphere-transaction-type</module>
- </modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+
<artifactId>shardingsphere-transaction-distsql-statement</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleQueryResultSet.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleQueryResultSet.java
new file mode 100644
index 00000000000..809154d4ee6
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleQueryResultSet.java
@@ -0,0 +1,74 @@
+/*
+ * 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.transaction.distsql.handler.query;
+
+import
org.apache.shardingsphere.infra.distsql.query.GlobalRuleDistSQLResultSet;
+import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.util.props.PropertiesConverter;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.queryable.ShowTransactionRuleStatement;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * Query result set for transaction rule.
+ */
+public final class TransactionRuleQueryResultSet implements
GlobalRuleDistSQLResultSet {
+
+ private static final String DEFAULT_TYPE = "default_type";
+
+ private static final String PROVIDER_TYPE = "provider_type";
+
+ private static final String PROPS = "props";
+
+ private Iterator<Collection<Object>> data = Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereRuleMetaData ruleMetaData, final
SQLStatement sqlStatement) {
+ ruleMetaData.findSingleRule(TransactionRule.class).ifPresent(optional
-> data = buildData(optional).iterator());
+ }
+
+ private Collection<Collection<Object>> buildData(final TransactionRule
rule) {
+ return Collections.singleton(Arrays.asList(
+ rule.getDefaultType().name(), null != rule.getProviderType() ?
rule.getProviderType() : "", null != rule.getProps() ?
PropertiesConverter.convert(rule.getProps()) : ""));
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList(DEFAULT_TYPE, PROVIDER_TYPE, PROPS);
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ return data.next();
+ }
+
+ @Override
+ public String getType() {
+ return ShowTransactionRuleStatement.class.getName();
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdater.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpd
[...]
new file mode 100644
index 00000000000..0f761e8f290
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdater.java
@@ -0,0 +1,54 @@
+/*
+ * 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.transaction.distsql.handler.update;
+
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.util.Collection;
+
+/**
+ * Alter transaction rule statement handler.
+ */
+public final class AlterTransactionRuleStatementUpdater implements
GlobalRuleRALUpdater {
+
+ @Override
+ public void executeUpdate(final ShardingSphereMetaData metaData, final
SQLStatement sqlStatement) throws DistSQLException {
+ Collection<ShardingSphereRule> globalRules =
metaData.getGlobalRuleMetaData().getRules();
+ globalRules.stream().filter(each -> each instanceof
TransactionRule).forEach(each -> ((TransactionRule) each).closeStaleResource());
+ globalRules.removeIf(each -> each instanceof TransactionRule);
+ TransactionRuleConfiguration toBeAlteredRuleConfig =
createToBeAlteredRuleConfiguration(sqlStatement);
+ globalRules.add(new TransactionRule(toBeAlteredRuleConfig,
metaData.getDatabases(), null));
+ }
+
+ private TransactionRuleConfiguration
createToBeAlteredRuleConfiguration(final SQLStatement sqlStatement) {
+ AlterTransactionRuleStatement ruleStatement =
(AlterTransactionRuleStatement) sqlStatement;
+ return new
TransactionRuleConfiguration(ruleStatement.getDefaultType(),
ruleStatement.getProvider().getProviderType(),
ruleStatement.getProvider().getProps());
+ }
+
+ @Override
+ public String getType() {
+ return AlterTransactionRuleStatement.class.getName();
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
new file mode 100644
index 00000000000..a2c6c413273
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.transaction.distsql.handler.query.TransactionRuleQueryResultSet
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater
new file mode 100644
index 00000000000..481663dfe8a
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.transaction.distsql.handler.update.AlterTransactionRuleStatementUpdater
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleQueryResultSetTest.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleQueryResultSetTest.java
new file mode 100644
index 00000000000..0bc0f90551b
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/query/TransactionRuleQueryResultSetTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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.transaction.distsql.handler.query;
+
+import org.apache.shardingsphere.infra.instance.InstanceContext;
+import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.queryable.ShowTransactionRuleStatement;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+import org.junit.Test;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+public final class TransactionRuleQueryResultSetTest {
+
+ @Test
+ public void assertExecuteWithXA() {
+ TransactionRuleQueryResultSet resultSet = new
TransactionRuleQueryResultSet();
+ ShardingSphereRuleMetaData ruleMetaData =
createGlobalRuleMetaData("XA", "Atomikos", createProperties());
+ resultSet.init(ruleMetaData, mock(ShowTransactionRuleStatement.class));
+ Collection<Object> actual = resultSet.getRowData();
+ Iterator<Object> rowData = actual.iterator();
+ assertThat(actual.size(), is(3));
+ assertThat(rowData.next(), is("XA"));
+ assertThat(rowData.next(), is("Atomikos"));
+ String props = (String) rowData.next();
+ assertTrue(props.contains("host=127.0.0.1"));
+ assertTrue(props.contains("databaseName=jbossts"));
+ }
+
+ @Test
+ public void assertExecuteWithLocal() {
+ TransactionRuleQueryResultSet resultSet = new
TransactionRuleQueryResultSet();
+ ShardingSphereRuleMetaData ruleMetaData =
createGlobalRuleMetaData("LOCAL", null, null);
+ resultSet.init(ruleMetaData, mock(ShowTransactionRuleStatement.class));
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(3));
+ assertTrue(actual.contains("LOCAL"));
+ assertTrue(actual.contains(""));
+ }
+
+ private ShardingSphereRuleMetaData createGlobalRuleMetaData(final String
defaultType, final String providerType, final Properties props) {
+ TransactionRule rule = new TransactionRule(new
TransactionRuleConfiguration(defaultType, providerType, props),
Collections.emptyMap(), mock(InstanceContext.class));
+ return new ShardingSphereRuleMetaData(Collections.singleton(rule));
+ }
+
+ private Properties createProperties() {
+ Properties result = new Properties();
+ result.setProperty("host", "127.0.0.1");
+ result.setProperty("databaseName", "jbossts");
+ return result;
+ }
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterTransactionRuleHandlerTest.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java
similarity index 54%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterTransactionRuleHandlerTest.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java
index f7662c12019..830d98da831 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterTransactionRuleHandlerTest.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-handler/src/test/java/org/apache/shardingsphere/transaction/distsql/handler/update/AlterTransactionRuleStatementUpdaterTest.java
@@ -15,31 +15,23 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
+package org.apache.shardingsphere.transaction.distsql.handler.update;
-import com.atomikos.jdbc.AtomikosDataSourceBean;
-import
org.apache.shardingsphere.distsql.parser.segment.TransactionProviderSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
import org.apache.shardingsphere.infra.instance.InstanceContext;
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
+import org.apache.shardingsphere.infra.util.props.PropertiesConverter;
import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
import org.apache.shardingsphere.transaction.core.TransactionType;
+import
org.apache.shardingsphere.transaction.distsql.parser.segment.TransactionProviderSegment;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import javax.sql.DataSource;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -53,17 +45,32 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public final class AlterTransactionRuleHandlerTest extends
ProxyContextRestorer {
+public final class AlterTransactionRuleStatementUpdaterTest {
- @Mock
- private ContextManager contextManager;
+ @Test
+ public void assertExecuteWithXA() throws DistSQLException {
+ AlterTransactionRuleStatementUpdater updater = new
AlterTransactionRuleStatementUpdater();
+ ShardingSphereMetaData metaData = createMetaData();
+ updater.executeUpdate(metaData, new
AlterTransactionRuleStatement("XA", new TransactionProviderSegment("Atomikos",
createProperties())));
+ TransactionRule updatedRule =
metaData.getGlobalRuleMetaData().getSingleRule(TransactionRule.class);
+ assertThat(updatedRule.getDefaultType(), is(TransactionType.XA));
+ assertThat(updatedRule.getProviderType(), is("Atomikos"));
+ assertTrue(updatedRule.getDatabases().containsKey("foo_db"));
+ assertTrue(null != updatedRule.getProps() &&
!updatedRule.getProps().isEmpty());
+ String props = PropertiesConverter.convert(updatedRule.getProps());
+ assertTrue(props.contains("host=127.0.0.1"));
+ assertTrue(props.contains("databaseName=jbossts"));
+ }
- @Before
- public void before() {
- MetaDataContexts metaDataContexts = new
MetaDataContexts(mock(MetaDataPersistService.class, RETURNS_DEEP_STUBS),
createMetaData());
-
when(contextManager.getMetaDataContexts()).thenReturn(metaDataContexts);
- ProxyContext.init(contextManager);
+ @Test
+ public void assertExecuteWithLocal() throws DistSQLException {
+ AlterTransactionRuleStatementUpdater updater = new
AlterTransactionRuleStatementUpdater();
+ ShardingSphereMetaData metaData = createMetaData();
+ updater.executeUpdate(metaData, new
AlterTransactionRuleStatement("LOCAL", new TransactionProviderSegment("", new
Properties())));
+ TransactionRule updatedRule =
metaData.getGlobalRuleMetaData().getSingleRule(TransactionRule.class);
+ assertThat(updatedRule.getDefaultType(), is(TransactionType.LOCAL));
+ assertThat(updatedRule.getProviderType(), is(""));
+ assertTrue(updatedRule.getDatabases().containsKey("foo_db"));
}
private ShardingSphereMetaData createMetaData() {
@@ -73,22 +80,19 @@ public final class AlterTransactionRuleHandlerTest extends
ProxyContextRestorer
}
private TransactionRule createTransactionRule(final Map<String,
ShardingSphereDatabase> databases) {
- return new TransactionRule(new TransactionRuleConfiguration("LOCAL",
null, new Properties()), databases, mock(InstanceContext.class));
+ return new TransactionRule(new TransactionRuleConfiguration("BASE",
null, new Properties()), databases, mock(InstanceContext.class));
}
private ShardingSphereDatabase mockDatabase() {
ShardingSphereDatabase result = mock(ShardingSphereDatabase.class,
RETURNS_DEEP_STUBS);
-
when(result.getResource().getDataSources()).thenReturn(Collections.singletonMap("foo_ds",
mock(AtomikosDataSourceBean.class, RETURNS_DEEP_STUBS)));
+
when(result.getResource().getDataSources()).thenReturn(Collections.singletonMap("foo_ds",
mock(DataSource.class, RETURNS_DEEP_STUBS)));
return result;
}
- @Test
- public void assertUpdate() {
- AlterTransactionRuleHandler handler = new
AlterTransactionRuleHandler();
- handler.init(new AlterTransactionRuleStatement("BASE", new
TransactionProviderSegment(null, new Properties())),
mock(ConnectionSession.class, RETURNS_DEEP_STUBS));
- handler.update(contextManager);
- TransactionRule updatedRule =
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TransactionRule.class);
- assertThat(updatedRule.getDefaultType(), is(TransactionType.BASE));
- assertTrue(updatedRule.getDatabases().containsKey("foo_db"));
+ private Properties createProperties() {
+ Properties result = new Properties();
+ result.setProperty("host", "127.0.0.1");
+ result.setProperty("databaseName", "jbossts");
+ return result;
}
}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/pom.xml
new file mode 100644
index 00000000000..d5478e77531
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-distsql</artifactId>
+ <version>5.1.3-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-transaction-distsql-parser</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+
<artifactId>shardingsphere-transaction-distsql-statement</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>antlr</id>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ <configuration>
+
<libDirectory>src/main/antlr4/imports/transaction/</libDirectory>
+ <listener>false</listener>
+ <visitor>true</visitor>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Alphabet.g4
similarity index 56%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Alphabet.g4
index f68cdc3d0a9..f7603cc7e63 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Alphabet.g4
@@ -15,12 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+lexer grammar Alphabet;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
-/**
- * Show transaction rule statement.
- */
-public final class ShowTransactionRuleStatement extends QueryableRALStatement {
-}
+fragment A: [Aa];
+fragment B: [Bb];
+fragment C: [Cc];
+fragment D: [Dd];
+fragment E: [Ee];
+fragment F: [Ff];
+fragment G: [Gg];
+fragment H: [Hh];
+fragment I: [Ii];
+fragment J: [Jj];
+fragment K: [Kk];
+fragment L: [Ll];
+fragment M: [Mm];
+fragment N: [Nn];
+fragment O: [Oo];
+fragment P: [Pp];
+fragment Q: [Qq];
+fragment R: [Rr];
+fragment S: [Ss];
+fragment T: [Tt];
+fragment U: [Uu];
+fragment V: [Vv];
+fragment W: [Ww];
+fragment X: [Xx];
+fragment Y: [Yy];
+fragment Z: [Zz];
+fragment UL_: '_';
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Keyword.g4
similarity index 70%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Keyword.g4
index f68cdc3d0a9..6930ae3d436 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Keyword.g4
@@ -15,12 +15,42 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+lexer grammar Keyword;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import Alphabet;
-/**
- * Show transaction rule statement.
- */
-public final class ShowTransactionRuleStatement extends QueryableRALStatement {
-}
+WS
+ : [ \t\r\n] + ->skip
+ ;
+
+SHOW
+ : S H O W
+ ;
+
+RULE
+ : R U L E
+ ;
+
+TRANSACTION
+ : T R A N S A C T I O N
+ ;
+
+ALTER
+ : A L T E R
+ ;
+
+DEFAULT
+ : D E F A U L T
+ ;
+
+TYPE
+ : T Y P E
+ ;
+
+NAME
+ : N A M E
+ ;
+
+PROPERTIES
+ : P R O P E R T I E S
+ ;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Literals.g4
similarity index 73%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Literals.g4
index f68cdc3d0a9..586f6d635fa 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Literals.g4
@@ -15,12 +15,16 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+lexer grammar Literals;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import Alphabet, Symbol;
-/**
- * Show transaction rule statement.
- */
-public final class ShowTransactionRuleStatement extends QueryableRALStatement {
-}
+IDENTIFIER
+ : [A-Za-z_$0-9]*?[A-Za-z_$]+?[A-Za-z_$0-9]*
+ | BQ ~'`'+ BQ
+ ;
+
+STRING
+ : (DQ ('\\'. | '""' | ~('"' | '\\'))* DQ)
+ | (SQ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ)
+ ;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/RALStatement.g4
similarity index 57%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/RALStatement.g4
index a6a45d3aeb5..1187ab34dad 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/RALStatement.g4
@@ -15,22 +15,42 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+grammar RALStatement;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import Keyword, Literals;
-import java.util.Properties;
+showTransactionRule
+ : SHOW TRANSACTION RULE
+ ;
-/**
- * Transaction provider segment.
- */
-@RequiredArgsConstructor
-@Getter
-public final class TransactionProviderSegment implements ASTNode {
-
- private final String providerType;
-
- private final Properties props;
-}
+alterTransactionRule
+ : ALTER TRANSACTION RULE transactionRuleDefinition
+ ;
+
+transactionRuleDefinition
+ : LP DEFAULT EQ defaultType (COMMA providerDefinition)?
+ ;
+
+providerDefinition
+ : TYPE LP NAME EQ providerName (COMMA propertiesDefinition)? RP
+ ;
+
+defaultType
+ : STRING
+ ;
+
+providerName
+ : STRING
+ ;
+
+propertiesDefinition
+ : PROPERTIES LP properties? RP
+ ;
+
+properties
+ : property (COMMA property)*
+ ;
+
+property
+ : key=STRING EQ value=STRING
+ ;
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Symbol.g4
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Symbol.g4
new file mode 100644
index 00000000000..3322b09bb3a
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/imports/transaction/Symbol.g4
@@ -0,0 +1,62 @@
+/*
+ * 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.
+ */
+
+lexer grammar Symbol;
+
+AND: '&&';
+OR: '||';
+NOT: '!';
+TILDE: '~';
+VERTICALBAR: '|';
+AMPERSAND: '&';
+SIGNEDLEFTSHIFT: '<<';
+SIGNEDRIGHTSHIFT: '>>';
+CARET: '^';
+MOD: '%';
+COLON: ':';
+PLUS: '+';
+MINUS: '-';
+ASTERISK: '*';
+SLASH: '/';
+BACKSLASH: '\\';
+DOT: '.';
+DOTASTERISK: '.*';
+SAFEEQ: '<=>';
+DEQ: '==';
+EQ: '=';
+NEQ: '<>' | '!=';
+GT: '>';
+GTE: '>=';
+LT: '<';
+LTE: '<=';
+POUND: '#';
+LP: '(';
+RP: ')';
+LBE: '{';
+RBE: '}';
+LBT: '[';
+RBT: ']';
+COMMA: ',';
+DQ: '"';
+SQ: '\'';
+BQ: '`';
+QUESTION: '?';
+AT: '@';
+SEMI: ';';
+JSONSEPARATOR: '->>';
+UL: '_';
+DL: '$';
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/TransactionDistSQLStatement.g4
similarity index 73%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/TransactionDistSQLStatement.g4
index f68cdc3d0a9..8b7bf802b94 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/TransactionDistSQLStatement.g4
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+grammar TransactionDistSQLStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import Symbol, RALStatement;
-/**
- * Show transaction rule statement.
- */
-public final class ShowTransactionRuleStatement extends QueryableRALStatement {
-}
+execute
+ : (showTransactionRule
+ | alterTransactionRule
+ ) SEMI?
+ ;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLLexer.java
similarity index 62%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLLexer.java
index a6a45d3aeb5..c760b79912b 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLLexer.java
@@ -15,22 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+package org.apache.shardingsphere.transaction.distsql.parser.core;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-
-import java.util.Properties;
+import org.antlr.v4.runtime.CharStream;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
/**
- * Transaction provider segment.
+ * SQL lexer for transaction dist SQL.
*/
-@RequiredArgsConstructor
-@Getter
-public final class TransactionProviderSegment implements ASTNode {
-
- private final String providerType;
+public final class TransactionDistSQLLexer extends
TransactionDistSQLStatementLexer implements SQLLexer {
- private final Properties props;
+ public TransactionDistSQLLexer(final CharStream input) {
+ super(input);
+ }
}
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLParser.java
similarity index 54%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLParser.java
index a6a45d3aeb5..a8f0406f15f 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLParser.java
@@ -15,22 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+package org.apache.shardingsphere.transaction.distsql.parser.core;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.TokenStream;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
-
-import java.util.Properties;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
/**
- * Transaction provider segment.
+ * SQL parser for transaction dist SQL.
*/
-@RequiredArgsConstructor
-@Getter
-public final class TransactionProviderSegment implements ASTNode {
+public final class TransactionDistSQLParser extends
TransactionDistSQLStatementParser implements SQLParser {
- private final String providerType;
+ public TransactionDistSQLParser(final TokenStream input) {
+ super(input);
+ }
- private final Properties props;
+ @Override
+ public ASTNode parse() {
+ return new ParseASTNode(execute(), (CommonTokenStream)
getTokenStream());
+ }
}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLStatementVisitor.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLStatementVisitor.java
new file mode 100644
index 00000000000..0b34ed6ade8
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/core/TransactionDistSQLStatementVisitor.java
@@ -0,0 +1,81 @@
+/*
+ * 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.transaction.distsql.parser.core;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementBaseVisitor;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser.AlterTransactionRuleContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser.PropertiesDefinitionContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser.PropertyContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser.ProviderDefinitionContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser.ShowTransactionRuleContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.TransactionDistSQLStatementParser.TransactionRuleDefinitionContext;
+import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
+import
org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
+import
org.apache.shardingsphere.transaction.distsql.parser.segment.TransactionProviderSegment;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.queryable.ShowTransactionRuleStatement;
+
+import java.util.Properties;
+
+/**
+ * SQL statement visitor for transaction dist SQL.
+ */
+public final class TransactionDistSQLStatementVisitor extends
TransactionDistSQLStatementBaseVisitor<ASTNode> implements SQLVisitor {
+
+ @Override
+ public ASTNode visitShowTransactionRule(final ShowTransactionRuleContext
ctx) {
+ return new ShowTransactionRuleStatement();
+ }
+
+ @Override
+ public ASTNode visitAlterTransactionRule(final AlterTransactionRuleContext
ctx) {
+ return visit(ctx.transactionRuleDefinition());
+ }
+
+ @Override
+ public ASTNode visitTransactionRuleDefinition(final
TransactionRuleDefinitionContext ctx) {
+ String defaultType = getIdentifierValue(ctx.defaultType());
+ if (null != ctx.providerDefinition()) {
+ TransactionProviderSegment provider = (TransactionProviderSegment)
visit(ctx.providerDefinition());
+ return new AlterTransactionRuleStatement(defaultType, provider);
+ }
+ return new AlterTransactionRuleStatement(defaultType, new
TransactionProviderSegment(null, null));
+ }
+
+ @Override
+ public ASTNode visitProviderDefinition(final ProviderDefinitionContext
ctx) {
+ return new
TransactionProviderSegment(getIdentifierValue(ctx.providerName()),
getProperties(ctx.propertiesDefinition()));
+ }
+
+ private Properties getProperties(final PropertiesDefinitionContext ctx) {
+ Properties result = new Properties();
+ if (null == ctx || null == ctx.properties()) {
+ return result;
+ }
+ for (PropertyContext each : ctx.properties().property()) {
+
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()),
IdentifierValue.getQuotedContent(each.value.getText()));
+ }
+ return result;
+ }
+
+ private String getIdentifierValue(final ParseTree context) {
+ return null == context ? null : new
IdentifierValue(context.getText()).getValue();
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/facade/TransactionDistSQLStatementParserFacade.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/facade/TransactionDistSQLStatementParser
[...]
new file mode 100644
index 00000000000..1d932eccbf7
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/facade/TransactionDistSQLStatementParserFacade.java
@@ -0,0 +1,52 @@
+/*
+ * 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.transaction.distsql.parser.facade;
+
+import
org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
+import
org.apache.shardingsphere.transaction.distsql.parser.core.TransactionDistSQLLexer;
+import
org.apache.shardingsphere.transaction.distsql.parser.core.TransactionDistSQLParser;
+import
org.apache.shardingsphere.transaction.distsql.parser.core.TransactionDistSQLStatementVisitor;
+
+/**
+ * SQL parser facade for transaction dist SQL statement.
+ */
+public final class TransactionDistSQLStatementParserFacade implements
FeaturedDistSQLStatementParserFacade {
+
+ @Override
+ public Class<? extends SQLLexer> getLexerClass() {
+ return TransactionDistSQLLexer.class;
+ }
+
+ @Override
+ public Class<? extends SQLParser> getParserClass() {
+ return TransactionDistSQLParser.class;
+ }
+
+ @Override
+ public Class<? extends SQLVisitor> getVisitorClass() {
+ return TransactionDistSQLStatementVisitor.class;
+ }
+
+ @Override
+ public String getType() {
+ return "transaction";
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDis
[...]
new file mode 100644
index 00000000000..1b2f37dc1b7
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.transaction.distsql.parser.facade.TransactionDistSQLStatementParserFacade
diff --git a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/pom.xml
similarity index 76%
copy from shardingsphere-kernel/shardingsphere-transaction/pom.xml
copy to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/pom.xml
index 1cd096cf3ef..fefc1e03cab 100644
--- a/shardingsphere-kernel/shardingsphere-transaction/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/pom.xml
@@ -21,16 +21,17 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-kernel</artifactId>
+ <artifactId>shardingsphere-transaction-distsql</artifactId>
<version>5.1.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-transaction</artifactId>
- <packaging>pom</packaging>
+ <artifactId>shardingsphere-transaction-distsql-statement</artifactId>
<name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-transaction-api</module>
- <module>shardingsphere-transaction-core</module>
- <module>shardingsphere-transaction-type</module>
- </modules>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-distsql-statement</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/segment/TransactionProviderSegment.java
similarity index 94%
rename from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/segment/TransactionProviderSegment.java
index a6a45d3aeb5..78f8cf4cc2c 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/TransactionProviderSegment.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/segment/TransactionProviderSegment.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+package org.apache.shardingsphere.transaction.distsql.parser.segment;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/statement/queryable/ShowTransactionRuleStatement.java
similarity index 87%
rename from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/statement/queryable/ShowTransactionRuleStatement.java
index f68cdc3d0a9..fb0a4e55f19 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowTransactionRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/statement/queryable/ShowTransactionRuleStatement.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+package
org.apache.shardingsphere.transaction.distsql.parser.statement.queryable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableGlobalRuleRALStatement;
/**
* Show transaction rule statement.
*/
-public final class ShowTransactionRuleStatement extends QueryableRALStatement {
+public final class ShowTransactionRuleStatement extends
QueryableGlobalRuleRALStatement {
}
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/updatable/AlterTransactionRuleStatement.java
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/statement/updatable/AlterTransactionRuleStatement.java
similarity index 80%
rename from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/updatable/AlterTransactionRuleStatement.java
rename to
shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/statement/updatable/AlterTransactionRuleStatement.java
index 3f23830cfae..78468b0b777 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/updatable/AlterTransactionRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-distsql/shardingsphere-transaction-distsql-statement/src/main/java/org/apache/shardingsphere/transaction/distsql/parser/statement/updatable/AlterTransactionRuleStatement.java
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.updatable;
+package
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.segment.TransactionProviderSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableRALStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableGlobalRuleRALStatement;
+import
org.apache.shardingsphere.transaction.distsql.parser.segment.TransactionProviderSegment;
/**
- * Alter Transaction rule statement.
+ * Alter transaction rule statement.
*/
@RequiredArgsConstructor
@Getter
-public final class AlterTransactionRuleStatement extends UpdatableRALStatement
{
+public final class AlterTransactionRuleStatement extends
UpdatableGlobalRuleRALStatement {
private final String defaultType;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index b99c1ae3d65..ab4d0762c2f 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -138,6 +138,11 @@
<artifactId>shardingsphere-traffic-distsql-handler</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-distsql-handler</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-authority-core</artifactId>
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
index c98811bac69..21160b25e99 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
@@ -32,12 +32,10 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowMode
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLTranslatorRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetadataStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.QueryableScalingRALStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.UpdatableScalingRALStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ApplyDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.DiscardDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ImportDatabaseConfigurationStatement;
@@ -64,10 +62,8 @@ import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.Sho
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowSQLParserRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowSQLTranslatorRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowTableMetadataHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowTransactionRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowVariableHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.AlterSQLParserRuleHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.AlterTransactionRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ApplyDistSQLHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.DiscardDistSQLHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ImportDatabaseConfigurationHandler;
@@ -102,7 +98,6 @@ public final class RALBackendHandlerFactory {
HANDLERS.put(SetReadwriteSplittingStatusStatement.class,
SetReadwriteSplittingStatusHandler.class);
HANDLERS.put(RefreshTableMetadataStatement.class,
RefreshTableMetadataHandler.class);
HANDLERS.put(AlterSQLParserRuleStatement.class,
AlterSQLParserRuleHandler.class);
- HANDLERS.put(AlterTransactionRuleStatement.class,
AlterTransactionRuleHandler.class);
HANDLERS.put(PrepareDistSQLStatement.class,
PrepareDistSQLHandler.class);
HANDLERS.put(ApplyDistSQLStatement.class, ApplyDistSQLHandler.class);
HANDLERS.put(DiscardDistSQLStatement.class,
DiscardDistSQLHandler.class);
@@ -113,7 +108,6 @@ public final class RALBackendHandlerFactory {
HANDLERS.put(ShowReadwriteSplittingReadResourcesStatement.class,
ShowReadwriteSplittingReadResourcesHandler.class);
HANDLERS.put(ShowSQLParserRuleStatement.class,
ShowSQLParserRuleHandler.class);
HANDLERS.put(ShowTableMetadataStatement.class,
ShowTableMetadataHandler.class);
- HANDLERS.put(ShowTransactionRuleStatement.class,
ShowTransactionRuleHandler.class);
HANDLERS.put(ExportDatabaseConfigurationStatement.class,
ExportDatabaseConfigurationHandler.class);
HANDLERS.put(ConvertYamlConfigurationStatement.class,
ConvertYamlConfigurationHandler.class);
HANDLERS.put(ShowSQLTranslatorRuleStatement.class,
ShowSQLTranslatorRuleHandler.class);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableGlobalRuleRALBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableGlobalRuleRALBackendHandler.java
index c141f4ee0b3..7fe74019a07 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableGlobalRuleRALBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/UpdatableGlobalRuleRALBackendHandler.java
@@ -43,7 +43,7 @@ public final class UpdatableGlobalRuleRALBackendHandler
implements ProxyBackendH
@Override
public ResponseHeader execute() throws SQLException {
-
updater.executeUpdate(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData(),
sqlStatement);
+
updater.executeUpdate(ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(),
sqlStatement);
persistNewRuleConfigurations();
return new UpdateResponseHeader(sqlStatement);
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandler.java
deleted file mode 100644
index 4a437e3cb2e..00000000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandler.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
-
-import com.google.gson.Gson;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
-import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.QueryableRALBackendHandler;
-import org.apache.shardingsphere.transaction.rule.TransactionRule;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * Show transaction rule handler.
- */
-public final class ShowTransactionRuleHandler extends
QueryableRALBackendHandler<ShowTransactionRuleStatement> {
-
- private static final String DEFAULT_TYPE = "default_type";
-
- private static final String PROVIDER_TYPE = "provider_type";
-
- private static final String PROPS = "props";
-
- @Override
- protected Collection<String> getColumnNames() {
- return Arrays.asList(DEFAULT_TYPE, PROVIDER_TYPE, PROPS);
- }
-
- @Override
- protected Collection<LocalDataQueryResultRow> getRows(final ContextManager
contextManager) {
- TransactionRule rule =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(TransactionRule.class);
- return Collections.singleton(new LocalDataQueryResultRow(
- rule.getDefaultType().name(), null == rule.getProviderType() ?
"" : rule.getProviderType(), null == rule.getProps() ? "" : new
Gson().toJson(rule.getProps())));
- }
-}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterTransactionRuleHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterTransactionRuleHandler.java
deleted file mode 100644
index 7d90f52c965..00000000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterTransactionRuleHandler.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
-
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
-import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.UpdatableRALBackendHandler;
-import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
-import org.apache.shardingsphere.transaction.rule.TransactionRule;
-
-import java.util.Collection;
-import java.util.Map;
-
-/**
- * Alter transaction rule statement handler.
- */
-public final class AlterTransactionRuleHandler extends
UpdatableRALBackendHandler<AlterTransactionRuleStatement> {
-
- @Override
- protected void update(final ContextManager contextManager) {
- replaceNewRule(contextManager);
- persistNewRuleConfigurations();
- }
-
- private void replaceNewRule(final ContextManager contextManager) {
- TransactionRuleConfiguration toBeAlteredRuleConfig =
createToBeAlteredRuleConfiguration();
- Collection<ShardingSphereRule> globalRules =
contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules();
- globalRules.stream().filter(each -> each instanceof
TransactionRule).forEach(each -> ((TransactionRule) each).closeStaleResource());
- globalRules.removeIf(each -> each instanceof TransactionRule);
- Map<String, ShardingSphereDatabase> databases =
contextManager.getMetaDataContexts().getMetaData().getDatabases();
- TransactionRule transactionRule = new
TransactionRule(toBeAlteredRuleConfig, databases,
contextManager.getInstanceContext());
- globalRules.add(transactionRule);
- }
-
- private TransactionRuleConfiguration createToBeAlteredRuleConfiguration() {
- AlterTransactionRuleStatement sqlStatement = getSqlStatement();
- return new TransactionRuleConfiguration(sqlStatement.getDefaultType(),
sqlStatement.getProvider().getProviderType(),
sqlStatement.getProvider().getProps());
- }
-
- private void persistNewRuleConfigurations() {
- MetaDataContexts metaDataContexts =
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
-
metaDataContexts.getPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(),
true);
- }
-}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ApplyDistSQLHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ApplyDistSQLHandler.java
index b0d1dc638bc..e28e8e4bf16 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ApplyDistSQLHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/ApplyDistSQLHandler.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.UpdatableRALBackendHandler;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
/**
- * Apply dist sql statement handler.
+ * Apply dist SQL statement handler.
*/
public final class ApplyDistSQLHandler extends
UpdatableRALBackendHandler<AlterTransactionRuleStatement> {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/DiscardDistSQLHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/DiscardDistSQLHandler.java
index 39f9bcc13d5..687bfab3f71 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/DiscardDistSQLHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/DiscardDistSQLHandler.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.UpdatableRALBackendHandler;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
/**
- * Discard dist sql statement handler.
+ * Discard dist SQL statement handler.
*/
public final class DiscardDistSQLHandler extends
UpdatableRALBackendHandler<AlterTransactionRuleStatement> {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/PrepareDistSQLHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/PrepareDistSQLHandler.java
index 3b67999bd17..a0ee98e3229 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/PrepareDistSQLHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/PrepareDistSQLHandler.java
@@ -17,12 +17,12 @@
package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterTransactionRuleStatement;
import org.apache.shardingsphere.mode.manager.ContextManager;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.UpdatableRALBackendHandler;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
/**
- * Prepare dist sql statement handler.
+ * Prepare dist SQL statement handler.
*/
public final class PrepareDistSQLHandler extends
UpdatableRALBackendHandler<AlterTransactionRuleStatement> {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
index 7872c210e5b..4a88ae2c324 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/ProxyBackendHandlerFactoryTest.java
@@ -33,6 +33,7 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminQueryBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.admin.DatabaseAdminUpdateBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.data.impl.UnicastDatabaseBackendHandler;
+import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.QueryableGlobalRuleRALBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.QueryableRALBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.hint.HintRALBackendHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.SetVariableHandler;
@@ -251,7 +252,7 @@ public final class ProxyBackendHandlerFactoryTest extends
ProxyContextRestorer {
when(connectionSession.getTransactionStatus().isInTransaction()).thenReturn(true);
String sql = "SHOW TRANSACTION RULE;";
ProxyBackendHandler actual =
ProxyBackendHandlerFactory.newInstance(databaseType, sql, connectionSession);
- assertThat(actual, instanceOf(QueryableRALBackendHandler.class));
+ assertThat(actual,
instanceOf(QueryableGlobalRuleRALBackendHandler.class));
}
@Test
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
deleted file mode 100644
index 904fe187532..00000000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowTransactionRuleHandlerTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
-
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
-import org.apache.shardingsphere.infra.instance.InstanceContext;
-import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
-import
org.apache.shardingsphere.transaction.config.TransactionRuleConfiguration;
-import org.apache.shardingsphere.transaction.rule.TransactionRule;
-import org.junit.Test;
-
-import java.sql.SQLException;
-import java.util.Collections;
-import java.util.List;
-import java.util.Properties;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.hamcrest.CoreMatchers.is;
-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;
-
-public final class ShowTransactionRuleHandlerTest extends ProxyContextRestorer
{
-
- @Test
- public void assertExecuteWithXA() throws SQLException {
- ShowTransactionRuleHandler handler = new ShowTransactionRuleHandler();
- handler.init(new ShowTransactionRuleStatement(), null);
- ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
- ShardingSphereRuleMetaData metaData = createGlobalRuleMetaData("XA",
"Atomikos", getProperties());
-
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(metaData);
- ProxyContext.init(contextManager);
- handler.execute();
- handler.next();
- List<Object> data = handler.getRowData().getData();
- assertThat(data.size(), is(3));
- assertThat(data.get(0), is("XA"));
- assertThat(data.get(1), is("Atomikos"));
- String props = String.valueOf(data.get(2));
- assertThat(props, containsString("\"host\":\"127.0.0.1\""));
- assertThat(props, containsString("\"databaseName\":\"jbossts\""));
- }
-
- @Test
- public void assertExecuteWithLocal() throws SQLException {
- ShowTransactionRuleHandler handler = new ShowTransactionRuleHandler();
- handler.init(new ShowTransactionRuleStatement(), null);
- ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
- ShardingSphereRuleMetaData metaData =
createGlobalRuleMetaData("LOCAL", null, null);
-
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(metaData);
- ProxyContext.init(contextManager);
- handler.execute();
- handler.next();
- List<Object> data = handler.getRowData().getData();
- assertThat(data.size(), is(3));
- assertThat(data.get(0), is("LOCAL"));
- assertThat(data.get(1), is(""));
- assertThat(data.get(2), is(""));
- }
-
- private ShardingSphereRuleMetaData createGlobalRuleMetaData(final String
defaultType, final String providerType, final Properties props) {
- TransactionRule rule = new TransactionRule(new
TransactionRuleConfiguration(defaultType, providerType, props),
Collections.emptyMap(), mock(InstanceContext.class));
- return new ShardingSphereRuleMetaData(Collections.singleton(rule));
- }
-
- private Properties getProperties() {
- Properties result = new Properties();
- result.setProperty("host", "127.0.0.1");
- result.setProperty("databaseName", "jbossts");
- return result;
- }
-}
diff --git a/shardingsphere-test/shardingsphere-parser-test/pom.xml
b/shardingsphere-test/shardingsphere-parser-test/pom.xml
index 0854489ce5a..acde39f165c 100644
--- a/shardingsphere-test/shardingsphere-parser-test/pom.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/pom.xml
@@ -82,6 +82,11 @@
<artifactId>shardingsphere-traffic-distsql-parser</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-transaction-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-shadow-distsql-parser</artifactId>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
index 4ee77bf1a15..5c94ae24567 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
@@ -30,7 +30,6 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowMode
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLTranslatorRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetadataStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVariableStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
@@ -64,6 +63,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowTransactionRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowVariableStatementTestCase;
import
org.apache.shardingsphere.traffic.distsql.parser.statement.queryable.ShowTrafficRulesStatement;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.queryable.ShowTransactionRuleStatement;
/**
* Queryable RAL statement assert.
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
index a8e07856cd8..344c8fd4ef0 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
@@ -31,6 +31,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAs
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.AlterInstanceStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.AlterSQLParserRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.AlterTrafficRuleStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.AlterTransactionRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.CreateTrafficRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.DropTrafficRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.ImportDatabaseConfigurationStatementAssert;
@@ -52,6 +53,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.traffic.distsql.parser.statement.updatable.AlterTrafficRuleStatement;
import
org.apache.shardingsphere.traffic.distsql.parser.statement.updatable.CreateTrafficRuleStatement;
import
org.apache.shardingsphere.traffic.distsql.parser.statement.updatable.DropTrafficRuleStatement;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
/**
* Updatable RAL statement assert.
@@ -87,6 +89,8 @@ public final class UpdatableRALStatementAssert {
AlterTrafficRuleStatementAssert.assertIs(assertContext,
(AlterTrafficRuleStatement) actual, (AlterTrafficRuleStatementTestCase)
expected);
} else if (actual instanceof ImportDatabaseConfigurationStatement) {
ImportDatabaseConfigurationStatementAssert.assertIs(assertContext,
(ImportDatabaseConfigurationStatement) actual,
(ImportDatabaseConfigurationStatementTestCase) expected);
+ } else if (actual instanceof AlterTransactionRuleStatement) {
+ AlterTransactionRuleStatementAssert.assertIs(assertContext,
(AlterTransactionRuleStatement) actual, expected);
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
index 2c3e8640130..813c9c5aa48 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
@@ -19,9 +19,9 @@ package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statemen
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowTransactionRuleStatementTestCase;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.queryable.ShowTransactionRuleStatement;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterTransactionRuleStatementAssert.java
similarity index 66%
copy from
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
copy to
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterTransactionRuleStatementAssert.java
index 2c3e8640130..80db0ae064e 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowTransactionRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterTransactionRuleStatementAssert.java
@@ -15,31 +15,28 @@
* limitations under the License.
*/
-package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable;
+package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable;
-import lombok.AccessLevel;
-import lombok.NoArgsConstructor;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTransactionRuleStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
-import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowTransactionRuleStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+import
org.apache.shardingsphere.transaction.distsql.parser.statement.updatable.AlterTransactionRuleStatement;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
- * Show transaction rule statement assert.
+ * Alter transaction rule statement assert.
*/
-@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public final class ShowTransactionRuleStatementAssert {
+public final class AlterTransactionRuleStatementAssert {
/**
- * Assert show transaction rule statement is correct with expected parser
result.
+ * Assert alter transaction rule statement is correct with expected parser
result.
*
* @param assertContext assert context
- * @param actual actual show transaction rule statement
- * @param expected expected show transaction rule statement test case
+ * @param actual actual alter transaction rule statement
+ * @param expected expected alter transaction rule statement test case
*/
- public static void assertIs(final SQLCaseAssertContext assertContext,
final ShowTransactionRuleStatement actual, final
ShowTransactionRuleStatementTestCase expected) {
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final AlterTransactionRuleStatement actual, final SQLParserTestCase expected) {
if (null == expected) {
assertNull(assertContext.getText("Actual statement should not
exist."), actual);
} else {