You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2022/06/16 10:12:50 UTC
[shardingsphere] branch master updated: Simplify MySQLComStmtPrepareExecutor (#18396)
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 add6295e079 Simplify MySQLComStmtPrepareExecutor (#18396)
add6295e079 is described below
commit add6295e079b91258f819826f3a289fe412ed036
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Thu Jun 16 18:12:46 2022 +0800
Simplify MySQLComStmtPrepareExecutor (#18396)
---
.../binary/prepare/MySQLComStmtPrepareExecutor.java | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
index f6607625549..c9c2fb6b4fb 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/prepare/MySQLComStmtPrepareExecutor.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.prepare;
import com.google.common.base.Preconditions;
+import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLBinaryColumnType;
import org.apache.shardingsphere.db.protocol.mysql.constant.MySQLConstants;
import org.apache.shardingsphere.db.protocol.mysql.packet.command.admin.MySQLComSetOptionPacket;
@@ -49,22 +50,15 @@ import java.util.Optional;
/**
* COM_STMT_PREPARE command executor for MySQL.
*/
+@RequiredArgsConstructor
public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
private final MySQLComStmtPreparePacket packet;
private final ConnectionSession connectionSession;
- private final int characterSet;
-
private int currentSequenceId;
- public MySQLComStmtPrepareExecutor(final MySQLComStmtPreparePacket packet, final ConnectionSession connectionSession) {
- this.packet = packet;
- this.connectionSession = connectionSession;
- characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
- }
-
@Override
public Collection<DatabasePacket<?>> execute() throws SQLException {
failedIfContainsMultiStatements();
@@ -104,16 +98,17 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
private Collection<DatabasePacket<?>> createPackets(final int statementId, final int projectionCount, final int parameterCount) {
Collection<DatabasePacket<?>> result = new LinkedList<>();
result.add(new MySQLComStmtPrepareOKPacket(++currentSequenceId, statementId, projectionCount, parameterCount, 0));
+ int characterSet = connectionSession.getAttributeMap().attr(MySQLConstants.MYSQL_CHARACTER_SET_ATTRIBUTE_KEY).get().getId();
if (parameterCount > 0) {
- result.addAll(createParameterColumnDefinition41Packets(parameterCount));
+ result.addAll(createParameterColumnDefinition41Packets(parameterCount, characterSet));
}
if (projectionCount > 0) {
- result.addAll(createProjectionColumnDefinition41Packets(projectionCount));
+ result.addAll(createProjectionColumnDefinition41Packets(projectionCount, characterSet));
}
return result;
}
- private Collection<DatabasePacket<?>> createParameterColumnDefinition41Packets(final int parameterCount) {
+ private Collection<DatabasePacket<?>> createParameterColumnDefinition41Packets(final int parameterCount, final int characterSet) {
Collection<DatabasePacket<?>> result = new LinkedList<>();
for (int i = 0; i < parameterCount; i++) {
result.add(new MySQLColumnDefinition41Packet(++currentSequenceId, characterSet, "", "", "", "?", "", 0, MySQLBinaryColumnType.MYSQL_TYPE_VAR_STRING, 0, false));
@@ -122,7 +117,7 @@ public final class MySQLComStmtPrepareExecutor implements CommandExecutor {
return result;
}
- private Collection<DatabasePacket<?>> createProjectionColumnDefinition41Packets(final int projectionCount) {
+ private Collection<DatabasePacket<?>> createProjectionColumnDefinition41Packets(final int projectionCount, final int characterSet) {
Collection<DatabasePacket<?>> result = new LinkedList<>();
for (int i = 0; i < projectionCount; i++) {
result.add(new MySQLColumnDefinition41Packet(++currentSequenceId, characterSet, "", "", "", "", "", 0, MySQLBinaryColumnType.MYSQL_TYPE_VAR_STRING, 0, false));