本文整理汇总了Java中com.alibaba.cobar.server.ServerConnection.getSchema方法的典型用法代码示例。如果您正苦于以下问题:Java ServerConnection.getSchema方法的具体用法?Java ServerConnection.getSchema怎么用?Java ServerConnection.getSchema使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.cobar.server.ServerConnection
的用法示例。
在下文中一共展示了ServerConnection.getSchema方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
}
示例2: 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);
}
示例3: 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);
}