You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/04/12 14:19:45 UTC
[shardingsphere] branch master updated: Refactor PostgreSQL
protocol packet (#10055)
This is an automated email from the ASF dual-hosted git repository.
wuweijie 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 b65bd1e Refactor PostgreSQL protocol packet (#10055)
b65bd1e is described below
commit b65bd1e01100c40587f80ad59f4b3205e84d93bb
Author: Liang Zhang <te...@163.com>
AuthorDate: Mon Apr 12 22:19:14 2021 +0800
Refactor PostgreSQL protocol packet (#10055)
* Refactor handshake packet for pg
* Refactor generic packet for pg
* Refactor query packet for pg
* Refactor pg packet
---
.../command/PostgreSQLCommandPacketFactory.java | 6 +-----
.../command/PostgreSQLCommandPacketType.java | 2 +-
.../query/PostgreSQLRowDescriptionPacket.java | 8 +++++---
.../query/binary/PostgreSQLBinaryStatement.java | 2 --
.../bind/PostgreSQLBinaryResultSetRowPacket.java | 9 ++++----
.../binary/bind/PostgreSQLBindCompletePacket.java | 9 ++++----
.../query/binary/bind/PostgreSQLComBindPacket.java | 2 --
.../PostgreSQLTypeUnspecifiedSQLParameter.java | 6 ++----
.../protocol/PostgreSQLArrayParameterDecoder.java | 18 ++++++++--------
.../PostgreSQLBoolArrayBinaryProtocolValue.java | 4 ++--
.../PostgreSQLFloat4ArrayBinaryProtocolValue.java | 4 ++--
.../PostgreSQLFloat8ArrayBinaryProtocolValue.java | 4 ++--
.../PostgreSQLInt2ArrayBinaryProtocolValue.java | 4 ++--
.../PostgreSQLInt4ArrayBinaryProtocolValue.java | 4 ++--
.../PostgreSQLInt8ArrayBinaryProtocolValue.java | 4 ++--
.../PostgreSQLNumericBinaryProtocolValue.java | 8 +++-----
.../PostgreSQLStringArrayBinaryProtocolValue.java | 4 ++--
.../describe/PostgreSQLComDescribePacket.java | 2 --
.../binary/parse/PostgreSQLComParsePacket.java | 2 --
.../parse/PostgreSQLParseCompletePacket.java | 9 ++++----
.../query/text/PostgreSQLComQueryPacket.java | 2 --
.../query/text/PostgreSQLDataRowPacket.java | 7 +++++--
.../generic/PostgreSQLCommandCompletePacket.java | 24 ++++++++--------------
.../generic/PostgreSQLErrorResponsePacket.java | 9 ++++----
.../generic/PostgreSQLReadyForQueryPacket.java | 9 ++++----
.../PostgreSQLAuthenticationMD5PasswordPacket.java | 15 +++++++-------
.../PostgreSQLAuthenticationOKPacket.java | 17 ++++++++-------
.../handshake/PostgreSQLComStartupPacket.java | 7 +++++--
.../handshake/PostgreSQLParameterStatusPacket.java | 9 ++++----
.../handshake/PostgreSQLPasswordMessagePacket.java | 2 +-
.../handshake/PostgreSQLRandomGenerator.java | 6 +++---
.../handshake/PostgreSQLSSLNegativePacket.java | 9 ++++----
.../PostgreSQLCommandPacketFactoryTest.java | 18 ++++++++--------
.../command/PostgreSQLCommandExecuteEngine.java | 2 +-
34 files changed, 117 insertions(+), 130 deletions(-)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactory.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactory.java
index 89d0874..8c43c00 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactory.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactory.java
@@ -29,8 +29,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.tex
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLComTerminationPacket;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
-import java.sql.SQLException;
-
/**
* Command packet factory for PostgreSQL.
*/
@@ -44,10 +42,8 @@ public final class PostgreSQLCommandPacketFactory {
* @param payload packet payload for PostgreSQL
* @param connectionId connection id
* @return command packet for PostgreSQL
- * @throws SQLException SQL exception
*/
- public static PostgreSQLCommandPacket newInstance(
- final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLPacketPayload payload, final int connectionId) throws SQLException {
+ public static PostgreSQLCommandPacket newInstance(final PostgreSQLCommandPacketType commandPacketType, final PostgreSQLPacketPayload payload, final int connectionId) {
switch (commandPacketType) {
case QUERY:
return new PostgreSQLComQueryPacket(payload);
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
index b0d0451..df94004 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketType.java
@@ -119,7 +119,7 @@ public enum PostgreSQLCommandPacketType implements CommandPacketType {
PASSWORD_MESSAGE('p'),
PORTAL_SUSPENDED('s'),
-
+
SASL_INITIAL_RESPONSE('p'),
SASL_RESPONSE('p'),
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 bf50ef8..749b55d 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
@@ -32,9 +32,6 @@ import java.util.Collection;
public final class PostgreSQLRowDescriptionPacket implements PostgreSQLPacket {
@Getter
- private final char messageType = PostgreSQLCommandPacketType.ROW_DESCRIPTION.getValue();
-
- @Getter
private final int fieldCount;
private final Collection<PostgreSQLColumnDescription> columnDescriptions;
@@ -52,4 +49,9 @@ public final class PostgreSQLRowDescriptionPacket implements PostgreSQLPacket {
payload.writeInt2(each.getDataFormat());
}
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.ROW_DESCRIPTION.getValue();
+ }
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/PostgreSQLBinaryStatement.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/PostgreSQLBinaryStatement.java
index ef6d4f8..3cd01d2 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/PostgreSQLBinaryStatement.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/PostgreSQLBinaryStatement.java
@@ -19,7 +19,6 @@ package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.bi
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import lombok.Setter;
import java.util.List;
@@ -28,7 +27,6 @@ import java.util.List;
*/
@RequiredArgsConstructor
@Getter
-@Setter
public final class PostgreSQLBinaryStatement {
private final String sql;
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 91d6e2f..4a719df 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
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind;
-import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.binary.BinaryCell;
import org.apache.shardingsphere.db.protocol.binary.BinaryRow;
@@ -33,9 +32,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
@RequiredArgsConstructor
public final class PostgreSQLBinaryResultSetRowPacket implements PostgreSQLPacket {
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.DATA_ROW.getValue();
-
private final BinaryRow row;
@Override
@@ -52,4 +48,9 @@ public final class PostgreSQLBinaryResultSetRowPacket implements PostgreSQLPacke
binaryProtocolValue.write(payload, value);
}
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.DATA_ROW.getValue();
+ }
}
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 e9eba01..0923c71 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,7 +17,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind;
-import lombok.Getter;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -27,10 +26,12 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
*/
public final class PostgreSQLBindCompletePacket implements PostgreSQLPacket {
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.BIND_COMPLETE.getValue();
-
@Override
public void write(final PostgreSQLPacketPayload payload) {
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.BIND_COMPLETE.getValue();
+ }
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java
index 5211b20..8bac816 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLComBindPacket.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind;
import lombok.Getter;
-import lombok.ToString;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.BinaryStatementRegistry;
@@ -36,7 +35,6 @@ import java.util.List;
* Command bind packet for PostgreSQL.
*/
@Getter
-@ToString
public final class PostgreSQLComBindPacket extends PostgreSQLCommandPacket {
private final String statementId;
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLTypeUnspecifiedSQLParameter.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLTypeUnspecifiedSQLParameter.java
index 3749055..fda1c2b 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLTypeUnspecifiedSQLParameter.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/PostgreSQLTypeUnspecifiedSQLParameter.java
@@ -17,19 +17,17 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind;
+import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.parameter.TypeUnspecifiedSQLParameter;
/**
* Type unspecified SQL parameter for PostgreSQL.
*/
+@RequiredArgsConstructor
public final class PostgreSQLTypeUnspecifiedSQLParameter implements TypeUnspecifiedSQLParameter {
private final String parameterValue;
- public PostgreSQLTypeUnspecifiedSQLParameter(final String parameterValue) {
- this.parameterValue = parameterValue;
- }
-
@Override
public String toString() {
return parameterValue;
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLArrayParameterDecoder.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLArrayParameterDecoder.java
index 0439ea9..3ae71c1 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLArrayParameterDecoder.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLArrayParameterDecoder.java
@@ -186,20 +186,20 @@ public final class PostgreSQLArrayParameterDecoder {
throw new IllegalArgumentException("value not start with '{' or not end with '}'");
}
String[] elements = value.substring(1, value.length() - 1).split(",");
- return Arrays.stream(elements).map(e -> {
- if ("NULL".equals(e)) {
+ return Arrays.stream(elements).map(each -> {
+ if ("NULL".equals(each)) {
return null;
}
- if ('"' == e.charAt(0) && '"' == e.charAt(e.length() - 1)) {
- e = e.substring(1, e.length() - 1);
+ if ('"' == each.charAt(0) && '"' == each.charAt(each.length() - 1)) {
+ each = each.substring(1, each.length() - 1);
}
- while (e.contains("\\\"")) {
- e = e.replace("\\\"", "\"");
+ while (each.contains("\\\"")) {
+ each = each.replace("\\\"", "\"");
}
- while (e.contains("\\\\")) {
- e = e.replace("\\\\", "\\");
+ while (each.contains("\\\\")) {
+ each = each.replace("\\\\", "\\");
}
- return e;
+ return each;
}).collect(Collectors.toCollection(ArrayList::new));
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLBoolArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLBoolArrayBinaryProtocolValue.java
index 25f53d2..ccf99bf 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLBoolArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLBoolArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLBoolArrayBinaryProtocolValue implements PostgreSQLB
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLBoolArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLBoolArrayBinaryProtocolValue implements PostgreSQLB
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLBoolArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat4ArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat4ArrayBinaryProtocolValue.java
index c4af6a1..98945b8 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat4ArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat4ArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLFloat4ArrayBinaryProtocolValue implements PostgreSQ
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLFloat4ArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLFloat4ArrayBinaryProtocolValue implements PostgreSQ
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLFloat4ArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat8ArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat8ArrayBinaryProtocolValue.java
index 5adb06b..9d7d039 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat8ArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLFloat8ArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLFloat8ArrayBinaryProtocolValue implements PostgreSQ
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLFloat8ArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLFloat8ArrayBinaryProtocolValue implements PostgreSQ
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLFloat8ArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2ArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2ArrayBinaryProtocolValue.java
index 4494601..abaa167 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2ArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt2ArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLInt2ArrayBinaryProtocolValue implements PostgreSQLB
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLInt2ArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLInt2ArrayBinaryProtocolValue implements PostgreSQLB
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLInt2ArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4ArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4ArrayBinaryProtocolValue.java
index 6b02ae4..8d9525b 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4ArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt4ArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLInt4ArrayBinaryProtocolValue implements PostgreSQLB
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLInt4ArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLInt4ArrayBinaryProtocolValue implements PostgreSQLB
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLInt4ArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8ArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8ArrayBinaryProtocolValue.java
index 56ced5a..b86f6c7 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8ArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLInt8ArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLInt8ArrayBinaryProtocolValue implements PostgreSQLB
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLInt8ArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLInt8ArrayBinaryProtocolValue implements PostgreSQLB
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLInt8ArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLNumericBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLNumericBinaryProtocolValue.java
index be72c5f..99a4e22 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLNumericBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLNumericBinaryProtocolValue.java
@@ -17,9 +17,10 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.bind.protocol;
+import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
-import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
/**
* Binary protocol value for numeric for PostgreSQL.
@@ -28,10 +29,7 @@ public final class PostgreSQLNumericBinaryProtocolValue implements PostgreSQLBin
@Override
public int getColumnLength(final Object value) {
- if (null == value) {
- return 0;
- }
- return value.toString().getBytes(StandardCharsets.UTF_8).length;
+ return null == value ? 0 : value.toString().getBytes(StandardCharsets.UTF_8).length;
}
@Override
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringArrayBinaryProtocolValue.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringArrayBinaryProtocolValue.java
index ed953ce..c8ea77d 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringArrayBinaryProtocolValue.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/protocol/PostgreSQLStringArrayBinaryProtocolValue.java
@@ -28,7 +28,7 @@ public final class PostgreSQLStringArrayBinaryProtocolValue implements PostgreSQ
@Override
public int getColumnLength(final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLStringArrayBinaryProtocolValue.getColumnLength()");
}
@Override
@@ -41,6 +41,6 @@ public final class PostgreSQLStringArrayBinaryProtocolValue implements PostgreSQ
@Override
public void write(final PostgreSQLPacketPayload payload, final Object value) {
- throw new UnsupportedOperationException();
+ throw new UnsupportedOperationException("PostgreSQLStringArrayBinaryProtocolValue.write()");
}
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacket.java
index 35e8958..d4d7b70 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/describe/PostgreSQLComDescribePacket.java
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.describe;
-import lombok.Getter;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -25,7 +24,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
/**
* Command describe packet for PostgreSQL.
*/
-@Getter
public final class PostgreSQLComDescribePacket extends PostgreSQLCommandPacket {
public PostgreSQLComDescribePacket(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/PostgreSQLComParsePacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacket.java
index 911bf55..2f0c5fe 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/parse/PostgreSQLComParsePacket.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.parse;
import lombok.Getter;
-import lombok.ToString;
import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLBinaryColumnType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
@@ -33,7 +32,6 @@ import java.util.List;
* Command parse packet for PostgreSQL.
*/
@Getter
-@ToString
public final class PostgreSQLComParsePacket extends PostgreSQLCommandPacket {
private final String statementId;
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 2a85db5..b338158 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,7 +17,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.parse;
-import lombok.Getter;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -25,12 +24,14 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
/**
* Parse complete packet for PostgreSQL.
*/
-@Getter
public final class PostgreSQLParseCompletePacket implements PostgreSQLPacket {
- private final char messageType = PostgreSQLCommandPacketType.PARSE_COMPLETE.getValue();
-
@Override
public void write(final PostgreSQLPacketPayload payload) {
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.PARSE_COMPLETE.getValue();
+ }
}
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacket.java
index bdab4dc..ef45f2f 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/text/PostgreSQLComQueryPacket.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.text;
import lombok.Getter;
-import lombok.ToString;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -27,7 +26,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
* Command query packet for PostgreSQL.
*/
@Getter
-@ToString
public final class PostgreSQLComQueryPacket extends PostgreSQLCommandPacket {
private final String sql;
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 e655c4a..c4347c4 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
@@ -36,8 +36,6 @@ import java.util.Collection;
@Slf4j
public final class PostgreSQLDataRowPacket implements PostgreSQLPacket {
- private final char messageType = PostgreSQLCommandPacketType.DATA_ROW.getValue();
-
private final Collection<Object> data;
@Override
@@ -69,4 +67,9 @@ public final class PostgreSQLDataRowPacket implements PostgreSQLPacket {
log.error("PostgreSQL DataRowPacket write SQLXML type exception", ex);
}
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.DATA_ROW.getValue();
+ }
}
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 317fb5d..a60ba42 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
-import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -25,31 +25,25 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
/**
* Command complete packet for PostgreSQL.
*/
+@RequiredArgsConstructor
public final class PostgreSQLCommandCompletePacket implements PostgreSQLPacket {
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.COMMAND_COMPLETE.getValue();
-
private final String sqlCommand;
private final long rowCount;
public PostgreSQLCommandCompletePacket() {
- sqlCommand = "";
- rowCount = 0;
+ this("", 0);
}
- public PostgreSQLCommandCompletePacket(final String sqlCommand, final long rowCount) {
- this.sqlCommand = sqlCommand;
- this.rowCount = rowCount;
+ @Override
+ public void write(final PostgreSQLPacketPayload payload) {
+ String delimiter = "INSERT".equals(sqlCommand) ? " 0 " : " ";
+ payload.writeStringNul(String.join(delimiter, sqlCommand, Long.toString(rowCount)));
}
@Override
- public void write(final PostgreSQLPacketPayload payload) {
- if ("INSERT".equals(sqlCommand)) {
- payload.writeStringNul(sqlCommand + " 0 " + rowCount);
- } else {
- payload.writeStringNul(sqlCommand + " " + rowCount);
- }
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.COMMAND_COMPLETE.getValue();
}
}
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 0838211..9fa9f53 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,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
-import lombok.Getter;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -69,9 +68,6 @@ public final class PostgreSQLErrorResponsePacket implements PostgreSQLPacket {
public static final char FIELD_TYPE_ROUTINE = 'R';
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.ERROR_RESPONSE.getValue();
-
private final Map<Character, String> fields = new HashMap<>();
@Override
@@ -92,4 +88,9 @@ public final class PostgreSQLErrorResponsePacket implements PostgreSQLPacket {
public void addField(final char fieldType, final String fieldValue) {
fields.put(fieldType, fieldValue);
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.ERROR_RESPONSE.getValue();
+ }
}
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 4e5f833..1dd9643 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,7 +17,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.generic;
-import lombok.Getter;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -29,11 +28,13 @@ public final class PostgreSQLReadyForQueryPacket implements PostgreSQLPacket {
private static final char STATUS = 'I';
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.READY_FOR_QUERY.getValue();
-
@Override
public void write(final PostgreSQLPacketPayload payload) {
payload.writeInt1(STATUS);
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.READY_FOR_QUERY.getValue();
+ }
}
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 59f0d62..530be88 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
-import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -25,22 +25,21 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
/**
* AuthenticationMD5Password (backend) packet for PostgreSQL.
*/
+@RequiredArgsConstructor
public final class PostgreSQLAuthenticationMD5PasswordPacket implements PostgreSQLPacket {
private static final int AUTH_REQ_MD5 = 5;
private final byte[] md5Salt;
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.AUTHENTICATION_MD5_PASSWORD.getValue();
-
- public PostgreSQLAuthenticationMD5PasswordPacket(final byte[] md5Salt) {
- this.md5Salt = md5Salt;
- }
-
@Override
public void write(final PostgreSQLPacketPayload payload) {
payload.writeInt4(AUTH_REQ_MD5);
payload.writeBytes(md5Salt);
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.AUTHENTICATION_MD5_PASSWORD.getValue();
+ }
}
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 80f18d8..2029372 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
@@ -17,7 +17,7 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
-import lombok.Getter;
+import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
@@ -25,19 +25,18 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
/**
* Authentication OK packet for PostgreSQL.
*/
+@RequiredArgsConstructor
public final class PostgreSQLAuthenticationOKPacket implements PostgreSQLPacket {
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.AUTHENTICATION_OK.getValue();
+ private final boolean success;
- private final int success;
-
- public PostgreSQLAuthenticationOKPacket(final boolean isSuccess) {
- success = isSuccess ? 0 : 1;
+ @Override
+ public void write(final PostgreSQLPacketPayload payload) {
+ payload.writeInt4(success ? 0 : 1);
}
@Override
- public void write(final PostgreSQLPacketPayload payload) {
- payload.writeInt4(success);
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.AUTHENTICATION_OK.getValue();
}
}
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 3ed20bd..b336a5a 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
@@ -30,8 +30,6 @@ import java.util.Map;
@Getter
public final class PostgreSQLComStartupPacket implements PostgreSQLPacket {
- private final char messageType = '\0';
-
private final Map<String, String> parametersMap = new HashMap<>(16, 1);
public PostgreSQLComStartupPacket(final PostgreSQLPacketPayload payload) {
@@ -44,4 +42,9 @@ 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 83fd7bc..cc48655 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
@@ -17,7 +17,6 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
-import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
@@ -29,9 +28,6 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
@RequiredArgsConstructor
public final class PostgreSQLParameterStatusPacket implements PostgreSQLPacket {
- @Getter
- private final char messageType = PostgreSQLCommandPacketType.PARAMETER_STATUS.getValue();
-
private final String key;
private final String value;
@@ -41,4 +37,9 @@ public final class PostgreSQLParameterStatusPacket implements PostgreSQLPacket {
payload.writeStringNul(key);
payload.writeStringNul(value);
}
+
+ @Override
+ public char getMessageType() {
+ return PostgreSQLCommandPacketType.PARAMETER_STATUS.getValue();
+ }
}
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 1ab4492..17c94a8 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
@@ -25,9 +25,9 @@ import org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacket
/**
* PasswordMessage (frontend) packet for PostgreSQL.
*/
+@Getter
public final class PostgreSQLPasswordMessagePacket implements PostgreSQLPacket {
- @Getter
private final String md5Digest;
public PostgreSQLPasswordMessagePacket(final PostgreSQLPacketPayload payload) {
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLRandomGenerator.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLRandomGenerator.java
index eb22060..f17759b 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLRandomGenerator.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/handshake/PostgreSQLRandomGenerator.java
@@ -17,10 +17,11 @@
package org.apache.shardingsphere.db.protocol.postgresql.packet.handshake;
-import java.util.concurrent.ThreadLocalRandom;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import java.util.concurrent.ThreadLocalRandom;
+
/**
* Random generator for PostgreSQL.
*/
@@ -41,7 +42,7 @@ public final class PostgreSQLRandomGenerator {
/**
* Generate random bytes.
*
- * @param length length for generated random bytes.
+ * @param length length for generated random bytes
* @return generated random bytes
*/
public byte[] generateRandomBytes(final int length) {
@@ -49,5 +50,4 @@ public final class PostgreSQLRandomGenerator {
ThreadLocalRandom.current().nextBytes(result);
return result;
}
-
}
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 47a807f..1f24e54 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
@@ -17,7 +17,6 @@
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.payload.PostgreSQLPacketPayload;
@@ -28,11 +27,13 @@ public final class PostgreSQLSSLNegativePacket implements PostgreSQLPacket {
private static final char STATUS_CODE = 'N';
- @Getter
- private final char messageType = '\0';
-
@Override
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/packet/command/PostgreSQLCommandPacketFactoryTest.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
index 72a3bfa..2bfcfc5 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/PostgreSQLCommandPacketFactoryTest.java
@@ -32,8 +32,6 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.sql.SQLException;
-
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.when;
@@ -45,12 +43,12 @@ public final class PostgreSQLCommandPacketFactoryTest {
private PostgreSQLPacketPayload payload;
@Test
- public void assertNewInstanceWithQueryComPacket() throws SQLException {
+ public void assertNewInstanceWithQueryComPacket() {
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.QUERY, payload, 1), instanceOf(PostgreSQLComQueryPacket.class));
}
@Test
- public void assertNewInstanceWithParseComPacket() throws SQLException {
+ public void assertNewInstanceWithParseComPacket() {
when(payload.readInt4()).thenReturn(1);
when(payload.readStringNul()).thenReturn("stat-id");
when(payload.readStringNul()).thenReturn("SELECT * FROM t_order");
@@ -59,7 +57,7 @@ public final class PostgreSQLCommandPacketFactoryTest {
}
@Test
- public void assertNewInstanceWithBindComPacket() throws SQLException {
+ public void assertNewInstanceWithBindComPacket() {
when(payload.readInt4()).thenReturn(1);
when(payload.readStringNul()).thenReturn("stat-id");
when(payload.readStringNul()).thenReturn("SELECT * FROM t_order");
@@ -69,27 +67,27 @@ public final class PostgreSQLCommandPacketFactoryTest {
}
@Test
- public void assertNewInstanceWithDescribeComPacket() throws SQLException {
+ public void assertNewInstanceWithDescribeComPacket() {
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.DESCRIBE, payload, 1), instanceOf(PostgreSQLComDescribePacket.class));
}
@Test
- public void assertNewInstanceWithExecuteComPacket() throws SQLException {
+ public void assertNewInstanceWithExecuteComPacket() {
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.EXECUTE, payload, 1), instanceOf(PostgreSQLComExecutePacket.class));
}
@Test
- public void assertNewInstanceWithSyncComPacket() throws SQLException {
+ public void assertNewInstanceWithSyncComPacket() {
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.SYNC, payload, 1), instanceOf(PostgreSQLComSyncPacket.class));
}
@Test
- public void assertNewInstanceWithTerminationComPacket() throws SQLException {
+ public void assertNewInstanceWithTerminationComPacket() {
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.TERMINATE, payload, 1), instanceOf(PostgreSQLComTerminationPacket.class));
}
@Test
- public void assertNewInstanceWithUnsupportedComPacket() throws SQLException {
+ public void assertNewInstanceWithUnsupportedComPacket() {
assertThat(PostgreSQLCommandPacketFactory.newInstance(PostgreSQLCommandPacketType.PORTAL_SUSPENDED, payload, 1), instanceOf(PostgreSQLUnsupportedCommandPacket.class));
}
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
index 4e2d2f1..3e3da17 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngine.java
@@ -52,7 +52,7 @@ public final class PostgreSQLCommandExecuteEngine implements CommandExecuteEngin
}
@Override
- public PostgreSQLCommandPacket getCommandPacket(final PacketPayload payload, final CommandPacketType type, final BackendConnection backendConnection) throws SQLException {
+ public PostgreSQLCommandPacket getCommandPacket(final PacketPayload payload, final CommandPacketType type, final BackendConnection backendConnection) {
return PostgreSQLCommandPacketFactory.newInstance((PostgreSQLCommandPacketType) type, (PostgreSQLPacketPayload) payload, backendConnection.getConnectionId());
}