Search in sources :

Example 41 with FieldPacket

use of com.actiontech.dble.net.mysql.FieldPacket 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 42 with FieldPacket

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

the class OneRawSQLQueryResultHandler method onHeader.

@Override
public void onHeader(List<byte[]> fields) {
    fieldCount = fields.size();
    fetchColPosMap = new HashMap<>();
    for (String watchFd : fetchCols) {
        for (int i = 0; i < fieldCount; i++) {
            byte[] field = fields.get(i);
            FieldPacket fieldPkg = new FieldPacket();
            fieldPkg.read(field);
            String fieldName = new String(fieldPkg.getName());
            if (watchFd.equalsIgnoreCase(fieldName)) {
                fetchColPosMap.put(fieldName, i);
            }
        }
    }
}
Also used : FieldPacket(com.actiontech.dble.net.mysql.FieldPacket)

Example 43 with FieldPacket

use of com.actiontech.dble.net.mysql.FieldPacket 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)

Example 44 with FieldPacket

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

the class SelectLastInsertId method response.

public static void response(ServerConnection c, String stmt, int aliasIndex) {
    String alias = ParseUtil.parseAlias(stmt, aliasIndex);
    if (alias == null) {
        alias = ORG_NAME;
    }
    ByteBuffer buffer = c.allocate();
    // write header
    buffer = HEADER.write(buffer, c, true);
    // write fields
    byte packetId = HEADER.getPacketId();
    FieldPacket field = PacketUtil.getField(alias, ORG_NAME, 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)

Example 45 with FieldPacket

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

the class SelectTxReadOnly 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);
    int result = c.isReadOnly() ? 1 : 0;
    row.add(LongUtil.toBytes(result));
    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)

Aggregations

FieldPacket (com.actiontech.dble.net.mysql.FieldPacket)81 EOFPacket (com.actiontech.dble.net.mysql.EOFPacket)65 ByteBuffer (java.nio.ByteBuffer)64 RowDataPacket (com.actiontech.dble.net.mysql.RowDataPacket)59 ArrayList (java.util.ArrayList)9 Map (java.util.Map)8 NIOProcessor (com.actiontech.dble.net.NIOProcessor)6 ResultSetHeaderPacket (com.actiontech.dble.net.mysql.ResultSetHeaderPacket)6 Item (com.actiontech.dble.plan.common.item.Item)6 UserStat (com.actiontech.dble.statistic.stat.UserStat)6 SchemaConfig (com.actiontech.dble.config.model.SchemaConfig)4 PackageBufINf (com.actiontech.dble.manager.handler.PackageBufINf)4 RowDataComparator (com.actiontech.dble.backend.mysql.nio.handler.util.RowDataComparator)3 ServerConfig (com.actiontech.dble.config.ServerConfig)3 FrontendConnection (com.actiontech.dble.net.FrontendConnection)3 Field (com.actiontech.dble.plan.common.field.Field)3 BackendConnection (com.actiontech.dble.backend.BackendConnection)2 PhysicalDBNode (com.actiontech.dble.backend.datasource.PhysicalDBNode)2 TableConfig (com.actiontech.dble.config.model.TableConfig)2 UserConfig (com.actiontech.dble.config.model.UserConfig)2