static { int i = 0; byte packetId = 0; header.packetId = ++packetId; fields[i] = PacketUtil.getField("SESSION.AUTOINCREMENT", Fields.FIELD_TYPE_LONGLONG); fields[i++].packetId = ++packetId; eof.packetId = ++packetId; }
/** @author xianmao.hexm 2011-5-9 下午06:06:12 */ public final class SelectSessionAutoIncrement { private static final int FIELD_COUNT = 1; private static final ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT); private static final FieldPacket[] fields = new FieldPacket[FIELD_COUNT]; private static final EOFPacket eof = new EOFPacket(); static { int i = 0; byte packetId = 0; header.packetId = ++packetId; fields[i] = PacketUtil.getField("SESSION.AUTOINCREMENT", Fields.FIELD_TYPE_LONGLONG); fields[i++].packetId = ++packetId; eof.packetId = ++packetId; } public static void execute(ManagerConnection 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.packetId = ++packetId; row.add(LongUtil.toBytes(1)); 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); } }
/** @author <a href="mailto:[email protected]">QIU Shuo</a> */ public class SelectIdentity { private static final int FIELD_COUNT = 1; private static final ResultSetHeaderPacket header = PacketUtil.getHeader(FIELD_COUNT); static { byte packetId = 0; header.packetId = ++packetId; } 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); } }