This is an automated email from the ASF dual-hosted git repository.
zichaowang 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 a28b6efe234 Refactor Fix code inspection for db-protocol module
(#31201)
a28b6efe234 is described below
commit a28b6efe23459ddec4f0ec563dc1153c1ab36153
Author: Liang Zhang <[email protected]>
AuthorDate: Sat May 11 04:13:18 2024 +0800
Refactor Fix code inspection for db-protocol module (#31201)
---
.../binary/execute/protocol/MySQLInt1BinaryProtocolValue.java | 1 -
.../binary/execute/protocol/MySQLInt2BinaryProtocolValue.java | 1 -
.../binary/execute/protocol/MySQLInt4BinaryProtocolValue.java | 1 -
.../mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java | 9 ++-------
.../packet/command/generic/OpenGaussErrorResponsePacket.java | 6 +++---
.../packet/command/generic/OpenGaussErrorResponsePacketTest.java | 4 ++--
.../postgresql/packet/command/PostgreSQLCommandPacketType.java | 5 ++---
.../extended/bind/protocol/util/PostgreSQLTextBitUtils.java | 2 +-
.../extended/bind/protocol/util/PostgreSQLTextBoolUtils.java | 2 +-
.../distsql/handler/update/AlterSQLParserRuleExecutorTest.java | 7 +------
.../frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java | 6 +++---
11 files changed, 15 insertions(+), 29 deletions(-)
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt1BinaryProtocolValue.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt1BinaryProtocolValue.java
index a8666dea338..56637cb8945 100644
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt1BinaryProtocolValue.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt1BinaryProtocolValue.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
*/
public final class MySQLInt1BinaryProtocolValue implements
MySQLBinaryProtocolValue {
- @SuppressWarnings("SimplifiableIfStatement")
@Override
public Object read(final MySQLPacketPayload payload, final boolean
unsigned) {
if (unsigned) {
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt2BinaryProtocolValue.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt2BinaryProtocolValue.java
index f83f3d6ecd1..ea2068d7bce 100644
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt2BinaryProtocolValue.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt2BinaryProtocolValue.java
@@ -24,7 +24,6 @@ import
org.apache.shardingsphere.db.protocol.mysql.payload.MySQLPacketPayload;
*/
public final class MySQLInt2BinaryProtocolValue implements
MySQLBinaryProtocolValue {
- @SuppressWarnings("SimplifiableIfStatement")
@Override
public Object read(final MySQLPacketPayload payload, final boolean
unsigned) {
if (unsigned) {
diff --git
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValue.java
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValue.java
index 5dc130c8b97..e8a9f447a55 100644
---
a/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValue.java
+++
b/db-protocol/mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/command/query/binary/execute/protocol/MySQLInt4BinaryProtocolValue.java
@@ -26,7 +26,6 @@ import java.math.BigDecimal;
*/
public final class MySQLInt4BinaryProtocolValue implements
MySQLBinaryProtocolValue {
- @SuppressWarnings("SimplifiableIfStatement")
@Override
public Object read(final MySQLPacketPayload payload, final boolean
unsigned) {
if (unsigned) {
diff --git
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
index 597f5161888..8e7ff7b6ea9 100644
---
a/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
+++
b/db-protocol/mysql/src/test/java/org/apache/shardingsphere/db/protocol/mysql/packet/binlog/row/MySQLBinlogRowsEventPacketTest.java
@@ -32,7 +32,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import static org.hamcrest.CoreMatchers.is;
@@ -59,17 +59,12 @@ class MySQLBinlogRowsEventPacketTest {
@BeforeEach
void setUp() {
- mockColumnDefs();
+ columnDefs = Collections.singletonList(new
MySQLBinlogColumnDef(MySQLBinaryColumnType.LONGLONG));
when(payload.readInt6()).thenReturn(1L);
when(payload.readInt2()).thenReturn(2);
when(payload.readIntLenenc()).thenReturn(1L);
}
- private void mockColumnDefs() {
- columnDefs = new ArrayList<>();
- columnDefs.add(new
MySQLBinlogColumnDef(MySQLBinaryColumnType.LONGLONG));
- }
-
@Test
void assertReadWriteRowV1WithoutNullValue() throws
InvocationTargetException, NoSuchMethodException, IllegalAccessException {
MySQLBinlogRowsEventPacket actual = new
MySQLBinlogRowsEventPacket(binlogEventHeader, payload);
diff --git
a/db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacket.java
b/db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacket.java
index 291b5c55999..63280ecd124 100644
---
a/db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacket.java
+++
b/db-protocol/opengauss/src/main/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacket.java
@@ -56,7 +56,7 @@ public final class OpenGaussErrorResponsePacket extends
PostgreSQLIdentifierPack
public static final char FIELD_TYPE_ROUTINE = 'R';
- public static final char FIELD_TYPE_ERRORCODE = 'c';
+ public static final char FIELD_TYPE_ERROR_CODE = 'c';
private final Map<Character, String> fields;
@@ -85,7 +85,7 @@ public final class OpenGaussErrorResponsePacket extends
PostgreSQLIdentifierPack
fields.put(FIELD_TYPE_MESSAGE, serverErrorMessage.getMessage());
}
if (null != serverErrorMessage.getERRORCODE()) {
- fields.put(FIELD_TYPE_ERRORCODE,
serverErrorMessage.getERRORCODE());
+ fields.put(FIELD_TYPE_ERROR_CODE,
serverErrorMessage.getERRORCODE());
}
if (null != serverErrorMessage.getDetail()) {
fields.put(FIELD_TYPE_DETAIL, serverErrorMessage.getDetail());
@@ -117,7 +117,7 @@ public final class OpenGaussErrorResponsePacket extends
PostgreSQLIdentifierPack
}
private void fillRequiredFieldsIfNecessary() {
- fields.putIfAbsent(FIELD_TYPE_ERRORCODE, "0");
+ fields.putIfAbsent(FIELD_TYPE_ERROR_CODE, "0");
}
@Override
diff --git
a/db-protocol/opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacketTest.java
b/db-protocol/opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacketTest.java
index 1e60d972c23..d622b9bcbf1 100644
---
a/db-protocol/opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacketTest.java
+++
b/db-protocol/opengauss/src/test/java/org/apache/shardingsphere/db/protocol/opengauss/packet/command/generic/OpenGaussErrorResponsePacketTest.java
@@ -41,7 +41,7 @@ class OpenGaussErrorResponsePacketTest {
verify(payload).writeStringNul("3D000");
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE);
verify(payload).writeStringNul("database \"test\" does not exist");
-
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_ERRORCODE);
+
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_ERROR_CODE);
verify(payload).writeStringNul("-1");
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_DETAIL);
verify(payload).writeStringNul("detail");
@@ -76,7 +76,7 @@ class OpenGaussErrorResponsePacketTest {
verify(payload).writeStringNul("3D000");
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE);
verify(payload).writeStringNul("database \"test\" does not exist");
-
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_ERRORCODE);
+
verify(payload).writeInt1(OpenGaussErrorResponsePacket.FIELD_TYPE_ERROR_CODE);
verify(payload).writeStringNul("0");
}
}
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
index ab694c575de..21bf02bb793 100644
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
@@ -55,9 +55,8 @@ public enum PostgreSQLCommandPacketType implements
CommandPacketType, PostgreSQL
TERMINATE('X');
- private static final Set<PostgreSQLCommandPacketType>
EXTENDED_PROTOCOL_PACKET_TYPES =
EnumSet.of(PostgreSQLCommandPacketType.PARSE_COMMAND,
- PostgreSQLCommandPacketType.BIND_COMMAND,
PostgreSQLCommandPacketType.DESCRIBE_COMMAND,
PostgreSQLCommandPacketType.EXECUTE_COMMAND,
- PostgreSQLCommandPacketType.SYNC_COMMAND,
PostgreSQLCommandPacketType.CLOSE_COMMAND,
PostgreSQLCommandPacketType.FLUSH_COMMAND);
+ private static final Set<PostgreSQLCommandPacketType>
EXTENDED_PROTOCOL_PACKET_TYPES = EnumSet.of(
+ PARSE_COMMAND, BIND_COMMAND, DESCRIBE_COMMAND, EXECUTE_COMMAND,
SYNC_COMMAND, CLOSE_COMMAND, FLUSH_COMMAND);
private final char value;
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtils.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtils.java
index a7a4057c37c..7f6cf04ed8d 100644
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtils.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBitUtils.java
@@ -24,7 +24,7 @@ import lombok.NoArgsConstructor;
* Text bit utility class of PostgreSQL.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class PostgreSQLTextBitUtils {
+public final class PostgreSQLTextBitUtils {
/**
* Get bit Text value in PostgreSQL text format.
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtils.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtils.java
index c0f6ba1c8c4..dced984dc06 100644
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtils.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/util/PostgreSQLTextBoolUtils.java
@@ -24,7 +24,7 @@ import lombok.NoArgsConstructor;
* Text Bool utility class of PostgreSQL.
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
-public class PostgreSQLTextBoolUtils {
+public final class PostgreSQLTextBoolUtils {
/**
* Get Boolean Text value in PostgreSQL text format.
diff --git
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
index 209e5d179a8..5461cbdc529 100644
---
a/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
+++
b/kernel/sql-parser/distsql/handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleExecutorTest.java
@@ -20,7 +20,6 @@ package
org.apache.shardingsphere.parser.distsql.handler.update;
import
org.apache.shardingsphere.distsql.handler.engine.update.DistSQLUpdateExecuteEngine;
import
org.apache.shardingsphere.distsql.handler.engine.update.rdl.rule.spi.global.GlobalRuleDefinitionExecutor;
import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
import org.apache.shardingsphere.parser.distsql.segment.CacheOptionSegment;
import
org.apache.shardingsphere.parser.distsql.statement.updatable.AlterSQLParserRuleStatement;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
@@ -63,12 +62,8 @@ class AlterSQLParserRuleExecutorTest {
SQLParserRule rule = mock(SQLParserRule.class);
GlobalRuleDefinitionExecutor executor =
mock(GlobalRuleDefinitionExecutor.class);
when(executor.getRuleClass()).thenReturn(SQLParserRule.class);
-
when(rule.getConfiguration()).thenReturn(getSQLParserRuleConfiguration());
+ when(rule.getConfiguration()).thenReturn(new
DefaultSQLParserRuleConfigurationBuilder().build());
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(executor.getRuleClass())).thenReturn(rule);
return result;
}
-
- private SQLParserRuleConfiguration getSQLParserRuleConfiguration() {
- return new DefaultSQLParserRuleConfigurationBuilder().build();
- }
}
diff --git
a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
index 5903aa02a77..4e06074300e 100644
---
a/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
+++
b/proxy/frontend/type/opengauss/src/test/java/org/apache/shardingsphere/proxy/frontend/opengauss/err/OpenGaussErrorPacketFactoryTest.java
@@ -42,7 +42,7 @@ class OpenGaussErrorPacketFactoryTest {
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_SEVERITY),
is("FATAL"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_CODE),
is("3D000"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("database \"test\" does not exist"));
-
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERRORCODE),
is("-1"));
+
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERROR_CODE),
is("-1"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_DETAIL),
is("detail"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_HINT),
is("hint"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_POSITION),
is("1"));
@@ -63,7 +63,7 @@ class OpenGaussErrorPacketFactoryTest {
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_SEVERITY),
is("ERROR"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_CODE),
is("3D000"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("database \"test\" does not exist"));
-
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERRORCODE),
is("0"));
+
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERROR_CODE),
is("0"));
}
@Test
@@ -75,7 +75,7 @@ class OpenGaussErrorPacketFactoryTest {
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_SEVERITY),
is("ERROR"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_CODE),
is("58000"));
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_MESSAGE),
is("Unknown exception." + System.lineSeparator() + "More details: No reason"));
-
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERRORCODE),
is("0"));
+
assertThat(actualFields.get(OpenGaussErrorResponsePacket.FIELD_TYPE_ERROR_CODE),
is("0"));
}
@SuppressWarnings("unchecked")