Search in sources :

Example 1 with ResultSetHeaderPacket

use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.

the class PacketUtil method getHeader.

public static ResultSetHeaderPacket getHeader(int fieldCount) {
    ResultSetHeaderPacket packet = new ResultSetHeaderPacket();
    packet.setPacketId(1);
    packet.setFieldCount(fieldCount);
    return packet;
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket)

Example 2 with ResultSetHeaderPacket

use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.

the class ExplainHandler method handle.

public static void handle(String stmt, ServerConnection c, int offset) {
    stmt = stmt.substring(offset).trim();
    RouteResultset rrs = getRouteResultset(c, stmt);
    if (rrs == null) {
        return;
    }
    ByteBuffer buffer = c.allocate();
    // write header
    ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT);
    byte packetId = header.getPacketId();
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : FIELDS) {
        field.setPacketId(++packetId);
        buffer = field.write(buffer, c, true);
    }
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    buffer = eof.write(buffer, c, true);
    if (!rrs.isNeedOptimizer()) {
        // write rows
        for (RouteResultsetNode node : rrs.getNodes()) {
            RowDataPacket row = getRow(node, c.getCharset().getResults());
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
    } else {
        List<String[]> results = getComplexQueryResult(rrs, c);
        for (String[] result : results) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(result[0], c.getCharset().getResults()));
            row.add(StringUtil.encode(result[1], c.getCharset().getResults()));
            row.add(StringUtil.encode(result[2].replaceAll("[\\t\\n\\r]", " "), 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);
    // post write
    c.write(buffer);
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) RouteResultsetNode(com.actiontech.dble.route.RouteResultsetNode) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) RouteResultset(com.actiontech.dble.route.RouteResultset)

Example 3 with ResultSetHeaderPacket

use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.

the class MysqlInformationSchemaHandler method doWrite.

/**
 * @param fieldCount
 * @param fields
 * @param c
 */
public static void doWrite(int fieldCount, FieldPacket[] fields, ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
    byte packetId = header.getPacketId();
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        field.setPacketId(++packetId);
        buffer = field.write(buffer, c, true);
    }
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    buffer = eof.write(buffer, c, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    // post write
    c.write(buffer);
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 4 with ResultSetHeaderPacket

use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.

the class ShowTables method writeFullTablesHeader.

public static PackageBufINf writeFullTablesHeader(ByteBuffer buffer, ServerConnection c, String cSchema, List<FieldPacket> fieldPackets) {
    int fieldCount = 2;
    ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
    FieldPacket[] fields = new FieldPacket[fieldCount];
    int i = 0;
    byte packetId = 0;
    header.setPacketId(++packetId);
    fields[i] = PacketUtil.getField("Tables in " + cSchema, Fields.FIELD_TYPE_VAR_STRING);
    fields[i].setPacketId(++packetId);
    fieldPackets.add(fields[i]);
    fields[i + 1] = PacketUtil.getField("Table_type  ", Fields.FIELD_TYPE_VAR_STRING);
    fields[i + 1].setPacketId(++packetId);
    fieldPackets.add(fields[i + 1]);
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    eof.write(buffer, c, true);
    PackageBufINf packBuffInfo = new PackageBufINf();
    packBuffInfo.setBuffer(buffer);
    packBuffInfo.setPacketId(packetId);
    return packBuffInfo;
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) PackageBufINf(com.actiontech.dble.manager.handler.PackageBufINf) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 5 with ResultSetHeaderPacket

use of com.actiontech.dble.net.mysql.ResultSetHeaderPacket in project dble by actiontech.

the class ShowTables method writeTablesHeaderAndRows.

public static PackageBufINf writeTablesHeaderAndRows(ByteBuffer buffer, ServerConnection c, Map<String, String> tableMap, String cSchema) {
    int fieldCount = 1;
    ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
    FieldPacket[] fields = new FieldPacket[fieldCount];
    int i = 0;
    byte packetId = 0;
    header.setPacketId(++packetId);
    fields[i] = PacketUtil.getField("Tables in " + cSchema, Fields.FIELD_TYPE_VAR_STRING);
    fields[i].setPacketId(++packetId);
    EOFPacket eof = new EOFPacket();
    eof.setPacketId(++packetId);
    // write header
    buffer = header.write(buffer, c, true);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c, true);
    }
    // write eof
    eof.write(buffer, c, true);
    for (String name : tableMap.keySet()) {
        RowDataPacket row = new RowDataPacket(fieldCount);
        row.add(StringUtil.encode(name.toLowerCase(), c.getCharset().getResults()));
        row.setPacketId(++packetId);
        buffer = row.write(buffer, c, true);
    }
    PackageBufINf packBuffInfo = new PackageBufINf();
    packBuffInfo.setBuffer(buffer);
    packBuffInfo.setPacketId(packetId);
    return packBuffInfo;
}
Also used : ResultSetHeaderPacket(com.actiontech.dble.net.mysql.ResultSetHeaderPacket) PackageBufINf(com.actiontech.dble.manager.handler.PackageBufINf) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)7 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)6 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)6 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)4 ByteBuffer (java.nio.ByteBuffer)4 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)2 RouteResultset (com.actiontech.dble.route.RouteResultset)1 RouteResultsetNode (com.actiontech.dble.route.RouteResultsetNode)1