This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 71f3b3664ed Remove unnecessary null-check in PostgreSQLServerInfo
(#25534)
71f3b3664ed is described below
commit 71f3b3664ed005382d5f0407275ac53ed943a723
Author: 吴伟杰 <[email protected]>
AuthorDate: Tue May 9 19:21:29 2023 +0800
Remove unnecessary null-check in PostgreSQLServerInfo (#25534)
---
.../db/protocol/postgresql/constant/PostgreSQLServerInfo.java | 9 +++------
.../protocol/postgresql/constant/PostgreSQLServerInfoTest.java | 8 +-------
2 files changed, 4 insertions(+), 13 deletions(-)
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
index b7ee67f9b14..b61044a2251 100644
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfo.java
@@ -30,10 +30,10 @@ import java.util.concurrent.ConcurrentHashMap;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PostgreSQLServerInfo {
- private static final String DEFAULT_POSTGRESQL_VERSION = "12.3";
-
private static final String SERVER_VERSION_PATTERN =
"%s-ShardingSphere-Proxy %s";
+ private static final String DEFAULT_POSTGRESQL_VERSION = "12.3";
+
private static final Map<String, String> SERVER_VERSIONS = new
ConcurrentHashMap<>();
/**
@@ -43,10 +43,7 @@ public final class PostgreSQLServerInfo {
* @param serverVersion server version
*/
public static void setServerVersion(final String databaseName, final
String serverVersion) {
- // TODO check when the serverVersion is null value
- if (null != serverVersion) {
- SERVER_VERSIONS.put(databaseName,
String.format(SERVER_VERSION_PATTERN, serverVersion,
CommonConstants.PROXY_VERSION.get()));
- }
+ SERVER_VERSIONS.put(databaseName,
String.format(SERVER_VERSION_PATTERN, serverVersion,
CommonConstants.PROXY_VERSION.get()));
}
/**
diff --git
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
index a15387f524c..a7f0ed7caa6 100644
---
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
+++
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLServerInfoTest.java
@@ -32,15 +32,9 @@ class PostgreSQLServerInfoTest {
assertThat(PostgreSQLServerInfo.getServerVersion("foo_db"),
is("13.2-ShardingSphere-Proxy 5.0.0"));
}
- @Test
- void assertSetServerVersionForNull() {
- CommonConstants.PROXY_VERSION.set("5.0.0");
- PostgreSQLServerInfo.setServerVersion("foo_db", null);
- assertThat(PostgreSQLServerInfo.getServerVersion("foo_db"),
is("12.3-ShardingSphere-Proxy 5.0.0"));
- }
-
@Test
void assertGetServerVersionWithoutDatabase() {
+ CommonConstants.PROXY_VERSION.set("5.0.0");
assertThat(PostgreSQLServerInfo.getServerVersion(null),
is("12.3-ShardingSphere-Proxy 5.0.0"));
}
}