Search in sources :

Example 86 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.

the class ShowRouter 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;
    for (NIOProcessor p : MycatServer.getInstance().getProcessors()) {
        RowDataPacket row = getRow(p, c.getCharset());
        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) NIOProcessor(io.mycat.net.NIOProcessor) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 87 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.

the class ShowRouter method getRow.

private static RowDataPacket getRow(NIOProcessor processor, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(processor.getName().getBytes());
    row.add(null);
    row.add(null);
    row.add(null);
    row.add(null);
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 88 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.

the class ShowSQLCondition 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 key = QueryConditionAnalyzer.getInstance().getKey();
    List<Map.Entry<Object, AtomicLong>> list = QueryConditionAnalyzer.getInstance().getValues();
    if (list != null) {
        int size = list.size();
        long total = 0L;
        for (int i = 0; i < size; i++) {
            Map.Entry<Object, AtomicLong> entry = list.get(i);
            Object value = entry.getKey();
            Long count = entry.getValue().get();
            total += count;
            RowDataPacket row = getRow(i, key, value.toString(), count, c.getCharset());
            row.packetId = ++packetId;
            buffer = row.write(buffer, c, true);
        }
        RowDataPacket vk_row = getRow(size + 1, key + ".valuekey", "size", size, c.getCharset());
        vk_row.packetId = ++packetId;
        buffer = vk_row.write(buffer, c, true);
        RowDataPacket vc_row = getRow(size + 2, key + ".valuecount", "total", total, c.getCharset());
        vc_row.packetId = ++packetId;
        buffer = vc_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) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) FieldPacket(io.mycat.net.mysql.FieldPacket) Map(java.util.Map)

Example 89 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.

the class ShowSQLCondition method getRow.

private static RowDataPacket getRow(int i, String key, String value, long count, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(i));
    row.add(StringUtil.encode(key, charset));
    row.add(StringUtil.encode(value, charset));
    row.add(LongUtil.toBytes(count));
    return row;
}
Also used : RowDataPacket(io.mycat.net.mysql.RowDataPacket)

Example 90 with RowDataPacket

use of io.mycat.net.mysql.RowDataPacket in project Mycat-Server by MyCATApache.

the class ShowSQLExecute method getRow.

private static RowDataPacket getRow(long id, String charset) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(id));
    row.add(LongUtil.toBytes(100L));
    row.add(StringUtil.encode(nf.format(898.9), charset));
    row.add(StringUtil.encode(nf.format(8.8), charset));
    row.add(StringUtil.encode(nf.format(1.0), charset));
    return row;
}
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