Search in sources :

Example 1 with ErrorPacketException

use of com.alibaba.cobar.exception.ErrorPacketException in project cobar by alibaba.

the class MySQLChannel method sendSqlMode.

/**
 * 发送SQL_MODE设置
 */
private void sendSqlMode() throws IOException {
    CommandPacket cmd = getSqlModeCommand();
    cmd.write(out);
    out.flush();
    BinaryPacket bin = receive();
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            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 2 with ErrorPacketException

use of com.alibaba.cobar.exception.ErrorPacketException in project cobar by alibaba.

the class MySQLChannel method sendTxIsolation.

/**
 * 发送事务级别设置
 */
private void sendTxIsolation(int txIsolation) throws IOException {
    CommandPacket cmd = getTxIsolationCommand(txIsolation);
    cmd.write(out);
    out.flush();
    BinaryPacket bin = receive();
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            this.txIsolation = txIsolation;
            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 3 with ErrorPacketException

use of com.alibaba.cobar.exception.ErrorPacketException in project cobar by alibaba.

the class MySQLChannel method handshake.

private MySQLChannel handshake() throws IOException {
    // 读取握手数据包
    BinaryPacket initPacket = new BinaryPacket();
    initPacket.read(in);
    HandshakePacket hsp = new HandshakePacket();
    hsp.read(initPacket);
    // 设置通道参数
    this.threadId = hsp.threadId;
    int ci = hsp.serverCharsetIndex & 0xff;
    if ((dbCharset = CharsetUtil.getDbCharset(ci)) != null) {
        this.charsetIndex = ci;
        this.charset = CharsetUtil.getCharset(ci);
    } else {
        throw new UnknownCharsetException("charset:" + ci);
    }
    // 发送认证数据包
    BinaryPacket bin = null;
    try {
        bin = sendAuth411(hsp);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            afterSuccess();
            break;
        case ErrorPacket.FIELD_COUNT:
            ErrorPacket err = new ErrorPacket();
            err.read(bin);
            throw new ErrorPacketException(new String(err.message, charset));
        case EOFPacket.FIELD_COUNT:
            auth323(bin.packetId, hsp.seed);
            break;
        default:
            throw new UnknownPacketException(bin.toString());
    }
    return this;
}
Also used : HandshakePacket(com.alibaba.cobar.net.mysql.HandshakePacket) ErrorPacket(com.alibaba.cobar.net.mysql.ErrorPacket) ErrorPacketException(com.alibaba.cobar.exception.ErrorPacketException) UnknownPacketException(com.alibaba.cobar.exception.UnknownPacketException) UnknownCharsetException(com.alibaba.cobar.exception.UnknownCharsetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BinaryPacket(com.alibaba.cobar.net.mysql.BinaryPacket)

Example 4 with ErrorPacketException

use of com.alibaba.cobar.exception.ErrorPacketException in project cobar by alibaba.

the class MySQLChannel method auth323.

/**
 * 323协议认证
 */
private void auth323(byte packetId, byte[] seed) throws IOException {
    Reply323Packet r323 = new Reply323Packet();
    r323.packetId = ++packetId;
    String passwd = dsc.getPassword();
    if (passwd != null && passwd.length() > 0) {
        r323.seed = SecurityUtil.scramble323(passwd, new String(seed)).getBytes();
    }
    r323.write(out);
    out.flush();
    BinaryPacket bin = receive();
    switch(bin.data[0]) {
        case OkPacket.FIELD_COUNT:
            afterSuccess();
            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) Reply323Packet(com.alibaba.cobar.net.mysql.Reply323Packet) BinaryPacket(com.alibaba.cobar.net.mysql.BinaryPacket)

Example 5 with ErrorPacketException

use of com.alibaba.cobar.exception.ErrorPacketException 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)

Aggregations

ErrorPacketException (com.alibaba.cobar.exception.ErrorPacketException)6 UnknownPacketException (com.alibaba.cobar.exception.UnknownPacketException)6 BinaryPacket (com.alibaba.cobar.net.mysql.BinaryPacket)6 ErrorPacket (com.alibaba.cobar.net.mysql.ErrorPacket)6 CommandPacket (com.alibaba.cobar.net.mysql.CommandPacket)4 UnknownCharsetException (com.alibaba.cobar.exception.UnknownCharsetException)1 HandshakePacket (com.alibaba.cobar.net.mysql.HandshakePacket)1 Reply323Packet (com.alibaba.cobar.net.mysql.Reply323Packet)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1