<commit_before>/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed 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.
 * </p>
 */

package io.shardingsphere.proxy.transport.mysql.packet.command;

import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection;
import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.UnsupportedCommandPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.initdb.ComInitDbPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.ping.ComPingPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.quit.ComQuitPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.close.ComStmtClosePacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.execute.ComStmtExecutePacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.prepare.ComStmtPreparePacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.fieldlist.ComFieldListPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * Command packet factory.
 *
 * @author zhangliang
 * @author wangkai
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class CommandPacketFactory {
    
    /**
     * Create new instance of command packet.
     *
     * @param sequenceId sequence id
     * @param connectionId MySQL connection id
     * @param payload MySQL packet payload
     * @param backendConnection backend connection
     * @return command packet
     */
    public static CommandPacket newInstance(final int sequenceId, final int connectionId, final MySQLPacketPayload payload, final BackendConnection backendConnection) {
        int commandPacketTypeValue = payload.readInt1();
        CommandPacketType type = CommandPacketType.valueOf(commandPacketTypeValue);
        switch (type) {
            case COM_QUIT:
                return new ComQuitPacket(sequenceId);
            case COM_INIT_DB:
                return new ComInitDbPacket(sequenceId, payload);
            case COM_FIELD_LIST:
                return new ComFieldListPacket(sequenceId, connectionId, payload, backendConnection);
            case COM_QUERY:
                return new ComQueryPacket(sequenceId, connectionId, payload, backendConnection);
            case COM_STMT_PREPARE:
                return new ComStmtPreparePacket(sequenceId, payload);
            case COM_STMT_EXECUTE:
                return new ComStmtExecutePacket(sequenceId, connectionId, payload, backendConnection);
            case COM_STMT_CLOSE:
                return new ComStmtClosePacket(sequenceId, payload);
            case COM_PING:
                return new ComPingPacket(sequenceId);
            case COM_SLEEP:
            case COM_CREATE_DB:
            case COM_DROP_DB:
            case COM_REFRESH:
            case COM_SHUTDOWN:
            case COM_STATISTICS:
            case COM_PROCESS_INFO:
            case COM_CONNECT:
            case COM_PROCESS_KILL:
            case COM_DEBUG:
            case COM_TIME:
            case COM_DELAYED_INSERT:
            case COM_CHANGE_USER:
            case COM_BINLOG_DUMP:
            case COM_TABLE_DUMP:
            case COM_CONNECT_OUT:
            case COM_REGISTER_SLAVE:
            case COM_STMT_SEND_LONG_DATA:
            case COM_STMT_RESET:
            case COM_SET_OPTION:
            case COM_STMT_FETCH:
            case COM_DAEMON:
            case COM_BINLOG_DUMP_GTID:
            case COM_RESET_CONNECTION:
                return new UnsupportedCommandPacket(sequenceId, type);
            default:
                return new UnsupportedCommandPacket(sequenceId, type);
        }
    }
}<commit_msg>simplify CommandPacketFactory<commit_after>/*
 * Copyright 2016-2018 shardingsphere.io.
 * <p>
 * Licensed 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.
 * </p>
 */

package io.shardingsphere.proxy.transport.mysql.packet.command;

import io.shardingsphere.proxy.backend.jdbc.connection.BackendConnection;
import io.shardingsphere.proxy.transport.mysql.packet.MySQLPacketPayload;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.UnsupportedCommandPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.initdb.ComInitDbPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.ping.ComPingPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.admin.quit.ComQuitPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.close.ComStmtClosePacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.execute.ComStmtExecutePacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.binary.prepare.ComStmtPreparePacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.fieldlist.ComFieldListPacket;
import io.shardingsphere.proxy.transport.mysql.packet.command.query.text.query.ComQueryPacket;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

/**
 * Command packet factory.
 *
 * @author zhangliang
 * @author wangkai
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class CommandPacketFactory {
    
    /**
     * Create new instance of command packet.
     *
     * @param sequenceId sequence id
     * @param connectionId MySQL connection id
     * @param payload MySQL packet payload
     * @param backendConnection backend connection
     * @return command packet
     */
    public static CommandPacket newInstance(final int sequenceId, final int connectionId, final MySQLPacketPayload payload, final BackendConnection backendConnection) {
        int commandPacketTypeValue = payload.readInt1();
        CommandPacketType type = CommandPacketType.valueOf(commandPacketTypeValue);
        switch (type) {
            case COM_QUIT:
                return new ComQuitPacket(sequenceId);
            case COM_INIT_DB:
                return new ComInitDbPacket(sequenceId, payload);
            case COM_FIELD_LIST:
                return new ComFieldListPacket(sequenceId, connectionId, payload, backendConnection);
            case COM_QUERY:
                return new ComQueryPacket(sequenceId, connectionId, payload, backendConnection);
            case COM_STMT_PREPARE:
                return new ComStmtPreparePacket(sequenceId, payload);
            case COM_STMT_EXECUTE:
                return new ComStmtExecutePacket(sequenceId, connectionId, payload, backendConnection);
            case COM_STMT_CLOSE:
                return new ComStmtClosePacket(sequenceId, payload);
            case COM_PING:
                return new ComPingPacket(sequenceId);
            default:
                return new UnsupportedCommandPacket(sequenceId, type);
        }
    }
}
{'fraction_non_alphanumeric': 0.07346120095273913, 'fraction_numerical': 0.003259370690735866, 'mean_word_length': 3.203371970495258, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2021947', 'n_tokens_mistral': 2149, 'n_tokens_neox': 2144, 'n_words': 517}