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 47b7c5b Use ResponseType to refactor QueryCommandExecutor
new d126a9c Merge pull request #7352 from terrymanu/dev
47b7c5b is described below
commit 47b7c5bb3a2774bcf19dc7df9fe08c0aa32e7bd4
Author: terrymanu <[email protected]>
AuthorDate: Wed Sep 9 16:59:15 2020 +0800
Use ResponseType to refactor QueryCommandExecutor
---
.../mysql/command/MySQLCommandExecuteEngine.java | 3 ++-
.../execute/MySQLComStmtExecuteExecutor.java | 20 ++++++-----------
.../text/query/MySQLComQueryPacketExecutor.java | 17 +++++---------
.../execute/MySQLComStmtExecuteExecutorTest.java | 7 +++---
.../query/MySQLComQueryPacketExecutorTest.java | 7 +++---
.../command/PostgreSQLCommandExecuteEngine.java | 5 +++--
.../binary/bind/PostgreSQLComBindExecutor.java | 19 +++++++---------
.../query/text/PostgreSQLComQueryExecutor.java | 19 +++++++---------
.../PostgreSQLCommandExecuteEngineTest.java | 4 ++--
.../binary/bind/PostgreSQLComBindExecutorTest.java | 7 +++---
.../query/text/PostgreSQLComQueryExecutorTest.java | 3 ++-
.../command/executor/QueryCommandExecutor.java | 20 +++--------------
.../frontend/command/executor/ResponseType.java | 26 ++++++++++++++++++++++
13 files changed, 79 insertions(+), 78 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
index 07a9ea8..fa3e46a 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/MySQLCommandExecuteEngine.java
@@ -35,6 +35,7 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory;
import java.sql.SQLException;
@@ -74,7 +75,7 @@ public final class MySQLCommandExecuteEngine implements
CommandExecuteEngine {
@SneakyThrows(InterruptedException.class)
public void writeQueryData(final ChannelHandlerContext context,
final BackendConnection backendConnection,
final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount)
throws SQLException {
- if (!queryCommandExecutor.isQueryResponse() ||
!context.channel().isActive()) {
+ if (ResponseType.QUERY != queryCommandExecutor.getResponseType() ||
!context.channel().isActive()) {
return;
}
int count = 0;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
index 2b0c825..d3fee41 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
@@ -33,13 +33,14 @@ import
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.Que
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -58,19 +59,12 @@ public final class MySQLComStmtExecuteExecutor implements
QueryCommandExecutor {
private final DatabaseCommunicationEngine databaseCommunicationEngine;
@Getter
- private volatile boolean isQueryResponse;
-
- @Getter
- private volatile boolean isUpdateResponse;
-
- @Getter
- private volatile boolean isErrorResponse;
+ private volatile ResponseType responseType;
private int currentSequenceId;
public MySQLComStmtExecuteExecutor(final MySQLComStmtExecutePacket
comStmtExecutePacket, final BackendConnection backendConnection) {
- SQLStatement sqlStatement =
-
ProxyContext.getInstance().getSchema(backendConnection.getSchema()).getRuntimeContext().getSqlParserEngine().parse(comStmtExecutePacket.getSql(),
true);
+ SQLStatement sqlStatement =
ProxyContext.getInstance().getSchema(backendConnection.getSchema()).getRuntimeContext().getSqlParserEngine().parse(comStmtExecutePacket.getSql(),
true);
databaseCommunicationEngine =
DatabaseCommunicationEngineFactory.getInstance().newBinaryProtocolInstance(sqlStatement,
comStmtExecutePacket.getSql(),
comStmtExecutePacket.getParameters(), backendConnection);
}
@@ -82,14 +76,14 @@ public final class MySQLComStmtExecuteExecutor implements
QueryCommandExecutor {
}
BackendResponse backendResponse = getBackendResponse();
if (backendResponse instanceof QueryResponse) {
- isQueryResponse = true;
+ responseType = ResponseType.QUERY;
return createQueryPacket((QueryResponse) backendResponse);
}
if (backendResponse instanceof UpdateResponse) {
- isUpdateResponse = true;
+ responseType = ResponseType.UPDATE;
return
Collections.singletonList(createUpdatePacket((UpdateResponse) backendResponse));
}
- isErrorResponse = true;
+ responseType = ResponseType.ERROR;
return Collections.singletonList(createErrorPacket(((ErrorResponse)
backendResponse).getCause()));
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
index 8bdb7c7..a9fbc66 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
@@ -33,14 +33,15 @@ import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.apache.shardingsphere.proxy.frontend.mysql.MySQLErrPacketFactory;
import java.sql.SQLException;
@@ -57,13 +58,7 @@ public final class MySQLComQueryPacketExecutor implements
QueryCommandExecutor {
private final TextProtocolBackendHandler textProtocolBackendHandler;
@Getter
- private volatile boolean isQueryResponse;
-
- @Getter
- private volatile boolean isUpdateResponse;
-
- @Getter
- private volatile boolean isErrorResponse;
+ private volatile ResponseType responseType;
private int currentSequenceId;
@@ -78,14 +73,14 @@ public final class MySQLComQueryPacketExecutor implements
QueryCommandExecutor {
}
BackendResponse backendResponse = getBackendResponse();
if (backendResponse instanceof QueryResponse) {
- isQueryResponse = true;
+ responseType = ResponseType.QUERY;
return createQueryPackets((QueryResponse) backendResponse);
}
if (backendResponse instanceof UpdateResponse) {
- isUpdateResponse = true;
+ responseType = ResponseType.UPDATE;
return
Collections.singletonList(createUpdatePacket((UpdateResponse) backendResponse));
}
- isErrorResponse = true;
+ responseType = ResponseType.ERROR;
return Collections.singletonList(createErrorPacket(((ErrorResponse)
backendResponse).getCause()));
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
index 37aab46..e1df5bf 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutorTest.java
@@ -31,6 +31,7 @@ import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import
org.apache.shardingsphere.rdl.parser.engine.ShardingSphereSQLParserEngine;
import org.junit.Before;
import org.junit.Test;
@@ -84,7 +85,7 @@ public final class MySQLComStmtExecuteExecutorTest {
FieldSetter.setField(mysqlComStmtExecuteExecutor,
MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"),
databaseCommunicationEngine);
when(databaseCommunicationEngine.execute()).thenReturn(new
QueryResponse(Collections.singletonList(mock(QueryHeader.class))));
mysqlComStmtExecuteExecutor.execute();
- assertThat(mysqlComStmtExecuteExecutor.isQueryResponse(), is(true));
+ assertThat(mysqlComStmtExecuteExecutor.getResponseType(),
is(ResponseType.QUERY));
}
@Test
@@ -95,7 +96,7 @@ public final class MySQLComStmtExecuteExecutorTest {
FieldSetter.setField(mysqlComStmtExecuteExecutor,
MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"),
databaseCommunicationEngine);
when(databaseCommunicationEngine.execute()).thenReturn(new
UpdateResponse());
mysqlComStmtExecuteExecutor.execute();
- assertThat(mysqlComStmtExecuteExecutor.isUpdateResponse(), is(true));
+ assertThat(mysqlComStmtExecuteExecutor.getResponseType(),
is(ResponseType.UPDATE));
}
@Test
@@ -106,6 +107,6 @@ public final class MySQLComStmtExecuteExecutorTest {
FieldSetter.setField(mysqlComStmtExecuteExecutor,
MySQLComStmtExecuteExecutor.class.getDeclaredField("databaseCommunicationEngine"),
databaseCommunicationEngine);
when(databaseCommunicationEngine.execute()).thenReturn(new
ErrorResponse(sqlException));
mysqlComStmtExecuteExecutor.execute();
- assertThat(mysqlComStmtExecuteExecutor.isErrorResponse(), is(true));
+ assertThat(mysqlComStmtExecuteExecutor.getResponseType(),
is(ResponseType.ERROR));
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
index b197d1b..f4ba747 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutorTest.java
@@ -23,6 +23,7 @@ import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -53,7 +54,7 @@ public final class MySQLComQueryPacketExecutorTest {
FieldSetter.setField(mysqlComQueryPacketExecutor,
MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"),
textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new
QueryResponse(Collections.singletonList(mock(QueryHeader.class))));
mysqlComQueryPacketExecutor.execute();
- assertThat(mysqlComQueryPacketExecutor.isQueryResponse(), is(true));
+ assertThat(mysqlComQueryPacketExecutor.getResponseType(),
is(ResponseType.QUERY));
}
@Test
@@ -61,7 +62,7 @@ public final class MySQLComQueryPacketExecutorTest {
FieldSetter.setField(mysqlComQueryPacketExecutor,
MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"),
textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new
UpdateResponse());
mysqlComQueryPacketExecutor.execute();
- assertThat(mysqlComQueryPacketExecutor.isUpdateResponse(), is(true));
+ assertThat(mysqlComQueryPacketExecutor.getResponseType(),
is(ResponseType.UPDATE));
}
@Test
@@ -69,6 +70,6 @@ public final class MySQLComQueryPacketExecutorTest {
FieldSetter.setField(mysqlComQueryPacketExecutor,
MySQLComQueryPacketExecutor.class.getDeclaredField("textProtocolBackendHandler"),
textProtocolBackendHandler);
when(textProtocolBackendHandler.execute()).thenReturn(new
ErrorResponse(sqlException));
mysqlComQueryPacketExecutor.execute();
- assertThat(mysqlComQueryPacketExecutor.isErrorResponse(), is(true));
+ assertThat(mysqlComQueryPacketExecutor.getResponseType(),
is(ResponseType.ERROR));
}
}
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 c7ff500..65b5040 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
@@ -37,6 +37,7 @@ import
org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.frontend.command.executor.CommandExecutor;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
import org.apache.shardingsphere.proxy.frontend.command.CommandExecuteEngine;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import java.sql.SQLException;
import java.util.Optional;
@@ -77,12 +78,12 @@ public final class PostgreSQLCommandExecuteEngine
implements CommandExecuteEngin
@SneakyThrows(InterruptedException.class)
public void writeQueryData(final ChannelHandlerContext context,
final BackendConnection backendConnection,
final QueryCommandExecutor queryCommandExecutor, final int headerPackagesCount)
throws SQLException {
- if (queryCommandExecutor.isQueryResponse() &&
!context.channel().isActive()) {
+ if (ResponseType.QUERY == queryCommandExecutor.getResponseType() &&
!context.channel().isActive()) {
context.write(new PostgreSQLCommandCompletePacket());
context.write(new PostgreSQLReadyForQueryPacket());
return;
}
- if (queryCommandExecutor.isErrorResponse() ||
queryCommandExecutor.isUpdateResponse()) {
+ if (ResponseType.ERROR == queryCommandExecutor.getResponseType() ||
ResponseType.UPDATE == queryCommandExecutor.getResponseType()) {
context.write(new PostgreSQLReadyForQueryPacket());
return;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
index 0f21f45..e126b51 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutor.java
@@ -35,13 +35,14 @@ import
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.Que
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import
org.apache.shardingsphere.proxy.frontend.postgresql.PostgreSQLErrPacketFactory;
import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -64,13 +65,7 @@ public final class PostgreSQLComBindExecutor implements
QueryCommandExecutor {
private final DatabaseCommunicationEngine databaseCommunicationEngine;
@Getter
- private volatile boolean isQueryResponse;
-
- @Getter
- private volatile boolean isUpdateResponse;
-
- @Getter
- private volatile boolean isErrorResponse;
+ private volatile ResponseType responseType;
public PostgreSQLComBindExecutor(final PostgreSQLComBindPacket packet,
final BackendConnection backendConnection) {
this.packet = packet;
@@ -99,11 +94,11 @@ public final class PostgreSQLComBindExecutor implements
QueryCommandExecutor {
createQueryPacket((QueryResponse)
backendResponse).ifPresent(result::add);
}
if (backendResponse instanceof UpdateResponse) {
- isUpdateResponse = true;
+ responseType = ResponseType.UPDATE;
result.add(createUpdatePacket((UpdateResponse) backendResponse));
}
if (backendResponse instanceof ErrorResponse) {
- isErrorResponse = true;
+ responseType = ResponseType.ERROR;
result.add(createErrorPacket((ErrorResponse) backendResponse));
}
return result;
@@ -123,7 +118,9 @@ public final class PostgreSQLComBindExecutor implements
QueryCommandExecutor {
private Optional<PostgreSQLRowDescriptionPacket> createQueryPacket(final
QueryResponse queryResponse) {
List<PostgreSQLColumnDescription> columnDescriptions =
getPostgreSQLColumnDescriptions(queryResponse);
- isQueryResponse = !columnDescriptions.isEmpty();
+ if (columnDescriptions.isEmpty()) {
+ responseType = ResponseType.QUERY;
+ }
if (columnDescriptions.isEmpty() || packet.isBinaryRowData()) {
return Optional.empty();
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
index 9f494a9..f370cd8 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutor.java
@@ -30,14 +30,15 @@ import
org.apache.shardingsphere.infra.database.type.DatabaseTypes;
import org.apache.shardingsphere.infra.executor.sql.QueryResult;
import
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
import
org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandlerFactory;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import
org.apache.shardingsphere.proxy.frontend.postgresql.PostgreSQLErrPacketFactory;
import java.sql.ResultSetMetaData;
@@ -56,13 +57,7 @@ public final class PostgreSQLComQueryExecutor implements
QueryCommandExecutor {
private final TextProtocolBackendHandler textProtocolBackendHandler;
@Getter
- private volatile boolean isQueryResponse;
-
- @Getter
- private volatile boolean isUpdateResponse;
-
- @Getter
- private volatile boolean isErrorResponse;
+ private volatile ResponseType responseType;
public PostgreSQLComQueryExecutor(final PostgreSQLComQueryPacket
comQueryPacket, final BackendConnection backendConnection) {
textProtocolBackendHandler =
TextProtocolBackendHandlerFactory.newInstance(DatabaseTypes.getActualDatabaseType("PostgreSQL"),
comQueryPacket.getSql(), backendConnection);
@@ -79,10 +74,10 @@ public final class PostgreSQLComQueryExecutor implements
QueryCommandExecutor {
return
result.<List<DatabasePacket<?>>>map(Collections::singletonList).orElseGet(Collections::emptyList);
}
if (backendResponse instanceof UpdateResponse) {
- isUpdateResponse = true;
+ responseType = ResponseType.UPDATE;
return
Collections.singletonList(createUpdatePacket((UpdateResponse) backendResponse));
}
- isErrorResponse = true;
+ responseType = ResponseType.ERROR;
return Collections.singletonList(createErrorPacket((ErrorResponse)
backendResponse));
}
@@ -100,7 +95,9 @@ public final class PostgreSQLComQueryExecutor implements
QueryCommandExecutor {
private Optional<PostgreSQLRowDescriptionPacket> createQueryPacket(final
QueryResponse queryResponse) {
List<PostgreSQLColumnDescription> columnDescriptions =
getPostgreSQLColumnDescriptions(queryResponse);
- isQueryResponse = !columnDescriptions.isEmpty();
+ if (columnDescriptions.isEmpty()) {
+ responseType = ResponseType.QUERY;
+ }
if (columnDescriptions.isEmpty()) {
return Optional.empty();
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
index 0e65439..ed125ab 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/PostgreSQLCommandExecuteEngineTest.java
@@ -21,6 +21,7 @@ import io.netty.channel.ChannelHandlerContext;
import lombok.SneakyThrows;
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLReadyForQueryPacket;
import
org.apache.shardingsphere.proxy.frontend.command.executor.QueryCommandExecutor;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -44,8 +45,7 @@ public final class PostgreSQLCommandExecuteEngineTest {
@SneakyThrows
public void assertWriteQueryDataWithError() {
PostgreSQLCommandExecuteEngine postgreSQLCommandExecuteEngine = new
PostgreSQLCommandExecuteEngine();
- when(queryCommandExecutor.isQueryResponse()).thenReturn(false);
- when(queryCommandExecutor.isErrorResponse()).thenReturn(true);
+
when(queryCommandExecutor.getResponseType()).thenReturn(ResponseType.ERROR);
postgreSQLCommandExecuteEngine.writeQueryData(channelHandlerContext,
null, queryCommandExecutor, 0);
verify(channelHandlerContext,
times(1)).write(isA(PostgreSQLReadyForQueryPacket.class));
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutorTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutorTest.java
index dae796b..35b1944 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutorTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/PostgreSQLComBindExecutorTest.java
@@ -27,8 +27,9 @@ import
org.apache.shardingsphere.infra.context.impl.StandardSchemaContexts;
import org.apache.shardingsphere.infra.database.type.dialect.MySQLDatabaseType;
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngine;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -44,8 +45,8 @@ import java.util.Map;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.instanceOf;
+import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -69,7 +70,7 @@ public final class PostgreSQLComBindExecutorTest {
ErrorResponse errorResponse = new ErrorResponse(new
PSQLException(mock(ServerErrorMessage.class)));
when(databaseCommunicationEngine.execute()).thenReturn(errorResponse);
assertThat(((LinkedList) postgreSQLComBindExecutor.execute()).get(1),
instanceOf(PostgreSQLErrorResponsePacket.class));
- assertTrue(postgreSQLComBindExecutor.isErrorResponse());
+ assertThat(postgreSQLComBindExecutor.getResponseType(),
is(ResponseType.ERROR));
}
private Map<String, SchemaContext> getSchemaContextMap() {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutorTest.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutorTest.java
index a01ee43..d857c93 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutorTest.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/test/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/text/PostgreSQLComQueryExecutorTest.java
@@ -22,6 +22,7 @@ import
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.tex
import
org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLErrorResponsePacket;
import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
+import org.apache.shardingsphere.proxy.frontend.command.executor.ResponseType;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -50,6 +51,6 @@ public final class PostgreSQLComQueryExecutorTest {
ErrorResponse errorResponse = new ErrorResponse(new
PSQLException(mock(ServerErrorMessage.class)));
when(textProtocolBackendHandler.execute()).thenReturn(errorResponse);
assertThat(postgreSQLComQueryExecutor.execute().iterator().next(),
instanceOf(PostgreSQLErrorResponsePacket.class));
- assertThat(postgreSQLComQueryExecutor.isErrorResponse(), is(true));
+ assertThat(postgreSQLComQueryExecutor.getResponseType(),
is(ResponseType.ERROR));
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/QueryCommandExecutor.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/QueryCommandExecutor.java
index 49c8006..c0e5990 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/QueryCommandExecutor.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/QueryCommandExecutor.java
@@ -27,25 +27,11 @@ import java.sql.SQLException;
public interface QueryCommandExecutor extends CommandExecutor {
/**
- * Judge whether query response.
+ * Get response type.
*
- * @return is query response or not
+ * @return response type
*/
- boolean isQueryResponse();
-
- /**
- * Judge whether update response.
- *
- * @return is update response or not
- */
- boolean isUpdateResponse();
-
- /**
- * Judge whether error response.
- *
- * @return is error response or not
- */
- boolean isErrorResponse();
+ ResponseType getResponseType();
/**
* Goto next result value.
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/ResponseType.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/ResponseType.java
new file mode 100644
index 0000000..530a161
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-spi/src/main/java/org/apache/shardingsphere/proxy/frontend/command/executor/ResponseType.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.frontend.command.executor;
+
+/**
+ * Response type.
+ */
+public enum ResponseType {
+
+ QUERY, UPDATE, ERROR
+}