本文整理汇总了Java中com.alibaba.cobar.server.ServerConnection.writeErrMessage方法的典型用法代码示例。如果您正苦于以下问题:Java ServerConnection.writeErrMessage方法的具体用法?Java ServerConnection.writeErrMessage怎么用?Java ServerConnection.writeErrMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.cobar.server.ServerConnection
的用法示例。
在下文中一共展示了ServerConnection.writeErrMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCharset
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private static void setCharset(String charset, ServerConnection c) {
if ("null".equalsIgnoreCase(charset)) {
/* 忽略字符集为null的属性设置 */
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else if (c.setCharset(charset)) {
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else {
try {
if (c.setCharsetIndex(Integer.parseInt(charset))) {
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset :" + charset);
}
} catch (RuntimeException e) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset :" + charset);
}
}
}
示例2: getRouteResultset
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private static RouteResultset getRouteResultset(ServerConnection c, String stmt) {
String db = c.getSchema();
if (db == null) {
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return null;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return null;
}
try {
return ServerRouter.route(schema, stmt, c.getCharset(), c);
} catch (SQLNonTransientException e) {
StringBuilder s = new StringBuilder();
logger.warn(s.append(c).append(stmt).toString(), e);
String msg = e.getMessage();
c.writeErrMessage(ErrorCode.ER_PARSE_ERROR, msg == null ? e.getClass().getSimpleName() : msg);
return null;
}
}
示例3: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String sql, ServerConnection c) {
DMLLoadStatement loadStmt = null;
try {
SQLStatement stmt = SQLParserDelegate.parse(sql);
if (!(stmt instanceof DMLLoadStatement)) {
throw new TddlRuntimeException(ErrorCode.ERR_PARSER, "not a load statement");
}
loadStmt = (DMLLoadStatement) stmt;
} catch (Exception e) {
c.writeErrMessage(ErrorCode.ERR_PARSER.getCode(), e.getMessage());
}
try {
String fileName = loadStmt.getFileName().getUnescapedString();
BinaryPacket packet = new BinaryPacket();
byte[] fileNameBytes = StringUtil.encode(fileName, c.getCharset());
byte[] data = new byte[1 + fileNameBytes.length];
data[0] = BinaryPacket.LOCAL_INFILE;
System.arraycopy(fileNameBytes, 0, data, 1, fileNameBytes.length);
packet.data = data;
packet.packetId = c.getNewPacketId();
c.setLoadFile(true);
c.setLoadDataSql(sql);
c.write(packet.write(c.allocate(), c));
logger.info("start load data, sql is :" + sql);
} catch (Exception ex) {
logger.error("error in handle load file", ex);
c.writeErrMessage(ErrorCode.ERR_EXECUTOR.getCode(), ex.getMessage());
}
}
示例4: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String stmt, ServerConnection c, int offset) {
switch (ServerParseStart.parse(stmt, offset)) {
case ServerParseStart.TRANSACTION:
c.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unsupported statement");
break;
default:
c.execute(stmt, ServerParse.START);
}
}
示例5: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String stmt, ServerConnection c, int offset) {
switch (ServerParseStart.parse(stmt, offset)) {
case ServerParseStart.TRANSACTION:
c.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unsupported statement");
break;
default:
c.execute(stmt, ServerParse.START);
}
}
示例6: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String stmt, int offset, final ServerConnection c) {
String id = stmt.substring(offset).trim();
if (StringUtil.isEmpty(id)) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "NULL connection id");
} else {
// get value
long value = 0;
try {
value = Long.parseLong(id);
} catch (NumberFormatException e) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Invalid connection id:" + id);
return;
}
// kill query itself
if (value == c.getId()) {
c.cancel(null);
return;
}
// get the connection and kill query
FrontendConnection fc = null;
NIOProcessor[] processors = CobarServer.getInstance().getProcessors();
for (NIOProcessor p : processors) {
if ((fc = p.getFrontends().get(value)) != null) {
break;
}
}
if (fc != null) {
if (fc instanceof ServerConnection) {
((ServerConnection) fc).cancel(c);
} else {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unknown command");
}
} else {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
}
}
}
示例7: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String stmt, int offset, ServerConnection c) {
String id = stmt.substring(offset).trim();
if (StringUtil.isEmpty(id)) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "NULL connection id");
} else {
// get value
long value = 0;
try {
value = Long.parseLong(id);
} catch (NumberFormatException e) {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Invalid connection id:" + id);
return;
}
// kill myself
if (value == c.getId()) {
getOkPacket().write(c);
c.write(c.allocate());
return;
}
// get connection and close it
FrontendConnection fc = null;
NIOProcessor[] processors = CobarServer.getInstance().getProcessors();
for (NIOProcessor p : processors) {
if ((fc = p.getFrontends().get(value)) != null) {
break;
}
}
if (fc != null) {
fc.close();
getOkPacket().write(c);
} else {
c.writeErrMessage(ErrorCode.ER_NO_SUCH_THREAD, "Unknown connection id:" + id);
}
}
}
示例8: handleException
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private void handleException(Channel mc, BlockingSession session, Exception e) {
isFail.set(true);
if (decrementCountBy(1)) {
try {
session.clear();
ServerConnection sc = session.getSource();
getLogger().warn(new StringBuilder().append(sc).append(mc).append(getErrorMessage()).toString(), e);
String msg = e.getMessage();
sc.writeErrMessage(ErrorCode.ER_YES, msg == null ? e.getClass().getSimpleName() : msg);
} catch (Exception e2) {
getLogger().warn("exception happens in failure notification: " + session.getSource(), e2);
}
}
}
示例9: handleException
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private void handleException(Channel mc, BlockingSession session, Exception e) {
isFail.set(true);
if (decrementCountBy(1)) {
try {
session.clear();
ServerConnection source = session.getSource();
LOGGER.warn(new StringBuilder().append(source).append(mc).append("rollback").toString(), e);
String msg = e.getMessage();
source.writeErrMessage(ErrorCode.ER_YES, msg == null ? e.getClass().getSimpleName() : msg);
} catch (Exception e2) {
LOGGER.warn("exception happens in failure notification: " + session.getSource(), e2);
}
}
}
示例10: multiSetResponse
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private static void multiSetResponse(String stmt, ServerConnection c, int rs) {
String charResult = "null";
String charConnection = "null";
String[] sqlList = StringUtil.split(stmt, ',', false);
// check first
switch (rs & 0xff) {
case CHARACTER_SET_RESULTS:
charResult = sqlList[0].substring(rs >>> 8).trim();
break;
case CHARACTER_SET_CONNECTION:
charConnection = sqlList[0].substring(rs >>> 8).trim();
break;
}
// check remaining
for (int i = 1; i < sqlList.length; i++) {
String sql = new StringBuilder("set ").append(sqlList[i]).toString();
if ((i + 1 == sqlList.length) && sql.endsWith(";")) {
/* 去掉末尾的 ‘;’ */
sql = sql.substring(0, sql.length() - 1);
}
int rs2 = ServerParseSet.parse(sql, "set".length());
switch (rs2 & 0xff) {
case CHARACTER_SET_RESULTS:
charResult = sql.substring(rs2 >>> 8).trim();
break;
case CHARACTER_SET_CONNECTION:
charConnection = sql.substring(rs2 >>> 8).trim();
break;
case CHARACTER_SET_CLIENT:
break;
default:
StringBuilder s = new StringBuilder();
logger.warn(s.append(sql).append(" is not executed").toString());
}
}
if (charResult.startsWith("'") || charResult.startsWith("`")) {
charResult = charResult.substring(1, charResult.length() - 1);
}
if (charConnection.startsWith("'") || charConnection.startsWith("`")) {
charConnection = charConnection.substring(1, charConnection.length() - 1);
}
// 如果其中一个为null,则以另一个为准。
if ("null".equalsIgnoreCase(charResult)) {
setCharset(charConnection, c);
return;
}
if ("null".equalsIgnoreCase(charConnection)) {
setCharset(charResult, c);
return;
}
if (charConnection.equalsIgnoreCase(charResult)) {
setCharset(charConnection, c);
} else {
StringBuilder sb = new StringBuilder();
sb.append("charset is not consistent:[connection=").append(charConnection);
sb.append(",results=").append(charResult).append(']');
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, sb.toString());
}
}
示例11: execute
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void execute(ServerConnection c) {
// 取得SCHEMA
String db = c.getSchema();
if (db == null) {
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return;
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
SQLRecord[] records = schema.getDataSource().getRecorder().getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
示例12: execute
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void execute(ServerConnection c) {
// 取得SCHEMA
String db = c.getSchema();
if (db == null) {
c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
return;
}
SchemaConfig schema = CobarServer.getInstance().getConfig().getSchemas().get(db);
if (schema == null) {
c.writeErrMessage(ErrorCode.ER_BAD_DB_ERROR, "Unknown database '" + db + "'");
return;
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
// write eof
buffer = eof.write(buffer, c);
// write rows
byte packetId = eof.packetId;
SQLRecord[] records = schema.getRecorder().getRecords();
for (int i = records.length - 1; i >= 0; i--) {
if (records[i] != null) {
RowDataPacket row = getRow(records[i], c.getCharset());
row.packetId = ++packetId;
buffer = row.write(buffer, c);
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// write buffer
c.write(buffer);
}
示例13: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String stmt, ServerConnection c) {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_COM_ERROR, "Unsupported statement");
}
示例14: handle
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
public static void handle(String stmt, ServerConnection c, int offset) {
int rs = ServerParseSet.parse(stmt, offset);
switch (rs & 0xff) {
case AUTOCOMMIT_ON:
if (!c.isAutocommit()) {
c.setAutocommit(true);
}
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
break;
case AUTOCOMMIT_OFF: {
if (c.isAutocommit()) {
c.setAutocommit(false);
}
c.write(c.writeToBuffer(AC_OFF, c.allocate()));
break;
}
case TX_READ_UNCOMMITTED: {
c.setTxIsolation(Isolations.READ_UNCOMMITTED.getCode());
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
break;
}
case TX_READ_COMMITTED: {
c.setTxIsolation(Isolations.READ_COMMITTED.getCode());
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
break;
}
case TX_REPEATED_READ: {
c.setTxIsolation(Isolations.REPEATED_READ.getCode());
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
break;
}
case TX_SERIALIZABLE: {
c.setTxIsolation(Isolations.SERIALIZABLE.getCode());
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
break;
}
case NAMES:
String charset = stmt.substring(rs >>> 8).trim();
if (c.setCharset(charset)) {
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
} else {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, "Unknown charset '" + charset + "'");
}
break;
case CHARACTER_SET_CLIENT:
case CHARACTER_SET_CONNECTION:
case CHARACTER_SET_RESULTS:
CharacterSet.response(stmt, c, rs);
break;
case SQL_MODE:
SqlMode.response(stmt, c, rs);
break;
case TX_POLICY_1:
c.setTrxPolicy(ITransactionPolicy.TDDL);
break;
// case TX_POLICY_2:
// c.setTrxPolicy(new Cobar());
// c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
// break;
case TX_POLICY_3:
c.setTrxPolicy(ITransactionPolicy.ALLOW_READ_CROSS_DB);
break;
// case TX_POLICY_4:
// c.setTrxPolicy(new Corona());
// c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
// break;
case TX_POLICY_5:
c.setTrxPolicy(ITransactionPolicy.FREE);
break;
case AT_VAR:
c.execute(stmt, ServerParse.SET);
default:
StringBuilder s = new StringBuilder();
logger.warn(s.append(stmt).append(" is not executed").toString());
c.write(c.writeToBuffer(OkPacket.OK, c.allocate()));
}
}
示例15: multiSetResponse
import com.alibaba.cobar.server.ServerConnection; //导入方法依赖的package包/类
private static void multiSetResponse(String stmt, ServerConnection c, int rs) {
String charResult = "null";
String charConnection = "null";
String[] sqlList = SplitUtil.split(stmt, ',', false);
// check first
switch (rs & 0xff) {
case CHARACTER_SET_RESULTS:
charResult = sqlList[0].substring(rs >>> 8).trim();
break;
case CHARACTER_SET_CONNECTION:
charConnection = sqlList[0].substring(rs >>> 8).trim();
break;
}
// check remaining
for (int i = 1; i < sqlList.length; i++) {
String sql = new StringBuilder("set ").append(sqlList[i]).toString();
if ((i + 1 == sqlList.length) && sql.endsWith(";")) {
/* 去掉末尾的 ‘;’ */
sql = sql.substring(0, sql.length() - 1);
}
int rs2 = ServerParseSet.parse(sql, "set".length());
switch (rs2 & 0xff) {
case CHARACTER_SET_RESULTS:
charResult = sql.substring(rs2 >>> 8).trim();
break;
case CHARACTER_SET_CONNECTION:
charConnection = sql.substring(rs2 >>> 8).trim();
break;
case CHARACTER_SET_CLIENT:
break;
default:
StringBuilder s = new StringBuilder();
logger.warn(s.append(c).append(sql).append(" is not executed").toString());
}
}
if (charResult.startsWith("'") || charResult.startsWith("`")) {
charResult = charResult.substring(1, charResult.length() - 1);
}
if (charConnection.startsWith("'") || charConnection.startsWith("`")) {
charConnection = charConnection.substring(1, charConnection.length() - 1);
}
// 如果其中一个为null,则以另一个为准。
if ("null".equalsIgnoreCase(charResult)) {
setCharset(charConnection, c);
return;
}
if ("null".equalsIgnoreCase(charConnection)) {
setCharset(charResult, c);
return;
}
if (charConnection.equalsIgnoreCase(charResult)) {
setCharset(charConnection, c);
} else {
StringBuilder sb = new StringBuilder();
sb.append("charset is not consistent:[connection=").append(charConnection);
sb.append(",results=").append(charResult).append(']');
c.writeErrMessage(ErrorCode.ER_UNKNOWN_CHARACTER_SET, sb.toString());
}
}