Search in sources :

Example 6 with CommandPacket

use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.

the class MySQLChannel method sendCharset.

/**
     * 发送字符集设置
     */
private void sendCharset(int ci) throws IOException {
    // 发送命令: 直接写入到out中即可
    CommandPacket cmd = getCharsetCommand(ci);
    cmd.write(out);
    out.flush();
    BinaryPacket bin = receive();
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            this.charsetIndex = ci;
            this.charset = CharsetUtil.getCharset(ci);
            this.dbCharset = CharsetUtil.getCharset(ci);
            break;
        case ErrorPacket.FIELD_COUNT:
            ErrorPacket err = new ErrorPacket();
            err.read(bin);
            throw new ErrorPacketException(new String(err.message, charset));
        default:
            throw new UnknownPacketException(bin.toString());
    }
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ErrorPacketException(com.alibaba.cobar.exception.ErrorPacketException) UnknownPacketException(com.alibaba.cobar.exception.UnknownPacketException) CommandPacket(com.alibaba.cobar.net.mysql.CommandPacket) BinaryPacket(com.alibaba.cobar.net.mysql.BinaryPacket)

Example 7 with CommandPacket

use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.

the class MySQLChannel method getCharsetCommand.

private CommandPacket getCharsetCommand(int ci) {
    String charset = CharsetUtil.getDbCharset(ci);
    StringBuilder s = new StringBuilder();
    s.append("SET names ").append(charset);
    CommandPacket cmd = new CommandPacket();
    cmd.packetId = 0;
    cmd.command = MySQLPacket.COM_QUERY;
    cmd.arg = s.toString().getBytes();
    return cmd;
}
Also used : CommandPacket(com.alibaba.cobar.net.mysql.CommandPacket)

Example 8 with CommandPacket

use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.

the class MySQLChannel method getSqlModeCommand.

private CommandPacket getSqlModeCommand() {
    StringBuilder s = new StringBuilder();
    s.append("SET sql_mode=\"").append(dsc.getSqlMode()).append('"');
    CommandPacket cmd = new CommandPacket();
    cmd.packetId = 0;
    cmd.command = MySQLPacket.COM_QUERY;
    cmd.arg = s.toString().getBytes();
    return cmd;
}
Also used : CommandPacket(com.alibaba.cobar.net.mysql.CommandPacket)

Example 9 with CommandPacket

use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.

the class MySQLChannel method sendAutocommit.

/**
     * 发送事务递交模式设置
     */
private void sendAutocommit(boolean autocommit) throws IOException {
    CommandPacket cmd = getAutocommitCommand(autocommit);
    cmd.write(out);
    out.flush();
    BinaryPacket bin = receive();
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            this.autocommit = autocommit;
            break;
        case ErrorPacket.FIELD_COUNT:
            ErrorPacket err = new ErrorPacket();
            err.read(bin);
            throw new ErrorPacketException(new String(err.message, charset));
        default:
            throw new UnknownPacketException(bin.toString());
    }
}
Also used : ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ErrorPacketException(com.alibaba.cobar.exception.ErrorPacketException) UnknownPacketException(com.alibaba.cobar.exception.UnknownPacketException) CommandPacket(com.alibaba.cobar.net.mysql.CommandPacket) BinaryPacket(com.alibaba.cobar.net.mysql.BinaryPacket)

Example 10 with CommandPacket

use of com.alibaba.cobar.net.mysql.CommandPacket in project cobar by alibaba.

the class KillConnectionHandler method connectionAcquired.

@Override
public void connectionAcquired(MySQLConnection conn) {
    conn.setResponseHandler(this);
    CommandPacket packet = new CommandPacket();
    packet.packetId = 0;
    packet.command = MySQLPacket.COM_QUERY;
    packet.arg = new StringBuilder("KILL ").append(killee.getThreadId()).toString().getBytes();
    packet.write(conn);
}
Also used : CommandPacket(com.alibaba.cobar.net.mysql.CommandPacket)

Aggregations

CommandPacket (com.alibaba.cobar.net.mysql.CommandPacket)10 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)6 ErrorPacketException (com.alibaba.cobar.exception.ErrorPacketException)5 UnknownPacketException (com.alibaba.cobar.exception.UnknownPacketException)5 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)4 UnknownCharsetException (com.alibaba.cobar.exception.UnknownCharsetException)1 UnknownTxIsolationException (com.alibaba.cobar.exception.UnknownTxIsolationException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1