Skip to content

Commit

Permalink
refactor ExecuteUpdateResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu committed Jul 21, 2018
1 parent be15756 commit 2124346
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -129,11 +129,11 @@ private boolean isUnsupportedXA(final SQLType sqlType) throws SystemException {
private CommandResponsePackets merge(final SQLStatement sqlStatement) {
if (executeResponse instanceof ExecuteUpdateResponse) {
Collection<DatabasePacket> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private ExecuteResponse getExecuteUpdateResponse(final Collection<ExecuteRespons
for (Future<Collection<ExecuteResponseUnit>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,18 +33,18 @@
@Getter
public final class ExecuteUpdateResponse implements ExecuteResponse {

private final List<CommandResponsePackets> packetsList = new LinkedList<>();
private final List<DatabasePacket> 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<ExecuteResponseUnit> responseUnits) {
for (ExecuteResponseUnit each : responseUnits) {
packetsList.add(each.getCommandResponsePackets());
packetsList.add(each.getCommandResponsePackets().getHeadPacket());
}
firstPackets = packetsList.iterator().next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ private ExecuteResponse getExecuteQueryResponse(final ExecuteQueryResponseUnit f
}

private ExecuteResponse getExecuteUpdateResponse(final ExecuteResponseUnit firstResponseUnit, final List<Future<ExecuteResponseUnit>> futureList) {
ExecuteUpdateResponse result = new ExecuteUpdateResponse(firstResponseUnit.getCommandResponsePackets());
ExecuteUpdateResponse result = new ExecuteUpdateResponse(firstResponseUnit.getCommandResponsePackets().getHeadPacket());
for (Future<ExecuteResponseUnit> 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);
}
Expand Down

0 comments on commit 2124346

Please sign in to comment.