Search in sources :

Example 1 with EOFPacket

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

the class MyCATSequnceProcessor method outRawData.

private void outRawData(ServerConnection sc, String value) {
    byte packetId = 0;
    int fieldCount = 1;
    ByteBuffer byteBuf = sc.allocate();
    ResultSetHeaderPacket headerPkg = new ResultSetHeaderPacket();
    headerPkg.fieldCount = fieldCount;
    headerPkg.packetId = ++packetId;
    byteBuf = headerPkg.write(byteBuf, sc, true);
    FieldPacket fieldPkg = new FieldPacket();
    fieldPkg.packetId = ++packetId;
    fieldPkg.name = StringUtil.encode("SEQUNCE", sc.getCharset());
    byteBuf = fieldPkg.write(byteBuf, sc, true);
    EOFPacket eofPckg = new EOFPacket();
    eofPckg.packetId = ++packetId;
    byteBuf = eofPckg.write(byteBuf, sc, true);
    RowDataPacket rowDataPkg = new RowDataPacket(fieldCount);
    rowDataPkg.packetId = ++packetId;
    rowDataPkg.add(StringUtil.encode(value, sc.getCharset()));
    byteBuf = rowDataPkg.write(byteBuf, sc, true);
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    byteBuf = lastEof.write(byteBuf, sc, true);
    // write buffer
    sc.write(byteBuf);
}
Also used : ResultSetHeaderPacket(io.mycat.net.mysql.ResultSetHeaderPacket) RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 2 with EOFPacket

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

the class PackageBufINf method handle.

public static void handle(String stmt, 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;
    PackageBufINf bufInf = null;
    // show log key=warn limit=0,30
    Map<String, String> condPairMap = getCondPair(stmt);
    if (condPairMap.isEmpty()) {
        bufInf = showLogSum(c, buffer, packetId);
    } else {
        String logFile = condPairMap.get("file");
        if (logFile == null) {
            logFile = DEFAULT_LOGFILE;
        }
        String limitStr = condPairMap.get("limit");
        limitStr = (limitStr != null) ? limitStr : "0," + 100000;
        String[] limtArry = limitStr.split("\\s|,");
        int start = Integer.parseInt(limtArry[0]);
        int page = Integer.parseInt(limtArry[1]);
        int end = Integer.valueOf(start + page);
        String key = condPairMap.get("key");
        String regex = condPairMap.get("regex");
        bufInf = showLogRange(c, buffer, packetId, key, regex, start, end, logFile);
    }
    packetId = bufInf.packetId;
    buffer = bufInf.buffer;
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 3 with EOFPacket

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

the class SelectSessionAutoIncrement 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;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.packetId = ++packetId;
    row.add(LongUtil.toBytes(1));
    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 : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 4 with EOFPacket

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

the class SelectVersionComment 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;
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(VERSION_COMMENT);
    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 : RowDataPacket(io.mycat.net.mysql.RowDataPacket) EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Example 5 with EOFPacket

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

the class ConfFileHandler method handle.

public static void handle(String stmt, 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 theStmt = stmt.toUpperCase().trim();
    PackageBufINf bufInf = null;
    if (theStmt.equals("FILE @@LIST")) {
        bufInf = listConfigFiles(c, buffer, packetId);
    } else if (theStmt.startsWith("FILE @@SHOW")) {
        int index = stmt.lastIndexOf(' ');
        String fileName = stmt.substring(index + 1);
        bufInf = showConfigFile(c, buffer, packetId, fileName);
    } else if (theStmt.startsWith(UPLOAD_CMD)) {
        int index = stmt.indexOf(' ', UPLOAD_CMD.length());
        int index2 = stmt.indexOf(' ', index + 1);
        if (index <= 0 || index2 <= 0 || index + 1 > stmt.length() || index2 + 1 > stmt.length()) {
            bufInf = showInfo(c, buffer, packetId, "Invald param ,usage  ");
        }
        String fileName = stmt.substring(index + 1, index2);
        String content = stmt.substring(index2 + 1).trim();
        bufInf = upLoadConfigFile(c, buffer, packetId, fileName, content);
    } else {
        bufInf = showInfo(c, buffer, packetId, "Invald command ");
    }
    packetId = bufInf.packetId;
    buffer = bufInf.buffer;
    // write last eof
    EOFPacket lastEof = new EOFPacket();
    lastEof.packetId = ++packetId;
    buffer = lastEof.write(buffer, c, true);
    // write buffer
    c.write(buffer);
}
Also used : EOFPacket(io.mycat.net.mysql.EOFPacket) ByteBuffer(java.nio.ByteBuffer) FieldPacket(io.mycat.net.mysql.FieldPacket)

Aggregations

EOFPacket (io.mycat.net.mysql.EOFPacket)154 ByteBuffer (java.nio.ByteBuffer)153 FieldPacket (io.mycat.net.mysql.FieldPacket)146 RowDataPacket (io.mycat.net.mysql.RowDataPacket)137 ResultSetHeaderPacket (io.mycat.net.mysql.ResultSetHeaderPacket)18 NIOProcessor (io.mycat.net.NIOProcessor)14 ServerConnection (io.mycat.server.ServerConnection)12 UserStat (io.mycat.statistic.stat.UserStat)12 Map (java.util.Map)10 SchemaConfig (io.mycat.config.model.SchemaConfig)8 ArrayList (java.util.ArrayList)7 MycatConfig (io.mycat.config.MycatConfig)6 FrontendConnection (io.mycat.net.FrontendConnection)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 HashMap (java.util.HashMap)4 List (java.util.List)4 TreeSet (java.util.TreeSet)3