提交 bbd32017 编写于 作者: T terrymanu

for #1941, add DatabaseFrontendEngine.getCommandPacketTypeLoader

上级 097df8f8
......@@ -108,6 +108,11 @@ public final class MySQLFrontendEngine implements DatabaseFrontendEngine {
}
}
@Override
public MySQLCommandPacketTypeLoader getCommandPacketTypeLoader(final PacketPayload payload) {
return new MySQLCommandPacketTypeLoader((MySQLPacketPayload) payload);
}
@Override
public void executeCommand(final ChannelHandlerContext context, final PacketPayload packetPayload, final BackendConnection backendConnection) {
try {
......@@ -126,7 +131,7 @@ public final class MySQLFrontendEngine implements DatabaseFrontendEngine {
}
private void writePackets(final ChannelHandlerContext context, final MySQLPacketPayload payload, final BackendConnection backendConnection) throws SQLException {
MySQLCommandPacketType commandPacketType = new MySQLCommandPacketTypeLoader(payload).getCommandPacketType();
MySQLCommandPacketType commandPacketType = getCommandPacketTypeLoader(payload).getCommandPacketType();
MySQLCommandPacket commandPacket = MySQLCommandPacketFactory.newInstance(commandPacketType, payload);
CommandExecutor<MySQLPacket> commandPacketExecutor = MySQLCommandExecutorFactory.newInstance(commandPacketType, commandPacket, backendConnection);
Collection<MySQLPacket> responsePackets = commandPacketExecutor.execute();
......
......@@ -116,6 +116,11 @@ public final class PostgreSQLFrontendEngine implements DatabaseFrontendEngine {
}
}
@Override
public PostgreSQLCommandPacketTypeLoader getCommandPacketTypeLoader(final PacketPayload payload) {
return new PostgreSQLCommandPacketTypeLoader((PostgreSQLPacketPayload) payload);
}
@Override
public void executeCommand(final ChannelHandlerContext context, final PacketPayload packetPayload, final BackendConnection backendConnection) {
try {
......@@ -131,7 +136,7 @@ public final class PostgreSQLFrontendEngine implements DatabaseFrontendEngine {
}
private void writePackets(final ChannelHandlerContext context, final PostgreSQLPacketPayload payload, final BackendConnection backendConnection) throws SQLException {
PostgreSQLCommandPacketType commandPacketType = new PostgreSQLCommandPacketTypeLoader(payload).getCommandPacketType();
PostgreSQLCommandPacketType commandPacketType = getCommandPacketTypeLoader(payload).getCommandPacketType();
PostgreSQLCommandPacket commandPacket = PostgreSQLCommandPacketFactory.newInstance(commandPacketType, payload, backendConnection.getConnectionId());
CommandExecutor<PostgreSQLPacket> commandPacketExecutor = PostgreSQLCommandExecutorFactory.newInstance(commandPacketType, commandPacket, backendConnection);
Collection<PostgreSQLPacket> responsePackets = commandPacketExecutor.execute();
......
......@@ -20,6 +20,7 @@ package org.apache.shardingsphere.shardingproxy.frontend.spi;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import org.apache.shardingsphere.shardingproxy.backend.communication.jdbc.connection.BackendConnection;
import org.apache.shardingsphere.shardingproxy.transport.api.packet.CommandPacketTypeLoader;
import org.apache.shardingsphere.shardingproxy.transport.api.payload.PacketPayload;
/**
......@@ -69,6 +70,14 @@ public interface DatabaseFrontendEngine {
*/
boolean auth(ChannelHandlerContext context, ByteBuf message, BackendConnection backendConnection);
/**
* Get command packet type loader.
*
* @param packetPayload packet payload
* @return command packet type loader
*/
CommandPacketTypeLoader getCommandPacketTypeLoader(PacketPayload packetPayload);
/**
* Execute command.
*
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.shardingproxy.transport.common.packet.CommandPacketType;
import org.apache.shardingsphere.shardingproxy.transport.api.packet.CommandPacketType;
/**
* MySQL command packet type.
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shardingproxy.transport.mysql.packet.command;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.shardingproxy.transport.common.packet.CommandPacketTypeLoader;
import org.apache.shardingsphere.shardingproxy.transport.api.packet.CommandPacketTypeLoader;
import org.apache.shardingsphere.shardingproxy.transport.mysql.payload.MySQLPacketPayload;
/**
......
......@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shardingproxy.transport.postgresql.packet.comm
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.shardingproxy.transport.common.packet.CommandPacketType;
import org.apache.shardingsphere.shardingproxy.transport.api.packet.CommandPacketType;
/**
* PostgreSQL command packet type.
......
......@@ -18,7 +18,7 @@
package org.apache.shardingsphere.shardingproxy.transport.postgresql.packet.command;
import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.shardingproxy.transport.common.packet.CommandPacketTypeLoader;
import org.apache.shardingsphere.shardingproxy.transport.api.packet.CommandPacketTypeLoader;
import org.apache.shardingsphere.shardingproxy.transport.postgresql.payload.PostgreSQLPacketPayload;
/**
......
......@@ -15,14 +15,14 @@
* limitations under the License.
*/
package org.apache.shardingsphere.shardingproxy.transport.common.packet;
package org.apache.shardingsphere.shardingproxy.transport.api.packet;
/**
* Command packet type loader.
*
* @param <T> Type of command packet type
*
* @author zhangliang
*
* @param <T> Type of command packet type
*/
public interface CommandPacketTypeLoader<T extends CommandPacketType> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册