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());
}
}
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());
}
}
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;
}
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());
}
}
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());
}
}
Aggregations