From 2124346c0752d2193bc147c13d4c3918635ec6df Mon Sep 17 00:00:00 2001 From: terrymanu Date: Sat, 21 Jul 2018 14:06:19 +0800 Subject: [PATCH] refactor ExecuteUpdateResponse --- .../backend/common/jdbc/JDBCBackendHandler.java | 10 +++++----- .../memory/ConnectionStrictlyExecuteEngine.java | 2 +- .../jdbc/execute/response/ExecuteUpdateResponse.java | 12 ++++++------ .../execute/stream/MemoryStrictlyExecuteEngine.java | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/JDBCBackendHandler.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/JDBCBackendHandler.java index 59b9312e09a51..6e14f402f204b 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/JDBCBackendHandler.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/JDBCBackendHandler.java @@ -116,7 +116,7 @@ private CommandResponsePackets execute(final SQLRouteResult routeResult) throws executeResponse = executeEngine.execute(routeResult, isReturnGeneratedKeys); CommandResponsePackets result = merge(sqlStatement); if (!ruleRegistry.isMasterSlaveOnly()) { - ProxyShardingRefreshHandler.build(routeResult.getSqlStatement()).execute(); + ProxyShardingRefreshHandler.build(sqlStatement).execute(); } return result; } @@ -129,11 +129,11 @@ private boolean isUnsupportedXA(final SQLType sqlType) throws SystemException { private CommandResponsePackets merge(final SQLStatement sqlStatement) { if (executeResponse instanceof ExecuteUpdateResponse) { Collection headPackets = new LinkedList<>(); - for (CommandResponsePackets each : ((ExecuteUpdateResponse) executeResponse).getPacketsList()) { - if (each.getHeadPacket() instanceof ErrPacket) { - return new CommandResponsePackets(each.getHeadPacket()); + for (DatabasePacket each : ((ExecuteUpdateResponse) executeResponse).getPacketsList()) { + if (each instanceof ErrPacket) { + return new CommandResponsePackets(each); } - headPackets.add(each.getHeadPacket()); + headPackets.add(each); } return mergeUpdate(headPackets); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java index 4bd6414114676..13e71c2b353db 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/memory/ConnectionStrictlyExecuteEngine.java @@ -131,7 +131,7 @@ private ExecuteResponse getExecuteUpdateResponse(final Collection> each : futureList) { try { for (ExecuteResponseUnit executeResponse : each.get()) { - result.getPacketsList().add(executeResponse.getCommandResponsePackets()); + result.getPacketsList().add(executeResponse.getCommandResponsePackets().getHeadPacket()); } } catch (final InterruptedException | ExecutionException ex) { throw new ShardingException(ex.getMessage(), ex); diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/response/ExecuteUpdateResponse.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/response/ExecuteUpdateResponse.java index 2b798ec7144e7..4058cf6abc20d 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/response/ExecuteUpdateResponse.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/response/ExecuteUpdateResponse.java @@ -18,7 +18,7 @@ package io.shardingsphere.proxy.backend.common.jdbc.execute.response; import io.shardingsphere.proxy.backend.common.jdbc.execute.response.unit.ExecuteResponseUnit; -import io.shardingsphere.proxy.transport.mysql.packet.command.reponse.CommandResponsePackets; +import io.shardingsphere.proxy.transport.common.packet.DatabasePacket; import lombok.Getter; import java.util.Collection; @@ -33,18 +33,18 @@ @Getter public final class ExecuteUpdateResponse implements ExecuteResponse { - private final List packetsList = new LinkedList<>(); + private final List packetsList = new LinkedList<>(); - private final CommandResponsePackets firstPackets; + private final DatabasePacket firstPackets; - public ExecuteUpdateResponse(final CommandResponsePackets packets) { - packetsList.add(packets); + public ExecuteUpdateResponse(final DatabasePacket packet) { + packetsList.add(packet); firstPackets = packetsList.iterator().next(); } public ExecuteUpdateResponse(final Collection responseUnits) { for (ExecuteResponseUnit each : responseUnits) { - packetsList.add(each.getCommandResponsePackets()); + packetsList.add(each.getCommandResponsePackets().getHeadPacket()); } firstPackets = packetsList.iterator().next(); } diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java index b6a90798f1312..574ef0b732899 100644 --- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java +++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/backend/common/jdbc/execute/stream/MemoryStrictlyExecuteEngine.java @@ -96,10 +96,10 @@ private ExecuteResponse getExecuteQueryResponse(final ExecuteQueryResponseUnit f } private ExecuteResponse getExecuteUpdateResponse(final ExecuteResponseUnit firstResponseUnit, final List> futureList) { - ExecuteUpdateResponse result = new ExecuteUpdateResponse(firstResponseUnit.getCommandResponsePackets()); + ExecuteUpdateResponse result = new ExecuteUpdateResponse(firstResponseUnit.getCommandResponsePackets().getHeadPacket()); for (Future each : futureList) { try { - result.getPacketsList().add(each.get().getCommandResponsePackets()); + result.getPacketsList().add(each.get().getCommandResponsePackets().getHeadPacket()); } catch (final InterruptedException | ExecutionException ex) { throw new ShardingException(ex.getMessage(), ex); }