Search in sources :

Example 16 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class PreparedStmtResponse method response.

public static void response(PreparedStatement pstmt, FrontendConnection c) {
    byte packetId = 0;
    // write preparedOk packet
    PreparedOkPacket preparedOk = new PreparedOkPacket();
    preparedOk.packetId = ++packetId;
    preparedOk.statementId = pstmt.getId();
    preparedOk.columnsNumber = pstmt.getColumnsNumber();
    preparedOk.parametersNumber = pstmt.getParametersNumber();
    ByteBuffer buffer = preparedOk.write(c.allocate(), c);
    // write parameter field packet
    int parametersNumber = preparedOk.parametersNumber;
    if (parametersNumber > 0) {
        for (int i = 0; i < parametersNumber; i++) {
            FieldPacket field = new FieldPacket();
            field.packetId = ++packetId;
            buffer = field.write(buffer, c);
        }
        EOFPacket eof = new EOFPacket();
        eof.packetId = ++packetId;
        buffer = eof.write(buffer, c);
    }
    // write column field packet
    int columnsNumber = preparedOk.columnsNumber;
    if (columnsNumber > 0) {
        for (int i = 0; i < columnsNumber; i++) {
            FieldPacket field = new FieldPacket();
            field.packetId = ++packetId;
            buffer = field.write(buffer, c);
        }
        EOFPacket eof = new EOFPacket();
        eof.packetId = ++packetId;
        buffer = eof.write(buffer, c);
    }
    // send buffer
    c.write(buffer);
}
Also used : EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) PreparedOkPacket(com.alibaba.cobar.net.mysql.PreparedOkPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 17 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class SelectDatabase method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    buffer = header.write(buffer, c);
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    buffer = eof.write(buffer, c);
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(c.getSchema(), c.getCharset()));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    c.write(buffer);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 18 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class SelectIdentity method response.

public static void response(ServerConnection c, String stmt, int aliasIndex, final String orgName) {
    String alias = ParseUtil.parseAlias(stmt, aliasIndex);
    if (alias == null) {
        alias = orgName;
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    byte packetId = header.packetId;
    FieldPacket field = PacketUtil.getField(alias, orgName, Fields.FIELD_TYPE_LONGLONG);
    field.packetId = ++packetId;
    buffer = field.write(buffer, c);
    // write eof
    EOFPacket eof = new EOFPacket();
    eof.packetId = ++packetId;
    buffer = eof.write(buffer, c);
    // write rows
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(c.getLastInsertId()));
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 19 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class SelectVersionComment method response.

public static void response(ServerConnection c) {
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = header.write(buffer, c);
    // write fields
    for (FieldPacket field : fields) {
        buffer = field.write(buffer, c);
    }
    // write eof
    buffer = eof.write(buffer, c);
    // write rows
    byte packetId = eof.packetId;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(VERSION_COMMENT);
    row.packetId = ++packetId;
    buffer = row.write(buffer, c);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c);
    // post write
    c.write(buffer);
}
Also used : RowDataPacket(com.alibaba.cobar.net.mysql.RowDataPacket) EOFPacket(com.alibaba.cobar.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.alibaba.cobar.net.mysql.FieldPacket)

Example 20 with FieldPacket

use of com.alibaba.cobar.net.mysql.FieldPacket in project cobar by alibaba.

the class ShowCobarStatus method response.

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

Aggregations

FieldPacket (com.alibaba.cobar.net.mysql.FieldPacket)43 ByteBuffer (java.nio.ByteBuffer)40 EOFPacket (com.alibaba.cobar.net.mysql.EOFPacket)38 RowDataPacket (com.alibaba.cobar.net.mysql.RowDataPacket)37 NIOProcessor (com.alibaba.cobar.net.NIOProcessor)6 CobarConfig (com.alibaba.cobar.CobarConfig)5 MySQLDataNode (com.alibaba.cobar.mysql.MySQLDataNode)5 SchemaConfig (com.alibaba.cobar.config.model.SchemaConfig)3 MySQLDataSource (com.alibaba.cobar.mysql.MySQLDataSource)3 SQLRecord (com.alibaba.cobar.statistic.SQLRecord)3 FrontendConnection (com.alibaba.cobar.net.FrontendConnection)2 MySQLPacket (com.alibaba.cobar.net.mysql.MySQLPacket)2 ResultSetHeaderPacket (com.alibaba.cobar.net.mysql.ResultSetHeaderPacket)2 ServerConnection (com.alibaba.cobar.server.ServerConnection)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 DataSourceConfig (com.alibaba.cobar.config.model.DataSourceConfig)1 UserConfig (com.alibaba.cobar.config.model.UserConfig)1 MySQLChannel (com.alibaba.cobar.mysql.bio.MySQLChannel)1