use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowConnectionSQL method execute.
public static void execute(ManagerConnection c) {
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;
String charset = c.getCharset();
for (NIOProcessor p : CobarServer.getInstance().getProcessors()) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (!fc.isClosed()) {
RowDataPacket row = getRow(fc, charset);
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);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowConnectionSQL method getRow.
private static RowDataPacket getRow(FrontendConnection c, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(c.getId()));
row.add(StringUtil.encode(c.getHost(), charset));
row.add(StringUtil.encode(c.getSchema(), charset));
row.add(LongUtil.toBytes(c.getLastReadTime()));
long rt = c.getLastReadTime();
long wt = c.getLastWriteTime();
row.add(LongUtil.toBytes((wt > rt) ? (wt - rt) : (TimeUtil.currentTimeMillis() - rt)));
row.add(null);
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class ShowDataSource method getRow.
private static RowDataPacket getRow(DataSourceConfig dsc, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(dsc.getName(), charset));
row.add(StringUtil.encode(dsc.getType(), charset));
row.add(StringUtil.encode(dsc.getHost(), charset));
row.add(IntegerUtil.toBytes(dsc.getPort()));
row.add(StringUtil.encode(dsc.getDatabase(), charset));
return row;
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class SelectDatabase method response.
public static void response(ServerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c);
}
buffer = eof.write(buffer, c);
byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(c.getSchema(), c.getCharset()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
c.write(buffer);
}
use of com.alibaba.cobar.net.mysql.RowDataPacket in project cobar by alibaba.
the class SelectIdentity method response.
public static void response(ServerConnection c, String stmt, int aliasIndex, final String orgName) {
String alias = ParseUtil.parseAlias(stmt, aliasIndex);
if (alias == null) {
alias = orgName;
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c);
// write fields
byte packetId = header.packetId;
FieldPacket field = PacketUtil.getField(alias, orgName, Fields.FIELD_TYPE_LONGLONG);
field.packetId = ++packetId;
buffer = field.write(buffer, c);
// write eof
EOFPacket eof = new EOFPacket();
eof.packetId = ++packetId;
buffer = eof.write(buffer, c);
// write rows
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(LongUtil.toBytes(c.getLastInsertId()));
row.packetId = ++packetId;
buffer = row.write(buffer, c);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c);
// post write
c.write(buffer);
}
Aggregations