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 2023/05/12 12:30:50 UTC
[shardingsphere] branch master updated: Fix sonar issue for ShardingStrategyType (#25625)
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 942543bfb0a Fix sonar issue for ShardingStrategyType (#25625)
942543bfb0a is described below
commit 942543bfb0a20d63e723b8ad0340e7f21289ff41
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Fri May 12 20:30:43 2023 +0800
Fix sonar issue for ShardingStrategyType (#25625)
---
.../route/engine/type/ShardingRouteEngineFactory.java | 2 +-
.../distsql/handler/enums/ShardingStrategyType.java | 14 +++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
index bde9eb050d1..47621e1bb2e 100644
--- a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
+++ b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/route/engine/type/ShardingRouteEngineFactory.java
@@ -92,7 +92,7 @@ public final class ShardingRouteEngineFactory {
*/
public static ShardingRouteEngine newInstance(final ShardingRule shardingRule, final ShardingSphereDatabase database, final QueryContext queryContext,
final ShardingConditions shardingConditions, final ConfigurationProperties props, final ConnectionContext connectionContext) {
- SQLStatementContext sqlStatementContext = queryContext.getSqlStatementContext();
+ SQLStatementContext<?> sqlStatementContext = queryContext.getSqlStatementContext();
SQLStatement sqlStatement = sqlStatementContext.getSqlStatement();
if (sqlStatement instanceof TCLStatement) {
return new ShardingDatabaseBroadcastRoutingEngine();
diff --git a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/enums/ShardingStrategyType.java b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/enums/ShardingStrategyType.java
index cb288b2b222..f6515ad9a26 100644
--- a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/enums/ShardingStrategyType.java
+++ b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/enums/ShardingStrategyType.java
@@ -17,6 +17,7 @@
package org.apache.shardingsphere.sharding.distsql.handler.enums;
+import org.apache.shardingsphere.infra.util.exception.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.util.exception.external.sql.type.generic.UnsupportedSQLOperationException;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.ComplexShardingStrategyConfiguration;
import org.apache.shardingsphere.sharding.api.config.strategy.sharding.HintShardingStrategyConfiguration;
@@ -29,7 +30,7 @@ import java.util.Collection;
import java.util.Optional;
/**
- * Sharding strategy type enum.
+ * Sharding strategy type.
*/
public enum ShardingStrategyType {
@@ -172,14 +173,13 @@ public enum ShardingStrategyType {
/**
* Returns the sharding strategy type.
*
- * @param shardingStrategyConfig implementation class of sharding strategy configuration
+ * @param config sharding strategy configuration
* @return sharding strategy type
*/
- public static ShardingStrategyType getValueOf(final ShardingStrategyConfiguration shardingStrategyConfig) {
- Optional<ShardingStrategyType> type = Arrays.stream(values())
- .filter(each -> shardingStrategyConfig.getClass().getName().equals(each.getImplementedClass().getName())).findFirst();
- type.orElseThrow(() -> new UnsupportedOperationException(String.format("unsupported strategy type %s", shardingStrategyConfig.getClass().getName())));
- return type.get();
+ public static ShardingStrategyType getValueOf(final ShardingStrategyConfiguration config) {
+ Optional<ShardingStrategyType> result = Arrays.stream(values()).filter(each -> config.getClass().getName().equals(each.getImplementedClass().getName())).findFirst();
+ ShardingSpherePreconditions.checkState(result.isPresent(), () -> new UnsupportedOperationException(String.format("unsupported strategy type: `%s`.", config.getClass().getName())));
+ return result.get();
}
/**