use of com.actiontech.dble.net.mysql.RowDataPacket 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);
}
use of com.actiontech.dble.net.mysql.RowDataPacket 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);
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class SelectVariables method execute.
public static void execute(ServerConnection c, String sql) {
String subSql = sql.substring(sql.indexOf("SELECT") + 6);
List<String> splitVar = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(subSql);
splitVar = convert(splitVar);
int fieldCount = splitVar.size();
ResultSetHeaderPacket header = PacketUtil.getHeader(fieldCount);
FieldPacket[] fields = new FieldPacket[fieldCount];
int i = 0;
byte packetId = 0;
header.setPacketId(++packetId);
for (String s : splitVar) {
fields[i] = PacketUtil.getField(s, Fields.FIELD_TYPE_VAR_STRING);
fields[i++].setPacketId(++packetId);
}
ByteBuffer buffer = c.allocate();
// write header
buffer = header.write(buffer, c, true);
// write fields
for (FieldPacket field : fields) {
buffer = field.write(buffer, c, true);
}
EOFPacket eof = new EOFPacket();
eof.setPacketId(++packetId);
// write eof
buffer = eof.write(buffer, c, true);
// write rows
// byte packetId = eof.packetId;
RowDataPacket row = new RowDataPacket(fieldCount);
for (String s : splitVar) {
String value = VARIABLES.get(s) == null ? "" : VARIABLES.get(s);
row.add(value.getBytes());
}
row.setPacketId(++packetId);
buffer = row.write(buffer, c, true);
// write lastEof
EOFPacket lastEof = new EOFPacket();
lastEof.setPacketId(++packetId);
buffer = lastEof.write(buffer, c, true);
// write buffer
c.write(buffer);
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class FetchMySQLSequenceHandler method rowResponse.
@Override
public boolean rowResponse(byte[] row, RowDataPacket rowPacket, boolean isLeft, BackendConnection conn) {
RowDataPacket rowDataPkg = new RowDataPacket(1);
rowDataPkg.read(row);
byte[] columnData = rowDataPkg.fieldValues.get(0);
String columnVal = new String(columnData);
SequenceVal seqVal = (SequenceVal) conn.getAttachment();
if (IncrSequenceMySQLHandler.ERR_SEQ_RESULT.equals(columnVal)) {
seqVal.dbretVal = IncrSequenceMySQLHandler.ERR_SEQ_RESULT;
LOGGER.warn(AlarmCode.CORE_SEQUENCE_WARN + " sequnce sql returned err value ,sequence:" + seqVal.seqName + " " + columnVal + " sql:" + seqVal.sql);
} else {
seqVal.dbretVal = columnVal;
}
return false;
}
use of com.actiontech.dble.net.mysql.RowDataPacket in project dble by actiontech.
the class JoinHandler method addRowToDeque.
private void addRowToDeque(RowDataPacket row, int columnCount, FairLinkedBlockingDeque<LocalResult> deque, RowDataComparator cmp) throws InterruptedException {
LocalResult localResult = deque.peekLast();
if (localResult != null) {
RowDataPacket lastRow = localResult.getLastRow();
if (lastRow.getFieldCount() == 0) {
// eof may added in terminateThread
return;
} else if (row.getFieldCount() > 0 && cmp.compare(lastRow, row) == 0) {
localResult.add(row);
return;
} else {
localResult.done();
}
}
LocalResult newLocalResult = new UnSortedLocalResult(columnCount, pool, this.charset).setMemSizeController(session.getJoinBufferMC());
newLocalResult.add(row);
if (row.getFieldCount() == 0)
newLocalResult.done();
deque.putLast(newLocalResult);
}
Aggregations