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 8571c710572 Fix sonar issue of ShardingStatisticsTableCollector
(#25664)
8571c710572 is described below
commit 8571c710572b6991ed6946cf38db12f69c6b87d1
Author: Liang Zhang <[email protected]>
AuthorDate: Sun May 14 23:30:56 2023 +0800
Fix sonar issue of ShardingStatisticsTableCollector (#25664)
---
.../algorithm/like/CharDigestLikeEncryptAlgorithm.java | 6 +++---
.../data/ShardingStatisticsTableCollector.java | 18 +++++++++++-------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
index cf08dee7f99..b5b4b5b2122 100644
---
a/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
+++
b/features/encrypt/core/src/main/java/org/apache/shardingsphere/encrypt/algorithm/like/CharDigestLikeEncryptAlgorithm.java
@@ -75,7 +75,7 @@ public final class CharDigestLikeEncryptAlgorithm implements
LikeEncryptAlgorith
try {
return Integer.parseInt(delta);
} catch (final NumberFormatException ignored) {
- throw new
EncryptAlgorithmInitializationException("CHAR_DIGEST_LIKE", "delta can only be
a decimal number");
+ throw new EncryptAlgorithmInitializationException(getType(),
"delta can only be a decimal number");
}
}
return DEFAULT_DELTA;
@@ -87,7 +87,7 @@ public final class CharDigestLikeEncryptAlgorithm implements
LikeEncryptAlgorith
try {
return Integer.parseInt(mask);
} catch (final NumberFormatException ignored) {
- throw new
EncryptAlgorithmInitializationException("CHAR_DIGEST_LIKE", "mask can only be a
decimal number");
+ throw new EncryptAlgorithmInitializationException(getType(),
"mask can only be a decimal number");
}
}
return DEFAULT_MASK;
@@ -99,7 +99,7 @@ public final class CharDigestLikeEncryptAlgorithm implements
LikeEncryptAlgorith
try {
return Integer.parseInt(start);
} catch (final NumberFormatException ignored) {
- throw new
EncryptAlgorithmInitializationException("CHAR_DIGEST_LIKE", "start can only be
a decimal number");
+ throw new EncryptAlgorithmInitializationException(getType(),
"start can only be a decimal number");
}
}
return DEFAULT_START;
diff --git
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
index 98614cb50dc..4772dc06976 100644
---
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
+++
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/metadata/data/ShardingStatisticsTableCollector.java
@@ -55,7 +55,11 @@ public final class ShardingStatisticsTableCollector
implements ShardingSphereDat
private static final String POSTGRESQL_TABLE_DATA_LENGTH = "SELECT
PG_RELATION_SIZE(RELID) as DATA_LENGTH FROM PG_STAT_ALL_TABLES T WHERE
SCHEMANAME='%s' AND RELNAME = '%s'";
- private static final String OPENGAUSS_TABLE_ROWS_AND_DATA_LENGTH = "SELECT
RELTUPLES AS TABLE_ROWS, PG_TABLE_SIZE('%s') AS DATA_LENGTH FROM PG_CLASS
WHERE RELNAME = '%s'";
+ private static final String OPENGAUSS_TABLE_ROWS_AND_DATA_LENGTH = "SELECT
RELTUPLES AS TABLE_ROWS, PG_TABLE_SIZE('%s') AS DATA_LENGTH FROM PG_CLASS WHERE
RELNAME = '%s'";
+
+ private static final String TABLE_ROWS_COLUMN_NAME = "TABLE_ROWS";
+
+ private static final String DATA_LENGTH_COLUMN_NAME = "DATA_LENGTH";
@Override
public Optional<ShardingSphereTableData> collect(final String
databaseName, final ShardingSphereTable table,
@@ -120,8 +124,8 @@ public final class ShardingStatisticsTableCollector
implements ShardingSphereDat
Statement statement = connection.createStatement()) {
try (ResultSet resultSet =
statement.executeQuery(String.format(MYSQL_TABLE_ROWS_AND_DATA_LENGTH,
connection.getCatalog(), dataNode.getTableName()))) {
if (resultSet.next()) {
- tableRows = resultSet.getBigDecimal("TABLE_ROWS");
- dataLength = resultSet.getBigDecimal("DATA_LENGTH");
+ tableRows =
resultSet.getBigDecimal(TABLE_ROWS_COLUMN_NAME);
+ dataLength =
resultSet.getBigDecimal(DATA_LENGTH_COLUMN_NAME);
}
}
}
@@ -138,12 +142,12 @@ public final class ShardingStatisticsTableCollector
implements ShardingSphereDat
Statement statement = connection.createStatement()) {
try (ResultSet resultSet =
statement.executeQuery(String.format(POSTGRESQL_TABLE_ROWS_LENGTH,
dataNode.getSchemaName(), dataNode.getTableName()))) {
if (resultSet.next()) {
- tableRows = resultSet.getBigDecimal("TABLE_ROWS");
+ tableRows =
resultSet.getBigDecimal(TABLE_ROWS_COLUMN_NAME);
}
}
try (ResultSet resultSet =
statement.executeQuery(String.format(POSTGRESQL_TABLE_DATA_LENGTH,
dataNode.getSchemaName(), dataNode.getTableName()))) {
if (resultSet.next()) {
- dataLength = resultSet.getBigDecimal("DATA_LENGTH");
+ dataLength =
resultSet.getBigDecimal(DATA_LENGTH_COLUMN_NAME);
}
}
}
@@ -175,8 +179,8 @@ public final class ShardingStatisticsTableCollector
implements ShardingSphereDat
ResultSet resultSet = statement
.executeQuery(String.format(OPENGAUSS_TABLE_ROWS_AND_DATA_LENGTH,
dataNode.getTableName(), dataNode.getTableName()))) {
if (resultSet.next()) {
- row.add(resultSet.getBigDecimal("TABLE_ROWS"));
- row.add(resultSet.getBigDecimal("DATA_LENGTH"));
+ row.add(resultSet.getBigDecimal(TABLE_ROWS_COLUMN_NAME));
+ row.add(resultSet.getBigDecimal(DATA_LENGTH_COLUMN_NAME));
}
}
}