Search in sources :

Example 96 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class ShowCobarCluster method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c, true);
    // write field
    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 (RowDataPacket row : getRows(c)) {
        row.packetId = ++packetId;
        buffer = row.write(buffer, c, true);
    }
    // last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // post write
    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 97 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class ShowDatabases method response.

public static void response(ServerConnection 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;
    MycatConfig conf = MycatServer.getInstance().getConfig();
    Map<String, UserConfig> users = conf.getUsers();
    UserConfig user = users == null ? null : users.get(c.getUser());
    if (user != null) {
        TreeSet<String> schemaSet = new TreeSet<String>();
        Set<String> schemaList = user.getSchemas();
        if (schemaList == null || schemaList.size() == 0) {
            schemaSet.addAll(conf.getSchemas().keySet());
        } else {
            for (String schema : schemaList) {
                schemaSet.add(schema);
            }
        }
        for (String name : schemaSet) {
            RowDataPacket row = new RowDataPacket(FIELD_COUNT);
            row.add(StringUtil.encode(name, 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);
    // post write
    c.write(buffer);
}
Also used : TreeSet(java.util.TreeSet) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) MycatConfig(io.mycat.config.MycatConfig) UserConfig(io.mycat.config.model.UserConfig) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 98 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class ShowFullTables method response.

/**
 * response method.
 * @param c
 */
public static void response(ServerConnection c, String stmt, int type) {
    String showSchemal = SchemaUtil.parseShowTableSchema(stmt);
    String cSchema = showSchemal == null ? c.getSchema() : showSchemal;
    SchemaConfig schema = MycatServer.getInstance().getConfig().getSchemas().get(cSchema);
    if (schema != null) {
        // 不分库的schema,show tables从后端 mysql中查
        String node = schema.getDataNode();
        if (!Strings.isNullOrEmpty(node)) {
            c.execute(stmt, ServerParse.SHOW);
            return;
        }
    } else {
        c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
    }
    // 分库的schema,直接从SchemaConfig中获取所有表名
    Map<String, String> parm = buildFields(c, stmt);
    Set<String> tableSet = getTableSet(c, parm);
    int i = 0;
    byte packetId = 0;
    header.packetId = ++packetId;
    fields[i] = PacketUtil.getField("Tables in " + parm.get(SCHEMA_KEY), Fields.FIELD_TYPE_VAR_STRING);
    fields[i].packetId = ++packetId;
    fields[i + 1] = PacketUtil.getField("Table_type  ", Fields.FIELD_TYPE_VAR_STRING);
    fields[i + 1].packetId = ++packetId;
    eof.packetId = ++packetId;
    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
    packetId = eof.packetId;
    for (String name : tableSet) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(name.toLowerCase(), c.getCharset()));
        row.add(StringUtil.encode("BASE TABLE", 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);
    // post write
    c.write(buffer);
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 99 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class ShowMyCatStatus method response.

public static void response(ServerConnection c) {
    if (MycatServer.getInstance().isOnline()) {
        ByteBuffer buffer = c.allocate();
        buffer = header.write(buffer, c, true);
        for (FieldPacket field : fields) {
            buffer = field.write(buffer, c, true);
        }
        buffer = eof.write(buffer, c, true);
        buffer = status.write(buffer, c, true);
        buffer = lastEof.write(buffer, c, true);
        c.write(buffer);
    } else {
        error.write(c);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 100 with FieldPacket

use of io.mycat.net.mysql.FieldPacket in project Mycat_plus by coderczp.

the class ShowTables method response.

/**
 * response method.
 * @param c
 */
public static void response(ServerConnection c, String stmt, int type) {
    String showSchemal = SchemaUtil.parseShowTableSchema(stmt);
    String cSchema = showSchemal == null ? c.getSchema() : showSchemal;
    SchemaConfig schema = MycatServer.getInstance().getConfig().getSchemas().get(cSchema);
    if (schema != null) {
        // 不分库的schema,show tables从后端 mysql中查
        String node = schema.getDataNode();
        if (!Strings.isNullOrEmpty(node)) {
            c.execute(stmt, ServerParse.SHOW);
            return;
        }
    } else {
        c.writeErrMessage(ErrorCode.ER_NO_DB_ERROR, "No database selected");
        return;
    }
    // 分库的schema,直接从SchemaConfig中获取所有表名
    Map<String, String> parm = buildFields(c, stmt);
    java.util.Set<String> tableSet = getTableSet(c, parm);
    int i = 0;
    byte packetId = 0;
    header.packetId = ++packetId;
    fields[i] = PacketUtil.getField("Tables in " + parm.get(SCHEMA_KEY), Fields.FIELD_TYPE_VAR_STRING);
    fields[i++].packetId = ++packetId;
    eof.packetId = ++packetId;
    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
    packetId = eof.packetId;
    for (String name : tableSet) {
        RowDataPacket row = new RowDataPacket(FIELD_COUNT);
        row.add(StringUtil.encode(name.toLowerCase(), 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);
    // post write
    c.write(buffer);
}
Also used : SchemaConfig(io.mycat.config.model.SchemaConfig) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

FieldPacket (io.mycat.net.mysql.FieldPacket)173 ByteBuffer (java.nio.ByteBuffer)151 EOFPacket (io.mycat.net.mysql.EOFPacket)146 RowDataPacket (io.mycat.net.mysql.RowDataPacket)143 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)18 NIOProcessor (io.mycat.net.NIOProcessor)14 UserStat (io.mycat.statistic.stat.UserStat)12 Map (java.util.Map)12 SchemaConfig (io.mycat.config.model.SchemaConfig)9 ServerConnection (io.mycat.server.ServerConnection)8 ArrayList (java.util.ArrayList)8 MycatConfig (io.mycat.config.MycatConfig)6 FrontendConnection (io.mycat.net.FrontendConnection)6 HashMap (java.util.HashMap)6 BackendConnection (io.mycat.backend.BackendConnection)4 PhysicalDBNode (io.mycat.backend.datasource.PhysicalDBNode)4 UserConfig (io.mycat.config.model.UserConfig)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 List (java.util.List)4 TreeSet (java.util.TreeSet)3