use of com.actiontech.dble.net.mysql.FieldPacket in project dble by actiontech.
the class SelectVariables method execute.
public static void execute(ServerConnection c, String sql) {
String subSql = sql.substring(sql.indexOf("SELECT") + 6);
List<String> splitVar = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(subSql);
splitVar = convert(splitVar);
int fieldCount = splitVar.size();
ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
FieldPacket[] fields = new FieldPacket[fieldCount];
int i = 0;
byte packetId = 0;
header.setPacketId(++packetId);
for (String s : splitVar) {
fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING);
fields[i++].setPacketId(++packetId);
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
// write eof
buffer = eof.write(buffer, c, true);
// write rows
// byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(fieldCount);
for (String s : splitVar) {
String value = VARIABLES.get(s) == null ? "" : VARIABLES.get(s);
row.add(value.getBytes());
}
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
// write lastEof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.FieldPacket in project dble by actiontech.
the class ShowBinlogStatus method writeResponse.
private static void writeResponse(ManagerConnection c) {
if (errMsg == null) {
ByteBuffer buffer = c.allocate();
buffer = HEADER.write(buffer, c, true);
for (FieldPacket field : FIELDS_PACKET) {
buffer = field.write(buffer, c, true);
}
buffer = EOF.write(buffer, c, true);
byte packetId = EOF.getPacketId();
for (RowDataPacket row : rows) {
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
rows.clear();
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
} else {
c.writeErrMessage(ErrorCode.ER_UNKNOWN_ERROR, errMsg);
errMsg = null;
}
}
use of com.actiontech.dble.net.mysql.FieldPacket in project dble by actiontech.
the class ShowCache method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
CacheService cacheService = DbleServer.getInstance().getCacheService();
for (Map.Entry<String, CachePool> entry : cacheService.getAllCachePools().entrySet()) {
String cacheName = entry.getKey();
CachePool cachePool = entry.getValue();
if (cachePool != null) {
if (cachePool instanceof LayerCachePool) {
for (Map.Entry<String, CacheStatic> staticsEntry : ((LayerCachePool) cachePool).getAllCacheStatic().entrySet()) {
RowDataPacket row = getRow(cacheName + '.' + staticsEntry.getKey(), staticsEntry.getValue(), c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
} else {
RowDataPacket row = getRow(cacheName, cachePool.getCacheStatic(), c.getCharset().getResults());
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.FieldPacket in project dble by actiontech.
the class ShowCommand method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
for (NIOProcessor p : DbleServer.getInstance().getFrontProcessors()) {
RowDataPacket row = getRow(p);
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.FieldPacket in project dble by actiontech.
the class ShowConnectionCount method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
// write header
buffer = HEADER.write(buffer, c, true);
// write fields
for (FieldPacket field : FIELDS) {
buffer = field.write(buffer, c, true);
}
// write eof
buffer = EOF.write(buffer, c, true);
// write rows
byte packetId = EOF.getPacketId();
RowDataPacket row = getRow();
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
Aggregations