use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShareRowOutPutDataHandler method onRowData.
@Override
public boolean onRowData(String dataNode, byte[] rowData) {
RowDataPacket rowDataPkgold = ResultSetUtil.parseRowData(rowData, bfields);
// 拷贝一份batchRows
Map<String, byte[]> batchRowsCopy = new ConcurrentHashMap<String, byte[]>();
batchRowsCopy.putAll(arows);
// 获取Id字段,
String id = ByteUtil.getString(rowDataPkgold.fieldValues.get(joinR));
// 查找ID对应的A表的记录
// arows.remove(id);
byte[] arow = getRow(batchRowsCopy, id, joinL);
// byte[] arow = getRow(id,joinL);//arows.remove(id);
while (arow != null) {
// ctx.getAllFields());
RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(arow, afields);
for (int i = 1; i < rowDataPkgold.fieldCount; i++) {
// 设置b.name 字段
byte[] bname = rowDataPkgold.fieldValues.get(i);
rowDataPkg.add(bname);
rowDataPkg.addFieldCount(1);
}
// RowData(rowDataPkg);
// huangyiming add
MiddlerResultHandler middlerResultHandler = session.getMiddlerResultHandler();
if (null == middlerResultHandler) {
ctx.writeRow(rowDataPkg);
} else {
if (middlerResultHandler instanceof MiddlerQueryResultHandler) {
// if(middlerResultHandler.getDataType().equalsIgnoreCase("string")){
byte[] columnData = rowDataPkg.fieldValues.get(0);
if (columnData != null && columnData.length > 0) {
String rowValue = new String(columnData);
middlerResultHandler.add(rowValue);
}
// }
}
}
arow = getRow(batchRowsCopy, id, joinL);
// arow = getRow(id,joinL);
}
return false;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class SelectSessionTxReadOnly 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.packetId;
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.packetId = ++packetId;
row.add(LongUtil.toBytes(0));
buffer = row.write(buffer, c, true);
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// post write
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowBackend method execute.
public static void execute(ManagerConnection c) {
ByteBuffer buffer = c.allocate();
buffer = header.write(buffer, c, true);
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
buffer = eof.write(buffer, c, true);
byte packetId = eof.packetId;
String charset = c.getCharset();
for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
for (BackendConnection bc : p.getBackends().values()) {
if (bc != null) {
RowDataPacket row = getRow(bc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowConnection 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.packetId;
String charset = c.getCharset();
NIOProcessor[] processors = MycatServer.getInstance().getProcessors();
for (NIOProcessor p : processors) {
for (FrontendConnection fc : p.getFrontends().values()) {
if (fc != null) {
RowDataPacket row = getRow(fc, charset);
row.packetId = ++packetId;
buffer = row.write(buffer, c, true);
}
}
}
// write last eof
EOFPacket lastEof = new EOFPacket();
lastEof.packetId = ++packetId;
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.
the class ShowDataNode method getRow.
private static RowDataPacket getRow(PhysicalDBNode node, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(node.getName(), charset));
row.add(StringUtil.encode(node.getDbPool().getHostName() + '/' + node.getDatabase(), charset));
PhysicalDBPool pool = node.getDbPool();
PhysicalDatasource ds = pool.getSource();
if (ds != null) {
int active = ds.getActiveCountForSchema(node.getDatabase());
int idle = ds.getIdleCountForSchema(node.getDatabase());
row.add(IntegerUtil.toBytes(pool.getActivedIndex()));
row.add(StringUtil.encode(ds.getConfig().getDbType(), charset));
row.add(IntegerUtil.toBytes(active));
row.add(IntegerUtil.toBytes(idle));
row.add(IntegerUtil.toBytes(ds.getSize()));
} else {
row.add(null);
row.add(null);
row.add(null);
row.add(null);
row.add(null);
}
row.add(LongUtil.toBytes(ds.getExecuteCountForSchema(node.getDatabase())));
row.add(StringUtil.encode(nf.format(0), charset));
row.add(StringUtil.encode(nf.format(0), charset));
row.add(LongUtil.toBytes(0));
long recoveryTime = pool.getSource().getHeartbeatRecoveryTime() - TimeUtil.currentTimeMillis();
row.add(LongUtil.toBytes(recoveryTime > 0 ? recoveryTime / 1000L : -1L));
return row;
}
Aggregations