Skip to content

Commit befd5f2

Browse files
committed
Add row recycling in collector
1 parent 689ead8 commit befd5f2

File tree

16 files changed

+176
-38
lines changed

16 files changed

+176
-38
lines changed

vertx-db2-client/src/main/java/io/vertx/db2client/impl/DB2RowImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
import io.vertx.sqlclient.Row;
3333
import io.vertx.sqlclient.data.Numeric;
3434
import io.vertx.sqlclient.impl.ArrayTuple;
35+
import io.vertx.sqlclient.impl.RowBase;
3536
import io.vertx.sqlclient.impl.RowDesc;
3637

37-
public class DB2RowImpl extends ArrayTuple implements Row {
38+
public class DB2RowImpl extends RowBase {
3839

3940
private final RowDesc rowDesc;
4041

vertx-db2-client/src/main/java/io/vertx/db2client/impl/codec/RowResultDecoder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.vertx.sqlclient.Row;
2828
import io.vertx.sqlclient.data.Numeric;
2929
import io.vertx.sqlclient.impl.RowDecoder;
30+
import io.vertx.sqlclient.impl.RowInternal;
3031

3132
class RowResultDecoder<C, R> extends RowDecoder<C, R> {
3233

@@ -53,8 +54,12 @@ public boolean next() {
5354
}
5455

5556
@Override
56-
protected Row decodeRow(int len, ByteBuf in) {
57-
Row row = new DB2RowImpl(rowDesc);
57+
protected RowInternal row() {
58+
return new DB2RowImpl(rowDesc);
59+
}
60+
61+
@Override
62+
protected boolean decodeRow(int len, ByteBuf in, Row row) {
5863
for (int i = 1; i < rowDesc.columnDefinitions().columns_ + 1; i++) {
5964
int startingIdx = cursor.dataBuffer_.readerIndex();
6065
Object o = cursor.getObject(i);
@@ -73,6 +78,6 @@ protected Row decodeRow(int len, ByteBuf in) {
7378
if (LOG.isDebugEnabled()) {
7479
LOG.debug("decoded row values: " + row.deepToString());
7580
}
76-
return row;
81+
return true;
7782
}
7883
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import io.vertx.core.buffer.Buffer;
1515
import io.vertx.sqlclient.Row;
1616
import io.vertx.sqlclient.impl.ArrayTuple;
17+
import io.vertx.sqlclient.impl.RowBase;
1718
import io.vertx.sqlclient.impl.RowDesc;
1819

1920
import java.math.BigDecimal;
@@ -25,7 +26,7 @@
2526
import java.util.List;
2627
import java.util.UUID;
2728

28-
public class MSSQLRowImpl extends ArrayTuple implements Row {
29+
public class MSSQLRowImpl extends RowBase {
2930
private final RowDesc rowDesc;
3031

3132
public MSSQLRowImpl(RowDesc rowDesc) {

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
import io.vertx.mssqlclient.impl.MSSQLRowImpl;
1616
import io.vertx.sqlclient.Row;
1717
import io.vertx.sqlclient.impl.RowDecoder;
18+
import io.vertx.sqlclient.impl.RowInternal;
1819

19-
import java.util.Objects;
2020
import java.util.stream.Collector;
2121

2222
public class RowResultDecoder<C, R> extends RowDecoder<C, R> {
@@ -36,18 +36,20 @@ public MSSQLRowDesc desc() {
3636
}
3737

3838
@Override
39-
public Row decodeRow(int len, ByteBuf in) {
40-
Row decoded;
39+
protected RowInternal row() {
40+
return new MSSQLRowImpl(desc);
41+
}
42+
43+
@Override
44+
protected boolean decodeRow(int len, ByteBuf in, Row row) {
4145
if (nbc) {
42-
decoded = decodeMssqlNbcRow(in);
46+
return decodeMssqlNbcRow(in, row);
4347
} else {
44-
decoded = decodeMssqlRow(in);
48+
return decodeMssqlRow(in, row);
4549
}
46-
return decoded;
4750
}
4851

49-
private Row decodeMssqlRow(ByteBuf in) {
50-
Row row = new MSSQLRowImpl(desc);
52+
private boolean decodeMssqlRow(ByteBuf in, Row row) {
5153
int len = desc.size();
5254
for (int c = 0; c < len; c++) {
5355
ColumnData columnData = desc.get(c);
@@ -56,18 +58,15 @@ private Row decodeMssqlRow(ByteBuf in) {
5658
return ifNotMissing(in, row);
5759
}
5860

59-
private Row ifNotMissing(ByteBuf in, Row row) {
60-
Row result;
61+
private boolean ifNotMissing(ByteBuf in, Row row) {
6162
if (desc.hasRowStat() && in.readIntLE() == FETCH_MISSING) {
62-
result = null;
63+
return false;
6364
} else {
64-
result = row;
65+
return true;
6566
}
66-
return result;
6767
}
6868

69-
private Row decodeMssqlNbcRow(ByteBuf in) {
70-
Row row = new MSSQLRowImpl(desc);
69+
private boolean decodeMssqlNbcRow(ByteBuf in, Row row) {
7170
int len = desc.size();
7271
int nullBitmapByteCount = ((len - 1) >> 3) + 1;
7372
int nullBitMapStartIdx = in.readerIndex();

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/MySQLRowImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@
2020
import io.vertx.sqlclient.Row;
2121
import io.vertx.sqlclient.data.Numeric;
2222
import io.vertx.sqlclient.impl.ArrayTuple;
23+
import io.vertx.sqlclient.impl.RowBase;
2324

2425
import java.time.*;
2526
import java.time.temporal.Temporal;
2627
import java.util.List;
2728
import java.util.UUID;
2829

29-
public class MySQLRowImpl extends ArrayTuple implements Row {
30+
public class MySQLRowImpl extends RowBase {
3031

3132
private final MySQLRowDesc rowDesc;
3233

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/codec/MySQLDecoder.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
import io.netty.channel.ChannelHandlerContext;
1717
import io.netty.channel.ChannelInboundHandlerAdapter;
1818

19-
import java.util.ArrayDeque;
20-
2119
import static io.vertx.mysqlclient.impl.protocol.Packets.PACKET_PAYLOAD_LENGTH_LIMIT;
2220

2321
class MySQLDecoder extends ChannelInboundHandlerAdapter {

vertx-mysql-client/src/main/java/io/vertx/mysqlclient/impl/codec/RowResultDecoder.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.vertx.mysqlclient.impl.protocol.ColumnDefinition;
2121
import io.vertx.sqlclient.Row;
2222
import io.vertx.sqlclient.impl.RowDecoder;
23+
import io.vertx.sqlclient.impl.RowInternal;
2324

2425
import java.util.stream.Collector;
2526

@@ -34,8 +35,12 @@ class RowResultDecoder<C, R> extends RowDecoder<C, R> {
3435
}
3536

3637
@Override
37-
protected Row decodeRow(int len, ByteBuf in) {
38-
Row row = new MySQLRowImpl(rowDesc);
38+
protected RowInternal row() {
39+
return new MySQLRowImpl(rowDesc);
40+
}
41+
42+
@Override
43+
protected boolean decodeRow(int len, ByteBuf in, Row row) {
3944
if (rowDesc.dataFormat() == DataFormat.BINARY) {
4045
// BINARY row decoding
4146
// 0x00 packet header
@@ -76,7 +81,7 @@ protected Row decodeRow(int len, ByteBuf in) {
7681
row.addValue(decoded);
7782
}
7883
}
79-
return row;
84+
return true;
8085
}
8186
}
8287

vertx-oracle-client/src/main/java/io/vertx/oracleclient/impl/OracleRow.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
import io.vertx.sqlclient.Row;
1717
import io.vertx.sqlclient.data.Numeric;
1818
import io.vertx.sqlclient.impl.ArrayTuple;
19+
import io.vertx.sqlclient.impl.RowBase;
1920
import io.vertx.sqlclient.impl.RowDesc;
2021

2122
import java.time.*;
2223
import java.util.List;
2324
import java.util.UUID;
2425

25-
public class OracleRow extends ArrayTuple implements Row {
26+
public class OracleRow extends RowBase {
2627

2728
private final RowDesc desc;
2829

vertx-oracle-client/src/test/java/io/vertx/oracleclient/test/tck/OracleCollectorTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.vertx.oracleclient.test.junit.OracleRule;
1717
import io.vertx.sqlclient.Row;
1818
import io.vertx.sqlclient.tck.CollectorTestBase;
19+
import org.junit.Assume;
1920
import org.junit.ClassRule;
2021
import org.junit.Test;
2122
import org.junit.runner.RunWith;
@@ -258,4 +259,14 @@ public Set<Characteristics> characteristics() {
258259
return Collections.emptySet();
259260
}
260261
}
262+
263+
@Override
264+
public void testCollectorRecycle(TestContext ctx) {
265+
Assume.assumeTrue(false);
266+
}
267+
268+
@Override
269+
public void testCollectorNoRecycle(TestContext ctx) {
270+
Assume.assumeTrue(false);
271+
}
261272
}

vertx-pg-client/src/main/java/io/vertx/pgclient/impl/RowImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@
2424
import io.vertx.sqlclient.Row;
2525
import io.vertx.sqlclient.data.Numeric;
2626
import io.vertx.sqlclient.impl.ArrayTuple;
27+
import io.vertx.sqlclient.impl.RowBase;
2728
import io.vertx.sqlclient.impl.RowDesc;
29+
import io.vertx.sqlclient.impl.RowInternal;
2830

2931
import java.lang.reflect.Array;
3032
import java.time.*;
3133
import java.util.List;
3234
import java.util.UUID;
3335

34-
public class RowImpl extends ArrayTuple implements Row {
36+
public class RowImpl extends RowBase {
3537

3638
private final RowDesc desc;
3739

0 commit comments

Comments
 (0)