Skip to content

Commit 689ead8

Browse files
committed
The MSSQL row decoder bypasses the decoder flow since handling a row might produce no row. We would like to have the same flow to be used.
The row decoder handleRow method now checks if the returned row is not null before passing it to the collector. In addition we need to use a specific mode to let the mssql decoder which decoding it should use dynamically.
1 parent 2e74ebc commit 689ead8

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/QueryCommandBaseCodec.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ protected void handleRowDesc(MSSQLRowDesc mssqlRowDesc) {
3838

3939
@Override
4040
protected void handleRow(ByteBuf payload) {
41-
rowResultDecoder.handleRow(payload);
41+
rowResultDecoder.nbc = false;
42+
rowResultDecoder.handleRow(-1, payload);
4243
}
4344

4445
@Override
4546
protected void handleNbcRow(ByteBuf payload) {
46-
rowResultDecoder.handleNbcRow(payload);
47+
rowResultDecoder.nbc = true;
48+
rowResultDecoder.handleRow(-1, payload);
4749
}
4850

4951
@Override

vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/RowResultDecoder.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ public class RowResultDecoder<C, R> extends RowDecoder<C, R> {
2424
private static final int FETCH_MISSING = 0x0002;
2525

2626
private final MSSQLRowDesc desc;
27-
28-
private Row decoded;
27+
public boolean nbc;
2928

3029
public RowResultDecoder(Collector<Row, C, R> collector, MSSQLRowDesc desc) {
3130
super(collector);
@@ -38,23 +37,13 @@ public MSSQLRowDesc desc() {
3837

3938
@Override
4039
public Row decodeRow(int len, ByteBuf in) {
41-
Row row = Objects.requireNonNull(decoded);
42-
decoded = null;
43-
return row;
44-
}
45-
46-
public void handleRow(ByteBuf in) {
47-
decoded = decodeMssqlRow(in);
48-
if (decoded != null) {
49-
super.handleRow(-1, in);
50-
}
51-
}
52-
53-
public void handleNbcRow(ByteBuf in) {
54-
decoded = decodeMssqlNbcRow(in);
55-
if (decoded != null) {
56-
super.handleRow(-1, in);
40+
Row decoded;
41+
if (nbc) {
42+
decoded = decodeMssqlNbcRow(in);
43+
} else {
44+
decoded = decodeMssqlRow(in);
5745
}
46+
return decoded;
5847
}
5948

6049
private Row decodeMssqlRow(ByteBuf in) {

vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/RowDecoder.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,24 @@ public int size() {
4646
protected abstract Row decodeRow(int len, ByteBuf in);
4747

4848
public void handleRow(int len, ByteBuf in) {
49-
if (failure != null) {
50-
return;
51-
}
5249
Row row = decodeRow(len, in);
53-
if (accumulator == null) {
50+
if (row != null && failure == null) {
51+
if (accumulator == null) {
52+
try {
53+
accumulator = collector.accumulator();
54+
} catch (Exception e) {
55+
failure = e;
56+
return;
57+
}
58+
}
5459
try {
55-
accumulator = collector.accumulator();
60+
accumulator.accept(container, row);
5661
} catch (Exception e) {
5762
failure = e;
5863
return;
5964
}
65+
size++;
6066
}
61-
try {
62-
accumulator.accept(container, row);
63-
} catch (Exception e) {
64-
failure = e;
65-
return;
66-
}
67-
size++;
6867
}
6968

7069
public R result() {

0 commit comments

Comments
 (0)