Search in sources :

Example 1 with PackageBufINf

use of com.actiontech.dble.manager.handler.PackageBufINf 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)

Example 2 with PackageBufINf

use of com.actiontech.dble.manager.handler.PackageBufINf in project dble by actiontech.

the class ShowTables method responseDirect.

private static void responseDirect(ServerConnection c, String cSchema, ShowCreateStmtInfo info) {
    ByteBuffer buffer = c.allocate();
    Map<String, String> tableMap = getTableSet(cSchema, info);
    PackageBufINf bufInf;
    if (info.isFull()) {
        List<FieldPacket> fieldPackets = new ArrayList<>(2);
        bufInf = writeFullTablesHeader(buffer, c, cSchema, fieldPackets);
        if (info.getWhere() != null) {
            MySQLItemVisitor mev = new MySQLItemVisitor(c.getSchema(), c.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager());
            info.getWhereExpr().accept(mev);
            List<Field> sourceFields = HandlerTool.createFields(fieldPackets);
            Item whereItem = HandlerTool.createItem(mev.getItem(), sourceFields, 0, false, DMLResponseHandler.HandlerType.WHERE);
            bufInf = writeFullTablesRow(bufInf.getBuffer(), c, tableMap, bufInf.getPacketId(), whereItem, sourceFields);
        } else {
            bufInf = writeFullTablesRow(bufInf.getBuffer(), c, tableMap, bufInf.getPacketId(), null, null);
        }
    } else {
        bufInf = writeTablesHeaderAndRows(buffer, c, tableMap, cSchema);
    }
    writeRowEof(bufInf.getBuffer(), c, bufInf.getPacketId());
}
Also used : MySQLItemVisitor(com.actiontech.dble.plan.visitor.MySQLItemVisitor) Field(com.actiontech.dble.plan.common.field.Field) Item(com.actiontech.dble.plan.common.item.Item) PackageBufINf(com.actiontech.dble.manager.handler.PackageBufINf) ByteBuffer(java.nio.ByteBuffer) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 3 with PackageBufINf

use of com.actiontech.dble.manager.handler.PackageBufINf in project dble by actiontech.

the class ShowTables method writeFullTablesRow.

public static PackageBufINf writeFullTablesRow(ByteBuffer buffer, ServerConnection c, Map<String, String> tableMap, byte packetId, Item whereItem, List<Field> sourceFields) {
    for (Map.Entry<String, String> entry : tableMap.entrySet()) {
        RowDataPacket row = new RowDataPacket(2);
        row.add(StringUtil.encode(entry.getKey().toLowerCase(), c.getCharset().getResults()));
        row.add(StringUtil.encode(entry.getValue(), c.getCharset().getResults()));
        if (whereItem != null) {
            HandlerTool.initFields(sourceFields, row.fieldValues);
            /* filter by where condition */
            if (whereItem.valBool()) {
                row.setPacketId(++packetId);
                buffer = row.write(buffer, c, true);
            }
        } else {
            row.setPacketId(++packetId);
            buffer = row.write(buffer, c, true);
        }
    }
    PackageBufINf packBuffInfo = new PackageBufINf();
    packBuffInfo.setBuffer(buffer);
    packBuffInfo.setPacketId(packetId);
    return packBuffInfo;
}
Also used : PackageBufINf(com.actiontech.dble.manager.handler.PackageBufINf) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 4 with PackageBufINf

use of com.actiontech.dble.manager.handler.PackageBufINf in project dble by actiontech.

the class ShowTables method writeTablesHeaderAndRows.

public static PackageBufINf writeTablesHeaderAndRows(ByteBuffer buffer, ServerConnection c, Map<String, String> tableMap, String cSchema) {
    int fieldCount = 1;
    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);
    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);
    }
    // write eof
    eof.write(buffer, c, true);
    for (String name : tableMap.keySet()) {
        RowDataPacket row = new RowDataPacket(fieldCount);
        row.add(StringUtil.encode(name.toLowerCase(), c.getCharset().getResults()));
        row.setPacketId(++packetId);
        buffer = row.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) RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket) EOFPacket(com.actiontech.dble.net.mysql.EOFPacket) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 5 with PackageBufINf

use of com.actiontech.dble.manager.handler.PackageBufINf in project dble by actiontech.

the class ShowTablesHandler method fieldEofResponse.

@Override
public void fieldEofResponse(byte[] header, List<byte[]> fields, List<FieldPacket> fieldPacketsNull, byte[] eof, boolean isLeft, BackendConnection conn) {
    ServerConnection source = session.getSource();
    buffer = allocBuffer();
    PackageBufINf bufInf;
    if (info.isFull()) {
        List<FieldPacket> fieldPackets = new ArrayList<>(2);
        bufInf = ShowTables.writeFullTablesHeader(buffer, source, showTableSchema, fieldPackets);
        packetId = bufInf.getPacketId();
        buffer = bufInf.getBuffer();
        if (info.getWhere() != null) {
            MySQLItemVisitor mev = new MySQLItemVisitor(source.getSchema(), source.getCharset().getResultsIndex(), DbleServer.getInstance().getTmManager());
            info.getWhereExpr().accept(mev);
            sourceFields = HandlerTool.createFields(fieldPackets);
            whereItem = HandlerTool.createItem(mev.getItem(), sourceFields, 0, false, DMLResponseHandler.HandlerType.WHERE);
            bufInf = ShowTables.writeFullTablesRow(buffer, source, shardingTablesMap, packetId, whereItem, sourceFields);
            packetId = bufInf.getPacketId();
            buffer = bufInf.getBuffer();
        } else {
            bufInf = ShowTables.writeFullTablesRow(buffer, source, shardingTablesMap, packetId, null, null);
            packetId = bufInf.getPacketId();
            buffer = bufInf.getBuffer();
        }
    } else {
        bufInf = ShowTables.writeTablesHeaderAndRows(buffer, source, shardingTablesMap, showTableSchema);
        packetId = bufInf.getPacketId();
        buffer = bufInf.getBuffer();
    }
}
Also used : MySQLItemVisitor(com.actiontech.dble.plan.visitor.MySQLItemVisitor) PackageBufINf(com.actiontech.dble.manager.handler.PackageBufINf) ArrayList(java.util.ArrayList) ServerConnection(com.actiontech.dble.server.ServerConnection) FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Aggregations

PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)5 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)4 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)2 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)2 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)2 MySQLItemVisitor (com.actiontech.dble.plan.visitor.MySQLItemVisitor)2 Field (com.actiontech.dble.plan.common.field.Field)1 Item (com.actiontech.dble.plan.common.item.Item)1 ServerConnection (com.actiontech.dble.server.ServerConnection)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1