use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowVersion 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.add(Versions.SERVER_VERSION);
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_plus by coderczp.
the class MyRowOutPutDataHandler method onRowData.
@Override
public boolean onRowData(String dataNode, byte[] rowData) {
RowDataPacket rowDataPkg = ResultSetUtil.parseRowData(rowData, bfields);
// 获取Id字段,
String id = ByteUtil.getString(rowDataPkg.fieldValues.get(0));
byte[] bname = rowDataPkg.fieldValues.get(1);
// 查找ID对应的A表的记录
byte[] arow = arows.remove(id);
rowDataPkg = ResultSetUtil.parseRowData(arow, afields);
// 设置b.name 字段
rowDataPkg.add(bname);
ctx.writeRow(rowDataPkg);
// EngineCtx.LOGGER.info("out put row ");
return false;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ShowVariables method getRow.
private static RowDataPacket getRow(String name, String value, String charset) {
RowDataPacket row = new RowDataPacket(FIELD_COUNT);
row.add(StringUtil.encode(name, charset));
row.add(StringUtil.encode(value, charset));
return row;
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class MultiNodeQueryHandler method outputMergeResult.
public void outputMergeResult(final ServerConnection source, final byte[] eof, List<RowDataPacket> results) {
try {
lock.lock();
ByteBuffer buffer = session.getSource().allocate();
final RouteResultset rrs = this.dataMergeSvr.getRrs();
// 处理limit语句
int start = rrs.getLimitStart();
int end = start + rrs.getLimitSize();
if (start < 0) {
start = 0;
}
if (rrs.getLimitSize() < 0) {
end = results.size();
}
// }
if (end > results.size()) {
end = results.size();
}
if (prepared) {
for (int i = start; i < end; i++) {
RowDataPacket row = results.get(i);
BinaryRowDataPacket binRowDataPk = new BinaryRowDataPacket();
binRowDataPk.read(fieldPackets, row);
binRowDataPk.packetId = ++packetId;
// binRowDataPk.write(source);
buffer = binRowDataPk.write(buffer, session.getSource(), true);
}
} else {
for (int i = start; i < end; i++) {
RowDataPacket row = results.get(i);
row.packetId = ++packetId;
buffer = row.write(buffer, source, true);
}
}
eof[3] = ++packetId;
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("last packet id:" + packetId);
}
source.write(source.writeToBuffer(eof, buffer));
} catch (Exception e) {
handleDataProcessException(e);
} finally {
lock.unlock();
dataMergeSvr.clear();
}
}
use of io.mycat.net.mysql.RowDataPacket in project Mycat_plus by coderczp.
the class ResultSetUtil method getColumnValAsString.
public static String getColumnValAsString(byte[] row, List<byte[]> fieldValues, int columnIndex) {
RowDataPacket rowDataPkg = new RowDataPacket(fieldValues.size());
rowDataPkg.read(row);
byte[] columnData = rowDataPkg.fieldValues.get(columnIndex);
// columnData 为空时,直接返回null
return columnData == null ? null : new String(columnData);
}
Aggregations