This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 30b88097d3d Reuse UnsupportedShardingOperationException (#20558)
30b88097d3d is described below

commit 30b88097d3d3cf58a50c54108e5a9b1f27785708
Author: Liang Zhang <[email protected]>
AuthorDate: Fri Aug 26 16:20:49 2022 +0800

    Reuse UnsupportedShardingOperationException (#20558)
    
    * Reuse UnsupportedShardingOperationException
    
    * Reuse UnsupportedShardingOperationException
    
    * Reuse UnsupportedShardingOperationException
---
 .../validator/ddl/impl/ShardingAlterTableStatementValidator.java    | 3 ++-
 .../validator/ddl/impl/ShardingDropTableStatementValidator.java     | 3 ++-
 .../validator/ddl/impl/ShardingRenameTableStatementValidator.java   | 3 ++-
 .../engine/validator/dml/impl/ShardingCopyStatementValidator.java   | 4 ++--
 .../validator/ddl/ShardingAlterTableStatementValidatorTest.java     | 5 +++--
 .../validator/ddl/ShardingRenameTableStatementValidatorTest.java    | 5 +++--
 .../engine/validator/dml/ShardingCopyStatementValidatorTest.java    | 6 +++---
 .../mode/manager/cluster/ClusterContextManagerBuilder.java          | 4 ++--
 8 files changed, 19 insertions(+), 14 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java
index b81910065ca..1dc752ae725 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingAlterTableStatementValidator.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -46,7 +47,7 @@ public final class ShardingAlterTableStatementValidator 
extends ShardingDDLState
                 : sqlStatementContext.getTablesContext().getTableNames();
         Optional<SimpleTableSegment> renameTable = 
sqlStatementContext.getSqlStatement().getRenameTable();
         if (renameTable.isPresent() && 
containsShardingBroadcastTable(shardingRule, tableNames)) {
-            throw new ShardingSphereException("ALTER TABLE ... RENAME TO ... 
statement can not support sharding tables and broadcast tables.");
+            throw new UnsupportedShardingOperationException("ALTER TABLE ... 
RENAME TO ...", renameTable.get().getTableName().getIdentifier().getValue());
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
index 1fd45d5af8f..7219a8cfb5a 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingDropTableStatementValidator.java
@@ -26,6 +26,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.schema.decorator.model.ShardingSphereSchema;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteMapper;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -53,7 +54,7 @@ public final class ShardingDropTableStatementValidator 
extends ShardingDDLStatem
             validateTableExist(schema, 
sqlStatementContext.getTablesContext().getTables());
         }
         if 
(DropTableStatementHandler.containsCascade(sqlStatementContext.getSqlStatement()))
 {
-            throw new ShardingSphereException("DROP TABLE ... CASCADE 
statement is not supported yet.");
+            throw new UnsupportedShardingOperationException("DROP TABLE ... 
CASCADE", 
sqlStatementContext.getTablesContext().getTables().iterator().next().getTableName().getIdentifier().getValue());
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
index 1e31ac51612..c93515ea840 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/impl/ShardingRenameTableStatementValidator.java
@@ -23,6 +23,7 @@ import 
org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
 import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.ShardingDDLStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.table.RenameTableDefinitionSegment;
@@ -46,7 +47,7 @@ public final class ShardingRenameTableStatementValidator 
extends ShardingDDLStat
                 : sqlStatementContext.getTablesContext().getTableNames();
         List<SimpleTableSegment> renameTables = 
sqlStatementContext.getSqlStatement().getRenameTables().stream().map(RenameTableDefinitionSegment::getRenameTable).collect(Collectors.toList());
         if (!renameTables.isEmpty() && 
containsShardingBroadcastTable(shardingRule, tableNames)) {
-            throw new ShardingSphereException("RENAME TABLE ... TO ... 
statement can not support sharding tables and broadcast tables.");
+            throw new UnsupportedShardingOperationException("RENAME TABLE", 
renameTables.get(0).getTableName().getIdentifier().getValue());
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java
index b13d7b1c33a..75dd07d6bfe 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/main/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/impl/ShardingCopyStatementValidator.java
@@ -19,9 +19,9 @@ package 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl;
 
 import org.apache.shardingsphere.infra.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.dml.ShardingDMLStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.statement.dml.CopyStatement;
@@ -38,7 +38,7 @@ public final class ShardingCopyStatementValidator extends 
ShardingDMLStatementVa
                             final SQLStatementContext<CopyStatement> 
sqlStatementContext, final List<Object> parameters, final 
ShardingSphereDatabase database) {
         String tableName = 
sqlStatementContext.getSqlStatement().getTableSegment().getTableName().getIdentifier().getValue();
         if (shardingRule.isShardingTable(tableName)) {
-            throw new ShardingSphereException("COPY statement can not support 
sharding table %s.", tableName);
+            throw new UnsupportedShardingOperationException("COPY", tableName);
         }
     }
     
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java
index 4d023ca8ea0..89e0586c7e0 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingAlterTableStatementValidatorTest.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteMapper;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingAlterTableStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -59,7 +60,7 @@ public final class ShardingAlterTableStatementValidatorTest {
     @Mock
     private RouteContext routeContext;
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedShardingOperationException.class)
     public void 
assertPreValidateAlterTableWithRenameTableWithShardingTableForPostgreSQL() {
         PostgreSQLAlterTableStatement sqlStatement = new 
PostgreSQLAlterTableStatement();
         sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 
0, new IdentifierValue("t_order"))));
@@ -69,7 +70,7 @@ public final class ShardingAlterTableStatementValidatorTest {
         new ShardingAlterTableStatementValidator().preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), database);
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedShardingOperationException.class)
     public void 
assertPreValidateAlterTableWithRenameTableWithBroadcastTableForPostgreSQL() {
         PostgreSQLAlterTableStatement sqlStatement = new 
PostgreSQLAlterTableStatement();
         sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 
0, new IdentifierValue("t_order"))));
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java
index 5f8b0d7b98b..38a6b73e75c 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/ddl/ShardingRenameTableStatementValidatorTest.java
@@ -25,6 +25,7 @@ import 
org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.route.context.RouteContext;
 import org.apache.shardingsphere.infra.route.context.RouteUnit;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.ddl.impl.ShardingRenameTableStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import org.apache.shardingsphere.sharding.rule.TableRule;
@@ -53,7 +54,7 @@ public final class ShardingRenameTableStatementValidatorTest {
     @Mock
     private ShardingRule shardingRule;
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedShardingOperationException.class)
     public void assertPreValidateShardingTable() {
         SQLStatementContext<RenameTableStatement> sqlStatementContext = 
createRenameTableStatementContext("t_order", "t_user_order");
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
@@ -61,7 +62,7 @@ public final class ShardingRenameTableStatementValidatorTest {
         new ShardingRenameTableStatementValidator().preValidate(shardingRule, 
sqlStatementContext, Collections.emptyList(), database);
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedShardingOperationException.class)
     public void assertPreValidateBroadcastTable() {
         SQLStatementContext<RenameTableStatement> sqlStatementContext = 
createRenameTableStatementContext("t_order", "t_user_order");
         ShardingSphereDatabase database = mock(ShardingSphereDatabase.class);
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingCopyStatementValidatorTest.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingCopyStatementValidatorTest.java
index c6f5e2dbed4..ce2c38a26ca 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingCopyStatementValidatorTest.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-core/src/test/java/org/apache/shardingsphere/sharding/route/engine/validator/dml/ShardingCopyStatementValidatorTest.java
@@ -18,8 +18,8 @@
 package org.apache.shardingsphere.sharding.route.engine.validator.dml;
 
 import 
org.apache.shardingsphere.infra.binder.statement.dml.CopyStatementContext;
-import org.apache.shardingsphere.infra.exception.ShardingSphereException;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
+import 
org.apache.shardingsphere.sharding.exception.UnsupportedShardingOperationException;
 import 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingCopyStatementValidator;
 import org.apache.shardingsphere.sharding.rule.ShardingRule;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
@@ -62,12 +62,12 @@ public class ShardingCopyStatementValidatorTest {
         new ShardingCopyStatementValidator().preValidate(shardingRule, new 
CopyStatementContext(sqlStatement), Collections.emptyList(), database);
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedShardingOperationException.class)
     public void assertPreValidateCopyWithShardingTableForPostgreSQL() {
         assertPreValidateCopyTable(new PostgreSQLCopyStatement());
     }
     
-    @Test(expected = ShardingSphereException.class)
+    @Test(expected = UnsupportedShardingOperationException.class)
     public void assertPreValidateCopyWithShardingTableForOpenGauss() {
         assertPreValidateCopyTable(new OpenGaussCopyStatement());
     }
diff --git 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
index 5967d410dfc..3a775b423a7 100644
--- 
a/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
+++ 
b/shardingsphere-mode/shardingsphere-mode-type/shardingsphere-cluster-mode/shardingsphere-cluster-mode-core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/ClusterContextManagerBuilder.java
@@ -70,8 +70,8 @@ public final class ClusterContextManagerBuilder implements 
ContextManagerBuilder
     }
     
     private void persistMetaData(final MetaDataContexts metaDataContexts) {
-        metaDataContexts.getMetaData().getDatabases().values().forEach(each -> 
each.getSchemas().forEach((schemaName, schema)
-                -> 
metaDataContexts.getPersistService().getDatabaseMetaDataService().persistMetaData(each.getName(),
 schemaName, schema.getTables())));
+        metaDataContexts.getMetaData().getDatabases().values().forEach(each -> 
each.getSchemas()
+                .forEach((schemaName, schema) -> 
metaDataContexts.getPersistService().getDatabaseMetaDataService().persistMetaData(each.getName(),
 schemaName, schema.getTables())));
     }
     
     private void registerOnline(final MetaDataPersistService persistService, 
final RegistryCenter registryCenter,

Reply via email to