Search in sources :

Example 26 with EOFPacket

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

the class ShowTime method execute.

public static void execute(ManagerConnection c, int type) {
    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.getPacketId();
    RowDataPacket row = getRow(type, 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 : 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)

Example 27 with EOFPacket

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

the class ShowWhiteHost 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.getPacketId();
    Map<String, List<UserConfig>> map = DbleServer.getInstance().getConfig().getFirewall().getWhitehost();
    for (Map.Entry<String, List<UserConfig>> entry : map.entrySet()) {
        List<UserConfig> userConfigs = entry.getValue();
        StringBuilder users = new StringBuilder();
        for (int i = 0; i < userConfigs.size(); i++) {
            if (i > 0) {
                users.append(",");
            }
            users.append(userConfigs.get(i).getName());
        }
        RowDataPacket row = getRow(entry.getKey(), users.toString(), 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);
    // write buffer
    c.write(buffer);
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) UserConfig(com.actiontech.dble.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) List(java.util.List) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket) Map(java.util.Map)

Example 28 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket 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 29 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket 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 30 with EOFPacket

use of com.actiontech.dble.net.mysql.EOFPacket 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)

Aggregations

EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)66 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)65 ByteBuffer (java.nio.ByteBuffer)63 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)59 Map (java.util.Map)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)6 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)6 UserStat (com.actiontech.dble.statistic.stat.UserStat)6 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 ServerConfig (com.actiontech.dble.config.ServerConfig)3 FrontendConnection (com.actiontech.dble.net.FrontendConnection)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)2 TableConfig (com.actiontech.dble.config.model.TableConfig)2 UserConfig (com.actiontech.dble.config.model.UserConfig)2 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)2 TreeSet (java.util.TreeSet)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 Matcher (java.util.regex.Matcher)2 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)1