Search in sources :

Example 71 with RowDataPacket

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

the class SessionIncrement method response.

public static void response(ServerConnection c) {
    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);
    byte packetId = EOF.getPacketId();
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(1));
    row.setPacketId(++packetId);
    buffer = row.write(buffer, c, true);
    EOFPacket lastEof = new EOFPacket();
    lastEof.setPacketId(++packetId);
    buffer = lastEof.write(buffer, c, true);
    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 72 with RowDataPacket

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

the class ShowCreateView method sendOutTheViewInfo.

public static void sendOutTheViewInfo(ServerConnection c, String schema, String viewName) throws Exception {
    // check if the view or schema is not exists
    if (schema == null || "".equals(schema)) {
        throw new Exception(" No database selected");
    }
    SchemaMeta schemaMeta = DbleServer.getInstance().getTmManager().getCatalogs().get(schema);
    if (schemaMeta == null) {
        throw new Exception("Table '" + schema + "." + viewName + "' doesn't exist");
    }
    ViewMeta view = schemaMeta.getViewMetas().get(viewName);
    if (view == null) {
        throw new Exception("Table '" + schema + "." + viewName + "' doesn't exist");
    }
    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(view, c.getCharset().getResults(), c.getCharset().getCollation());
    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 : ViewMeta(com.actiontech.dble.meta.ViewMeta) SchemaMeta(com.actiontech.dble.meta.SchemaMeta) 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 73 with RowDataPacket

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

the class ShowCreateView method getRow.

public static RowDataPacket getRow(ViewMeta view, String charset, String collationConnection) {
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(StringUtil.encode(view.getViewName(), charset));
    if (view.getViewColumnMeta() != null && view.getViewColumnMeta().size() > 0) {
        row.add(StringUtil.encode("create view " + view.getViewName() + view.getViewColumnMetaString() + " as " + view.getSelectSql(), charset));
    } else {
        row.add(StringUtil.encode("create view " + view.getViewName() + " as " + view.getSelectSql(), charset));
    }
    row.add(StringUtil.encode(charset, charset));
    row.add(StringUtil.encode(collationConnection, charset));
    return row;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 74 with RowDataPacket

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

the class OneRawSQLQueryResultHandler method onRowData.

@Override
public boolean onRowData(String dataNode, byte[] rowData) {
    RowDataPacket rowDataPkg = new RowDataPacket(fieldCount);
    rowDataPkg.read(rowData);
    String variableName = "";
    String variableValue = "";
    // if fieldcount is 2,it may be select x or show create table
    if (fieldCount == 2 && (fetchColPosMap.get("Variable_name") != null || fetchColPosMap.get("Value") != null)) {
        Integer ind = fetchColPosMap.get("Variable_name");
        if (ind != null) {
            byte[] columnData = rowDataPkg.fieldValues.get(ind);
            String columnVal = columnData != null ? new String(columnData) : null;
            variableName = columnVal;
        }
        ind = fetchColPosMap.get("Value");
        if (ind != null) {
            byte[] columnData = rowDataPkg.fieldValues.get(ind);
            String columnVal = columnData != null ? new String(columnData) : null;
            variableValue = columnVal;
        }
        result.put(variableName, variableValue);
    } else {
        for (String fetchCol : fetchCols) {
            Integer ind = fetchColPosMap.get(fetchCol);
            if (ind != null) {
                byte[] columnData = rowDataPkg.fieldValues.get(ind);
                String columnVal = columnData != null ? new String(columnData) : null;
                result.put(fetchCol, columnVal);
            } else {
                LOGGER.info("cant't find column in sql query result " + fetchCol);
            }
        }
    }
    return false;
}
Also used : RowDataPacket(com.actiontech.dble.net.mysql.RowDataPacket)

Example 75 with RowDataPacket

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

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, true);
    // write fields
    byte packetId = HEADER.getPacketId();
    FieldPacket field = PacketUtil.getField(alias, orgName, Fields.FIELD_TYPE_LONGLONG);
    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 rows
    RowDataPacket row = new RowDataPacket(FIELD_COUNT);
    row.add(LongUtil.toBytes(c.getLastInsertId()));
    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)

Aggregations

RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)141 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)59 FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)59 ByteBuffer (java.nio.ByteBuffer)59 ServerConfig (com.actiontech.dble.config.ServerConfig)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)8 Map (java.util.Map)8 PhysicalDBPool (com.actiontech.dble.backend.datasource.PhysicalDBPool)7 PhysicalDatasource (com.actiontech.dble.backend.datasource.PhysicalDatasource)7 MySQLConnection (com.actiontech.dble.backend.mysql.nio.MySQLConnection)7 LocalResult (com.actiontech.dble.backend.mysql.store.LocalResult)6 UnSortedLocalResult (com.actiontech.dble.backend.mysql.store.UnSortedLocalResult)6 DBHeartbeat (com.actiontech.dble.backend.heartbeat.DBHeartbeat)5 ItemSum (com.actiontech.dble.plan.common.item.function.sumfunc.ItemSum)5 UserStat (com.actiontech.dble.statistic.stat.UserStat)5 BackendConnection (com.actiontech.dble.backend.BackendConnection)4 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 FrontendConnection (com.actiontech.dble.net.FrontendConnection)4 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)4 LinkedList (java.util.LinkedList)4