You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by su...@apache.org on 2024/04/01 05:57:51 UTC

(shardingsphere) branch master updated: Refactor InvalidDataNodeFormatException (#30724)

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

sunnianjun 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 cdac1ce17b4 Refactor InvalidDataNodeFormatException (#30724)
cdac1ce17b4 is described below

commit cdac1ce17b4d9da0ca8dce8160ee816942d495c7
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Mon Apr 1 13:56:15 2024 +0800

    Refactor InvalidDataNodeFormatException (#30724)
    
    * Refactor InvalidDataNodesFormatException
    
    * Refactor InvalidDataNodeFormatException
---
 .../org/apache/shardingsphere/infra/datanode/DataNode.java   |  9 ++++-----
 ...matException.java => InvalidDataNodeFormatException.java} |  8 ++++----
 .../apache/shardingsphere/infra/datanode/DataNodeTest.java   | 12 ++++++------
 .../data/pipeline/core/datanode/DataNodeUtils.java           |  6 +++---
 .../distsql/handler/update/LoadSingleTableExecutor.java      |  6 +++---
 5 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
index 42e31567c64..910bd22738f 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/datanode/DataNode.java
@@ -26,7 +26,7 @@ import lombok.ToString;
 import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.infra.exception.InvalidDataNodesFormatException;
+import org.apache.shardingsphere.infra.exception.InvalidDataNodeFormatException;
 import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 
 import java.util.List;
@@ -60,10 +60,10 @@ public final class DataNode {
         // TODO remove duplicated splitting?
         boolean isIncludeInstance = isActualDataNodesIncludedDataSourceInstance(dataNode);
         if (!isIncludeInstance && !isValidDataNode(dataNode, 2)) {
-            throw new InvalidDataNodesFormatException(dataNode);
+            throw new InvalidDataNodeFormatException(dataNode);
         }
         if (isIncludeInstance && !isValidDataNode(dataNode, 3)) {
-            throw new InvalidDataNodesFormatException(dataNode);
+            throw new InvalidDataNodeFormatException(dataNode);
         }
         List<String> segments = Splitter.on(DELIMITER).splitToList(dataNode);
         dataSourceName = isIncludeInstance ? segments.get(0) + DELIMITER + segments.get(1) : segments.get(0);
@@ -78,8 +78,7 @@ public final class DataNode {
      * @param dataNode string of data node. use {@code .} to split data source name and table name
      */
     public DataNode(final String databaseName, final DatabaseType databaseType, final String dataNode) {
-        ShardingSpherePreconditions.checkState(dataNode.contains(DELIMITER),
-                () -> new InvalidDataNodesFormatException(dataNode, String.format("Invalid format for data node `%s`", dataNode)));
+        ShardingSpherePreconditions.checkState(dataNode.contains(DELIMITER), () -> new InvalidDataNodeFormatException(dataNode));
         boolean containsSchema = isValidDataNode(dataNode, 3);
         List<String> segments = Splitter.on(DELIMITER).splitToList(dataNode);
         dataSourceName = segments.get(0);
diff --git a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodesFormatException.java b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
similarity index 83%
rename from infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodesFormatException.java
rename to infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
index a8cdad3b5db..b74951c2a92 100644
--- a/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodesFormatException.java
+++ b/infra/common/src/main/java/org/apache/shardingsphere/infra/exception/InvalidDataNodeFormatException.java
@@ -21,17 +21,17 @@ import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.c
 import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
 
 /**
- * Invalid data nodes format exception.
+ * Invalid data node format exception.
  */
-public final class InvalidDataNodesFormatException extends MetaDataSQLException {
+public final class InvalidDataNodeFormatException extends MetaDataSQLException {
     
     private static final long serialVersionUID = 192279170808654743L;
     
-    public InvalidDataNodesFormatException(final String dataNode) {
+    public InvalidDataNodeFormatException(final String dataNode) {
         super(XOpenSQLState.INVALID_DATA_TYPE, 3, "Invalid format for actual data node `%s`.", dataNode);
     }
     
-    public InvalidDataNodesFormatException(final String dataNode, final String reason) {
+    public InvalidDataNodeFormatException(final String dataNode, final String reason) {
         super(XOpenSQLState.INVALID_DATA_TYPE, 3, "Invalid format for data node `%s`, reason is: %s.", dataNode, reason);
     }
 }
diff --git a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
index 55fd5113faa..9baaa2e603f 100644
--- a/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
+++ b/infra/common/src/test/java/org/apache/shardingsphere/infra/datanode/DataNodeTest.java
@@ -17,7 +17,7 @@
 
 package org.apache.shardingsphere.infra.datanode;
 
-import org.apache.shardingsphere.infra.exception.InvalidDataNodesFormatException;
+import org.apache.shardingsphere.infra.exception.InvalidDataNodeFormatException;
 import org.junit.jupiter.api.Test;
 
 import static org.hamcrest.CoreMatchers.is;
@@ -37,17 +37,17 @@ class DataNodeTest {
     
     @Test
     void assertNewInValidDataNodeWithoutDelimiter() {
-        assertThrows(InvalidDataNodesFormatException.class, () -> new DataNode("ds_0tbl_0"));
+        assertThrows(InvalidDataNodeFormatException.class, () -> new DataNode("ds_0tbl_0"));
     }
     
     @Test
     void assertNewInValidDataNodeWithTwoDelimiters() {
-        assertThrows(InvalidDataNodesFormatException.class, () -> new DataNode("ds_0.db_0.tbl_0.tbl_1"));
+        assertThrows(InvalidDataNodeFormatException.class, () -> new DataNode("ds_0.db_0.tbl_0.tbl_1"));
     }
     
     @Test
     void assertNewValidDataNodeWithInvalidDelimiter() {
-        assertThrows(InvalidDataNodesFormatException.class, () -> new DataNode("ds_0,tbl_0"));
+        assertThrows(InvalidDataNodeFormatException.class, () -> new DataNode("ds_0,tbl_0"));
     }
     
     @SuppressWarnings({"SimplifiableAssertion", "ConstantValue"})
@@ -72,12 +72,12 @@ class DataNodeTest {
     
     @Test
     void assertEmptyDataSourceDataNode() {
-        assertThrows(InvalidDataNodesFormatException.class, () -> new DataNode(".tbl_0"));
+        assertThrows(InvalidDataNodeFormatException.class, () -> new DataNode(".tbl_0"));
     }
     
     @Test
     void assertEmptyTableDataNode() {
-        assertThrows(InvalidDataNodesFormatException.class, () -> new DataNode("ds_0."));
+        assertThrows(InvalidDataNodeFormatException.class, () -> new DataNode("ds_0."));
     }
     
     @Test
diff --git a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/datanode/DataNodeUtils.java b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/datanode/DataNodeUtils.java
index b05512f0085..1c27e39b93d 100644
--- a/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/datanode/DataNodeUtils.java
+++ b/kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/datanode/DataNodeUtils.java
@@ -21,7 +21,7 @@ import com.google.common.base.Splitter;
 import lombok.AccessLevel;
 import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.infra.datanode.DataNode;
-import org.apache.shardingsphere.infra.exception.InvalidDataNodesFormatException;
+import org.apache.shardingsphere.infra.exception.InvalidDataNodeFormatException;
 
 import java.util.List;
 
@@ -46,13 +46,13 @@ public final class DataNodeUtils {
      *
      * @param text data node text
      * @return data node
-     * @throws InvalidDataNodesFormatException invalid data nodes format exception
+     * @throws InvalidDataNodeFormatException invalid data nodes format exception
      */
     public static DataNode parseWithSchema(final String text) {
         List<String> segments = Splitter.on(".").splitToList(text);
         boolean hasSchema = 3 == segments.size();
         if (!(2 == segments.size() || hasSchema)) {
-            throw new InvalidDataNodesFormatException(text);
+            throw new InvalidDataNodeFormatException(text);
         }
         DataNode result = new DataNode(segments.get(0), segments.get(segments.size() - 1));
         if (hasSchema) {
diff --git a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
index ccb00bb1df2..ce04e3b71b6 100644
--- a/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
+++ b/kernel/single/distsql/handler/src/main/java/org/apache/shardingsphere/single/distsql/handler/update/LoadSingleTableExecutor.java
@@ -23,7 +23,7 @@ import org.apache.shardingsphere.infra.exception.resource.storageunit.MissingReq
 import org.apache.shardingsphere.infra.database.DatabaseTypeEngine;
 import org.apache.shardingsphere.infra.database.core.metadata.database.DialectDatabaseMetaData;
 import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
-import org.apache.shardingsphere.infra.exception.InvalidDataNodesFormatException;
+import org.apache.shardingsphere.infra.exception.InvalidDataNodeFormatException;
 import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
 import org.apache.shardingsphere.infra.exception.dialect.exception.syntax.table.TableExistsException;
 import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
@@ -86,10 +86,10 @@ public final class LoadSingleTableExecutor implements DatabaseRuleCreateExecutor
         }
         if (isSchemaSupportedDatabaseType) {
             ShardingSpherePreconditions.checkState(singleTableSegment.getSchemaName().isPresent(),
-                    () -> new InvalidDataNodesFormatException(singleTableSegment.toString(), "Current database is schema required, please use format `db.schema.table`"));
+                    () -> new InvalidDataNodeFormatException(singleTableSegment.toString(), "Current database is schema required, please use format `db.schema.table`"));
         } else {
             ShardingSpherePreconditions.checkState(!singleTableSegment.getSchemaName().isPresent(),
-                    () -> new InvalidDataNodesFormatException(singleTableSegment.toString(), "Current database does not support schema, please use format `db.table`"));
+                    () -> new InvalidDataNodeFormatException(singleTableSegment.toString(), "Current database does not support schema, please use format `db.table`"));
         }
     }