Search in sources :

Example 41 with RowDataPacket

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);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 42 with RowDataPacket

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;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 43 with RowDataPacket

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;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 44 with RowDataPacket

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();
    }
}
Also used : BinaryRowDataPacket(io.mycat.net.mysql.BinaryRowDataPacket) RowDataPacket(io.mycat.net.mysql.RowDataPacket) BinaryRowDataPacket(io.mycat.net.mysql.BinaryRowDataPacket) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) RouteResultset(io.mycat.route.RouteResultset)

Example 45 with RowDataPacket

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);
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Aggregations

RowDataPacket (io.mycat.net.mysql.RowDataPacket)269 FieldPacket (io.mycat.net.mysql.FieldPacket)143 ByteBuffer (java.nio.ByteBuffer)140 EOFPacket (io.mycat.net.mysql.EOFPacket)137 MycatConfig (io.mycat.config.MycatConfig)20 LinkedList (java.util.LinkedList)16 PhysicalDatasource (io.mycat.backend.datasource.PhysicalDatasource)14 NIOProcessor (io.mycat.net.NIOProcessor)14 SchemaConfig (io.mycat.config.model.SchemaConfig)13 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)13 PhysicalDBPool (io.mycat.backend.datasource.PhysicalDBPool)12 UserStat (io.mycat.statistic.stat.UserStat)12 IOException (java.io.IOException)12 Map (java.util.Map)12 DBHeartbeat (io.mycat.backend.heartbeat.DBHeartbeat)10 ServerConnection (io.mycat.server.ServerConnection)10 BinaryRowDataPacket (io.mycat.net.mysql.BinaryRowDataPacket)8 File (java.io.File)8 DataSourceSyncRecorder (io.mycat.statistic.DataSourceSyncRecorder)6 BufferedReader (java.io.BufferedReader)6