This is an automated email from the ASF dual-hosted git repository.
panjuan 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 d29d61f Add PostgreSQLIdentifierPacket interface (#10069)
d29d61f is described below
commit d29d61f5a8aaa56919289314e389faeccdef01c2
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Apr 13 17:27:57 2021 +0800
Add PostgreSQLIdentifierPacket interface (#10069)
* Refactor PostgreSQLCommandPacketType
* Add PostgreSQLIdentifierPacket interface
* Fix checkstyle
---
.../db/protocol/mysql/codec/MySQLPacketCodecEngine.java | 10 +++++++---
.../db/protocol/mysql/packet/MySQLPacket.java | 4 ----
.../postgresql/codec/PostgreSQLPacketCodecEngine.java | 16 ++++++++++------
...greSQLPacket.java => PostgreSQLIdentifierPacket.java} | 11 ++---------
.../db/protocol/postgresql/packet/PostgreSQLPacket.java | 11 -----------
.../packet/command/PostgreSQLCommandPacket.java | 4 ++--
.../command/query/PostgreSQLRowDescriptionPacket.java | 4 ++--
.../binary/bind/PostgreSQLBinaryResultSetRowPacket.java | 4 ++--
.../query/binary/bind/PostgreSQLBindCompletePacket.java | 4 ++--
.../binary/parse/PostgreSQLParseCompletePacket.java | 4 ++--
.../command/query/text/PostgreSQLDataRowPacket.java | 4 ++--
.../packet/generic/PostgreSQLCommandCompletePacket.java | 4 ++--
.../packet/generic/PostgreSQLErrorResponsePacket.java | 4 ++--
.../packet/generic/PostgreSQLReadyForQueryPacket.java | 4 ++--
.../PostgreSQLAuthenticationMD5PasswordPacket.java | 4 ++--
.../handshake/PostgreSQLAuthenticationOKPacket.java | 4 ++--
.../packet/handshake/PostgreSQLComStartupPacket.java | 5 -----
.../handshake/PostgreSQLParameterStatusPacket.java | 4 ++--
.../handshake/PostgreSQLPasswordMessagePacket.java | 4 ++--
.../packet/handshake/PostgreSQLSSLNegativePacket.java | 5 -----
.../codec/PostgreSQLPacketCodecEngineTest.java | 8 ++++----
.../packet/generic/PostgreSQLComStartupPacketTest.java | 6 +++---
.../packet/generic/PostgreSQLSSLNegativePacketTest.java | 1 -
.../text/distsql/rdl/impl/AddResourceBackendHandler.java | 9 +++++----
24 files changed, 57 insertions(+), 81 deletions(-)
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
index a8ce9a0..c0b3ea3 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/codec/MySQLPacketCodecEngine.java
@@ -32,20 +32,24 @@ import java.util.List;
*/
public final class MySQLPacketCodecEngine implements
DatabasePacketCodecEngine<MySQLPacket> {
+ private static final int PAYLOAD_LENGTH = 3;
+
+ private static final int SEQUENCE_LENGTH = 1;
+
@Override
public boolean isValidHeader(final int readableBytes) {
- return readableBytes >= MySQLPacket.PAYLOAD_LENGTH +
MySQLPacket.SEQUENCE_LENGTH;
+ return readableBytes >= PAYLOAD_LENGTH + SEQUENCE_LENGTH;
}
@Override
public void decode(final ChannelHandlerContext context, final ByteBuf in,
final List<Object> out, final int readableBytes) {
int payloadLength = in.markReaderIndex().readMediumLE();
- int realPacketLength = payloadLength + MySQLPacket.PAYLOAD_LENGTH +
MySQLPacket.SEQUENCE_LENGTH;
+ int realPacketLength = payloadLength + PAYLOAD_LENGTH +
SEQUENCE_LENGTH;
if (readableBytes < realPacketLength) {
in.resetReaderIndex();
return;
}
- out.add(in.readRetainedSlice(payloadLength +
MySQLPacket.SEQUENCE_LENGTH));
+ out.add(in.readRetainedSlice(payloadLength + SEQUENCE_LENGTH));
}
@Override
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/MySQLPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/MySQLPacket.java
index fdf7d09..5e39965 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/MySQLPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/packet/MySQLPacket.java
@@ -25,10 +25,6 @@ import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
*/
public interface MySQLPacket extends DatabasePacket<MySQLPacketPayload> {
- int PAYLOAD_LENGTH = 3;
-
- int SEQUENCE_LENGTH = 1;
-
/**
* Get sequence ID.
*
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngine.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngine.java
index 381e976..22c4b0c 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngine.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngine.java
@@ -20,9 +20,9 @@ package
org.apache.shardingsphere.db.protocol.postgresql.codec;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import org.apache.shardingsphere.db.protocol.codec.DatabasePacketCodecEngine;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLErrorResponsePacket;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLSSLNegativePacket;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
import java.util.List;
@@ -32,9 +32,13 @@ import java.util.List;
*/
public final class PostgreSQLPacketCodecEngine implements
DatabasePacketCodecEngine<PostgreSQLPacket> {
+ private static final int MESSAGE_TYPE_LENGTH = 1;
+
+ private static final int PAYLOAD_LENGTH = 4;
+
@Override
public boolean isValidHeader(final int readableBytes) {
- return readableBytes >= PostgreSQLPacket.MESSAGE_TYPE_LENGTH +
PostgreSQLPacket.PAYLOAD_LENGTH;
+ return readableBytes >= MESSAGE_TYPE_LENGTH + PAYLOAD_LENGTH;
}
@Override
@@ -43,7 +47,7 @@ public final class PostgreSQLPacketCodecEngine implements
DatabasePacketCodecEng
if ('\0' == in.markReaderIndex().readByte()) {
in.resetReaderIndex();
} else {
- messageTypeLength = PostgreSQLPacket.MESSAGE_TYPE_LENGTH;
+ messageTypeLength = MESSAGE_TYPE_LENGTH;
}
int payloadLength = in.readInt();
int realPacketLength = payloadLength + messageTypeLength;
@@ -68,9 +72,9 @@ public final class PostgreSQLPacketCodecEngine implements
DatabasePacketCodecEng
postgreSQLErrorResponsePacket.addField(PostgreSQLErrorResponsePacket.FIELD_TYPE_MESSAGE,
ex.getMessage());
postgreSQLErrorResponsePacket.write(payload);
} finally {
- if (!(message instanceof PostgreSQLSSLNegativePacket)) {
- out.writeByte(message.getMessageType());
- out.writeInt(payload.getByteBuf().readableBytes() +
PostgreSQLPacket.PAYLOAD_LENGTH);
+ if (message instanceof PostgreSQLIdentifierPacket) {
+ out.writeByte(((PostgreSQLIdentifierPacket)
message).getMessageType());
+ out.writeInt(payload.getByteBuf().readableBytes() +
PAYLOAD_LENGTH);
}
out.writeBytes(payload.getByteBuf());
payload.close();
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLIdentifierPacket.java
similarity index 73%
copy from
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
copy to
shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLIdentifierPacket.java
index 3ecf900..b4dc5f1 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLIdentifierPacket.java
@@ -17,17 +17,10 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet;
-import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
-import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
-
/**
- * Database packet for PostgreSQL.
+ * Identifier packet for PostgreSQL.
*/
-public interface PostgreSQLPacket extends
DatabasePacket<PostgreSQLPacketPayload> {
-
- int MESSAGE_TYPE_LENGTH = 1;
-
- int PAYLOAD_LENGTH = 4;
+public interface PostgreSQLIdentifierPacket extends PostgreSQLPacket {
/**
* Get message type.
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
index 3ecf900..aad3845 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/PostgreSQLPacket.java
@@ -24,15 +24,4 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* Database packet for PostgreSQL.
*/
public interface PostgreSQLPacket extends
DatabasePacket<PostgreSQLPacketPayload> {
-
- int MESSAGE_TYPE_LENGTH = 1;
-
- int PAYLOAD_LENGTH = 4;
-
- /**
- * Get message type.
- *
- * @return message type
- */
- char getMessageType();
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacket.java
index 744dac9..c0c00a2 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacket.java
@@ -18,10 +18,10 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command;
import org.apache.shardingsphere.db.protocol.packet.CommandPacket;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
/**
* Command packet for PostgreSQL.
*/
-public abstract class PostgreSQLCommandPacket implements PostgreSQLPacket,
CommandPacket {
+public abstract class PostgreSQLCommandPacket implements
PostgreSQLIdentifierPacket, CommandPacket {
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/PostgreSQLRowDescriptionPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/PostgreSQLRowDescriptionPacket.java
index 749b55d..721fb46 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/PostgreSQLRowDescriptionPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/PostgreSQLRowDescriptionPacket.java
@@ -19,7 +19,7 @@ package
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -29,7 +29,7 @@ import java.util.Collection;
* Row description packet for PostgreSQL.
*/
@RequiredArgsConstructor
-public final class PostgreSQLRowDescriptionPacket implements PostgreSQLPacket {
+public final class PostgreSQLRowDescriptionPacket implements
PostgreSQLIdentifierPacket {
@Getter
private final int fieldCount;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBinaryResultSetRowPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBinaryResultSetRowPacket.java
index 4a719df..bece933 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBinaryResultSetRowPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBinaryResultSetRowPacket.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.bi
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.binary.BinaryCell;
import org.apache.shardingsphere.db.protocol.binary.BinaryRow;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol.PostgreSQLBinaryProtocolValue;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol.PostgreSQLBinaryProtocolValueFactory;
@@ -30,7 +30,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* Binary result set row packet for PostgreSQL.
*/
@RequiredArgsConstructor
-public final class PostgreSQLBinaryResultSetRowPacket implements
PostgreSQLPacket {
+public final class PostgreSQLBinaryResultSetRowPacket implements
PostgreSQLIdentifierPacket {
private final BinaryRow row;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBindCompletePacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBindCompletePacket.java
index 0923c71..22f49fb 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBindCompletePacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLBindCompletePacket.java
@@ -17,14 +17,14 @@
package
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
/**
* Bind complete packet for PostgreSQL.
*/
-public final class PostgreSQLBindCompletePacket implements PostgreSQLPacket {
+public final class PostgreSQLBindCompletePacket implements
PostgreSQLIdentifierPacket {
@Override
public void write(final PostgreSQLPacketPayload payload) {
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacket.java
index b338158..1cee482 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLParseCompletePacket.java
@@ -17,14 +17,14 @@
package
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.parse;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
/**
* Parse complete packet for PostgreSQL.
*/
-public final class PostgreSQLParseCompletePacket implements PostgreSQLPacket {
+public final class PostgreSQLParseCompletePacket implements
PostgreSQLIdentifierPacket {
@Override
public void write(final PostgreSQLPacketPayload payload) {
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacket.java
index c4347c4..c98901b 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLDataRowPacket.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.te
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -34,7 +34,7 @@ import java.util.Collection;
@RequiredArgsConstructor
@Getter
@Slf4j
-public final class PostgreSQLDataRowPacket implements PostgreSQLPacket {
+public final class PostgreSQLDataRowPacket implements
PostgreSQLIdentifierPacket {
private final Collection<Object> data;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
index a60ba42..ebbc875 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLCommandCompletePacket.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* Command complete packet for PostgreSQL.
*/
@RequiredArgsConstructor
-public final class PostgreSQLCommandCompletePacket implements PostgreSQLPacket
{
+public final class PostgreSQLCommandCompletePacket implements
PostgreSQLIdentifierPacket {
private final String sqlCommand;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLErrorResponsePacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLErrorResponsePacket.java
index 9fa9f53..6ed16c3 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLErrorResponsePacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLErrorResponsePacket.java
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -30,7 +30,7 @@ import java.util.Map.Entry;
*
* @see <a
href="https://www.postgresql.org/docs/12/protocol-message-formats.html">ErrorResponse
(B)</a>
*/
-public final class PostgreSQLErrorResponsePacket implements PostgreSQLPacket {
+public final class PostgreSQLErrorResponsePacket implements
PostgreSQLIdentifierPacket {
public static final char FIELD_TYPE_SEVERITY = 'S';
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLReadyForQueryPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLReadyForQueryPacket.java
index 1dd9643..fc71920 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLReadyForQueryPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLReadyForQueryPacket.java
@@ -17,14 +17,14 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
/**
* Ready for query packet for PostgreSQL.
*/
-public final class PostgreSQLReadyForQueryPacket implements PostgreSQLPacket {
+public final class PostgreSQLReadyForQueryPacket implements
PostgreSQLIdentifierPacket {
private static final char STATUS = 'I';
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java
index 5e18c0c..e73d1e4 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationMD5PasswordPacket.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* AuthenticationMD5Password (backend) packet for PostgreSQL.
*/
@RequiredArgsConstructor
-public final class PostgreSQLAuthenticationMD5PasswordPacket implements
PostgreSQLPacket {
+public final class PostgreSQLAuthenticationMD5PasswordPacket implements
PostgreSQLIdentifierPacket {
private static final int AUTH_REQ_MD5 = 5;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationOKPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationOKPacket.java
index 8a0c957..e56ebdb 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationOKPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLAuthenticationOKPacket.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* Authentication OK packet for PostgreSQL.
*/
@RequiredArgsConstructor
-public final class PostgreSQLAuthenticationOKPacket implements
PostgreSQLPacket {
+public final class PostgreSQLAuthenticationOKPacket implements
PostgreSQLIdentifierPacket {
private final boolean success;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLComStartupPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLComStartupPacket.java
index b336a5a..7a86107 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLComStartupPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLComStartupPacket.java
@@ -42,9 +42,4 @@ public final class PostgreSQLComStartupPacket implements
PostgreSQLPacket {
@Override
public void write(final PostgreSQLPacketPayload payload) {
}
-
- @Override
- public char getMessageType() {
- return '\0';
- }
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLParameterStatusPacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLParameterStatusPacket.java
index cc48655..369ea51 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLParameterStatusPacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLParameterStatusPacket.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
import lombok.RequiredArgsConstructor;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* Parameter status packet for PostgreSQL.
*/
@RequiredArgsConstructor
-public final class PostgreSQLParameterStatusPacket implements PostgreSQLPacket
{
+public final class PostgreSQLParameterStatusPacket implements
PostgreSQLIdentifierPacket {
private final String key;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java
index 17c94a8..d1698a0 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLPasswordMessagePacket.java
@@ -18,7 +18,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
import lombok.Getter;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* PasswordMessage (frontend) packet for PostgreSQL.
*/
@Getter
-public final class PostgreSQLPasswordMessagePacket implements PostgreSQLPacket
{
+public final class PostgreSQLPasswordMessagePacket implements
PostgreSQLIdentifierPacket {
private final String md5Digest;
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLSSLNegativePacket.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLSSLNegativePacket.java
index 1f24e54..4ba8a68 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLSSLNegativePacket.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLSSLNegativePacket.java
@@ -31,9 +31,4 @@ public final class PostgreSQLSSLNegativePacket implements
PostgreSQLPacket {
public void write(final PostgreSQLPacketPayload payload) {
payload.writeInt1(STATUS_CODE);
}
-
- @Override
- public char getMessageType() {
- return '\0';
- }
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngineTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngineTest.java
index 5dc7b97..89c9158 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngineTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/codec/PostgreSQLPacketCodecEngineTest.java
@@ -20,7 +20,7 @@ package
org.apache.shardingsphere.db.protocol.postgresql.codec;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
-import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
+import
org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLIdentifierPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -55,7 +55,7 @@ public final class PostgreSQLPacketCodecEngineTest {
@Test
public void assertIsInvalidHeader() {
- assertFalse(new
PostgreSQLPacketCodecEngine().isValidHeader(PostgreSQLPacket.PAYLOAD_LENGTH));
+ assertFalse(new PostgreSQLPacketCodecEngine().isValidHeader(4));
}
@Test
@@ -83,12 +83,12 @@ public final class PostgreSQLPacketCodecEngineTest {
ByteBuf payloadByteBuf = mock(ByteBuf.class);
when(byteBufAllocator.buffer()).thenReturn(payloadByteBuf);
when(payloadByteBuf.readableBytes()).thenReturn(50);
- PostgreSQLPacket actualMessage = mock(PostgreSQLPacket.class);
+ PostgreSQLIdentifierPacket actualMessage =
mock(PostgreSQLIdentifierPacket.class);
when(actualMessage.getMessageType()).thenReturn(PostgreSQLCommandPacketType.AUTHENTICATION_REQUEST.getValue());
new PostgreSQLPacketCodecEngine().encode(context, actualMessage,
byteBuf);
verify(actualMessage).write(ArgumentMatchers.any());
verify(byteBuf).writeByte(PostgreSQLCommandPacketType.AUTHENTICATION_REQUEST.getValue());
- verify(byteBuf).writeInt(50 + PostgreSQLPacket.PAYLOAD_LENGTH);
+ verify(byteBuf).writeInt(54);
verify(byteBuf).writeBytes(payloadByteBuf);
}
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLComStartupPacketTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLComStartupPacketTest.java
index 542cbe0..44130f3 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLComStartupPacketTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLComStartupPacketTest.java
@@ -18,13 +18,14 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
import io.netty.buffer.ByteBuf;
-import java.util.LinkedHashMap;
-import java.util.Map;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.ByteBufTestUtils;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.handshake.PostgreSQLComStartupPacket;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
import org.junit.Test;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -49,7 +50,6 @@ public final class PostgreSQLComStartupPacketTest {
payload.writeStringNul(each.getValue());
}
PostgreSQLComStartupPacket packet = new
PostgreSQLComStartupPacket(payload);
- assertThat(packet.getMessageType(), is('\0'));
Map<String, String> actualParametersMap = packet.getParametersMap();
assertThat(actualParametersMap, is(expectedParametersMap));
packet.write(payload);
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLSSLNegativePacketTest.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLSSLNegativePacketTest.java
index fee816f..6c4b8d8 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLSSLNegativePacketTest.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/generic/PostgreSQLSSLNegativePacketTest.java
@@ -33,7 +33,6 @@ public final class PostgreSQLSSLNegativePacketTest {
ByteBuf byteBuf = ByteBufTestUtils.createByteBuf(1);
PostgreSQLPacketPayload payload = new PostgreSQLPacketPayload(byteBuf);
PostgreSQLSSLNegativePacket packet = new PostgreSQLSSLNegativePacket();
- assertThat(packet.getMessageType(), is('\0'));
packet.write(payload);
assertThat(byteBuf.writerIndex(), is(1));
assertThat(payload.readInt1(), is((int) 'N'));
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
index 04cbf45..0283f00 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rdl/impl/AddResourceBackendHandler.java
@@ -34,6 +34,7 @@ import
org.apache.shardingsphere.proxy.converter.AddResourcesStatementConverter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
+import java.util.Map.Entry;
/**
* Add resource backend handler.
@@ -47,7 +48,7 @@ public final class AddResourceBackendHandler extends
SchemaRequiredBackendHandle
public AddResourceBackendHandler(final DatabaseType databaseType, final
AddResourceStatement sqlStatement, final BackendConnection backendConnection) {
super(sqlStatement, backendConnection);
this.databaseType = databaseType;
- this.dataSourceValidator = new DataSourceValidator();
+ dataSourceValidator = new DataSourceValidator();
}
@Override
@@ -55,9 +56,9 @@ public final class AddResourceBackendHandler extends
SchemaRequiredBackendHandle
Map<String, DataSourceConfiguration> dataSources =
DataSourceParameterConverter.getDataSourceConfigurationMap(
DataSourceParameterConverter.getDataSourceParameterMapFromYamlConfiguration(AddResourcesStatementConverter.convert(databaseType,
sqlStatement)));
Collection<String> invalidDataSourceNames = new ArrayList<>();
- for (String dataSourceName : dataSources.keySet()) {
- if
(!dataSourceValidator.validate(dataSources.get(dataSourceName))) {
- invalidDataSourceNames.add(dataSourceName);
+ for (Entry<String, DataSourceConfiguration> entry :
dataSources.entrySet()) {
+ if (!dataSourceValidator.validate(entry.getValue())) {
+ invalidDataSourceNames.add(entry.getKey());
}
}
if (!invalidDataSourceNames.isEmpty()) {