Skip to content

Commit 546a35b

Browse files
Remove support for trailing add()s
1 parent 1e90b9d commit 546a35b

File tree

6 files changed

+38
-24
lines changed

6 files changed

+38
-24
lines changed

src/main/java/oracle/r2dbc/impl/OracleStatementImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,10 +1092,9 @@ private Publisher<OracleResultImpl> executeGeneratingValues() {
10921092
/**
10931093
* <p>
10941094
* Executes this {@code Statement} as a batch DML command. The returned
1095-
* {@code Publisher} emits 1 {@code Result} for each set of bind values in
1096-
* this {@code Statement}'s {@link #batch}. Each {@code Result} has an
1097-
* update count and no row data. Update counts are floored to a maximum of
1098-
* {@link Integer#MAX_VALUE}.
1095+
* {@code Publisher} emits 1 {@code Result} having a
1096+
* {@link io.r2dbc.spi.Result.UpdateCount} segment for each set of bind
1097+
* values in the {@link #batch}.
10991098
* </p><p>
11001099
* This method copies any mutable state of this {@code Statement} needed to
11011100
* execute the batch; Any mutations that occur after this method returns will
@@ -1108,14 +1107,14 @@ private Publisher<OracleResultImpl> executeGeneratingValues() {
11081107
* subscriber subscribes, before the subscriber emits a {@code request}
11091108
* signal.
11101109
* </p>
1111-
* @return {@code Publisher} that the {@code Result}s of executing this
1110+
* @return {@code Publisher} that emits the {@code Result}s of executing this
11121111
* {@code Statement} as a batch DML command.
11131112
* @throws IllegalStateException If this {@code Statement} has been
11141113
* configured to return generated values with
11151114
* {@link #returnGeneratedValues(String...)}. Oracle JDBC does not support
11161115
* batch execution that returns generated keys.
1117-
* @throws IllegalStateException If at least one parameter has been set
1118-
* since the last call to {@link #add()}, but not all parameters have been set
1116+
* @throws IllegalStateException If not all parameters have been set since the
1117+
* last call to {@link #add()}
11191118
* @throws IllegalStateException If all parameters have been set since the
11201119
* last call to {@link #add()}, and an out parameter is present. JDBC does
11211120
* not support batch execution with out parameters.
@@ -1127,7 +1126,8 @@ Publisher<OracleResultImpl> executeBatch() {
11271126
"Batch execution with generated values is not supported");
11281127
}
11291128

1130-
addImplicit();
1129+
1130+
add(); // TODO: Catch and emit IllegalStateException as R2dbcException?
11311131
Queue<Object[]> currentBatch = batch;
11321132
int batchSize = batch.size();
11331133
batch = new LinkedList<>();

src/test/java/oracle/r2dbc/impl/OracleConnectionImplTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,9 @@ public void testRollbackTransaction() {
843843
"Hola, Oracle",
844844
"Namaste, Oracle",
845845
"Ni hao, Oracle");
846-
values.forEach(value -> insert.bind("value", value).add());
846+
values.subList(0, values.size() - 1)
847+
.forEach(value -> insert.bind("value", value).add());
848+
insert.bind("value", values.get(values.size() - 1));
847849
awaitUpdate(
848850
values.stream().map(value -> 1).collect(Collectors.toList()),
849851
insert);
@@ -982,7 +984,7 @@ public void testSetAutoCommit() {
982984
List.of(1, 1),
983985
insertInSessionA
984986
.bind(0, "D").add()
985-
.bind(0, "D").add());
987+
.bind(0, "D"));
986988
awaitNone(enableAutoCommitPublisher);
987989
assertFalse(sessionA.isAutoCommit(),
988990
"Unexpected value returned by isAutoCommit() after subscribing to"

src/test/java/oracle/r2dbc/impl/OracleResultImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ public void testBatchUpdateError() {
407407
awaitNone(Mono.from(connection.createStatement(
408408
"INSERT INTO testBatchUpdateError VALUES (?)")
409409
.bind(0, 0).add()
410-
.bind(0, 0).add()
410+
.bind(0, 0)
411411
.execute())
412412
.flatMapMany(result ->
413413
result.flatMap(segment -> {

src/test/java/oracle/r2dbc/impl/OracleStatementImplTest.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void testBindByIndex() {
9595
.bind(0, 0).bind(1, 0).add()
9696
.bind(0, 1).bind(1, 0).add()
9797
.bind(0, 1).bind(1, 1).add()
98-
.bind(0, 1).bind(1, 2).add());
98+
.bind(0, 1).bind(1, 2));
9999

100100
// Expect bind values to be applied in WHERE clause as:
101101
// SELECT x, y FROM testBindByIndex WHERE x = 1 AND y > 0
@@ -217,7 +217,7 @@ public void testBindByName() {
217217
.bind("X", 0).bind("Y", 0).add()
218218
.bind("X", 1).bind("Y", 0).add()
219219
.bind("X", 1).bind("Y", 1).add()
220-
.bind("X", 1).bind("Y", 2).add());
220+
.bind("X", 1).bind("Y", 2));
221221

222222
// Expect bind values to be applied in WHERE clause as:
223223
// SELECT x, y FROM testBindByName WHERE x = 1 AND y > 0
@@ -430,7 +430,7 @@ public void testBindNullByIndex() {
430430
.bindNull(0, Integer.class).bind(1, 1).add()
431431
.bindNull(0, Integer.class).bind(1, 2).add()
432432
.bind(0, 0).bind(1, 3).add()
433-
.bind(0, 0).bindNull(1, Integer.class).add());
433+
.bind(0, 0).bindNull(1, Integer.class));
434434
awaitQuery(
435435
asList(
436436
asList(null, 0),
@@ -574,7 +574,7 @@ public void testBindNullByName() {
574574
.bindNull("x", Integer.class).bind("y", 1).add()
575575
.bindNull("x", Integer.class).bind("y", 2).add()
576576
.bind("x", 0).bind("y", 3).add()
577-
.bind("x", 0).bindNull("y", Integer.class).add());
577+
.bind("x", 0).bindNull("y", Integer.class));
578578
awaitQuery(
579579
asList(
580580
asList(null, 0),
@@ -725,7 +725,7 @@ public void testAdd() {
725725
awaitUpdate(
726726
asList(1, 1, 1),
727727
connection.createStatement("INSERT INTO testAdd VALUES(0, 0)")
728-
.add().add().add());
728+
.add().add());
729729
awaitQuery(
730730
asList(asList(0, 0), asList(0, 0), asList(0, 0)),
731731
row -> asList(row.get(0, Integer.class), row.get(1, Integer.class)),
@@ -737,7 +737,7 @@ public void testAdd() {
737737
connection.createStatement("INSERT INTO testAdd VALUES(:x, :y)")
738738
.bind("x", 1).bind("y", 1).add()
739739
.bind("x", 1).bind("y", 2).add()
740-
.bind("x", 1).bind("y", 3).add());
740+
.bind("x", 1).bind("y", 3));
741741
awaitQuery(
742742
asList(asList(1, 1), asList(1, 2), asList(1, 3)),
743743
row -> asList(row.get(0, Integer.class), row.get(1, Integer.class)),
@@ -768,7 +768,7 @@ public void testAdd() {
768768
Mono.from(connection.createStatement("SELECT ? FROM dual")
769769
.bind(0, 1).add()
770770
.bind(0, 2).add()
771-
.bind(0, 3).add()
771+
.bind(0, 3)
772772
.execute())
773773
.flatMapMany(Result::getRowsUpdated));
774774

@@ -860,7 +860,7 @@ public void testExecute() {
860860
asList(1, 1),
861861
updateStatement
862862
.bind("oldValue", 1).bind("newValue", 2).add()
863-
.bind("oldValue", 0).bind("newValue", 1).add());
863+
.bind("oldValue", 0).bind("newValue", 1));
864864

865865
// Expect bind values to be cleared after execute with explicit add()
866866
assertThrows(IllegalStateException.class, updateStatement::execute);
@@ -1757,8 +1757,9 @@ public void testNoOutImplicitResult() {
17571757
// Load [0,100] into the table
17581758
Statement insert = connection.createStatement(
17591759
"INSERT INTO testNoOutImplicitResult VALUES (?)");
1760-
IntStream.rangeClosed(0, 100)
1760+
IntStream.range(0, 100)
17611761
.forEach(i -> insert.bind(0, i).add());
1762+
insert.bind(0, 100);
17621763
awaitOne(101, Flux.from(insert.execute())
17631764
.flatMap(Result::getRowsUpdated)
17641765
.reduce(0, (total, updateCount) -> total + updateCount));
@@ -1867,8 +1868,9 @@ public void testOutAndImplicitResult() {
18671868
// Load [0,100] into the table
18681869
Statement insert = connection.createStatement(
18691870
"INSERT INTO testOutAndImplicitResult VALUES (?)");
1870-
IntStream.rangeClosed(0, 100)
1871+
IntStream.range(0, 100)
18711872
.forEach(i -> insert.bind(0, i).add());
1873+
insert.bind(0, 100);
18721874
awaitOne(101, Flux.from(insert.execute())
18731875
.flatMap(Result::getRowsUpdated)
18741876
.reduce(0, (total, updateCount) -> total + updateCount));

src/test/java/oracle/r2dbc/impl/TypeMappingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ private static <T, U> void verifyTypeMapping(
543543
awaitUpdate(asList(1,1), connection.createStatement(
544544
"INSERT INTO "+table+"(javaValue) VALUES(:javaValue)")
545545
.bind("javaValue", javaValue).add()
546-
.bindNull("javaValue", javaValue.getClass()).add());
546+
.bindNull("javaValue", javaValue.getClass()));
547547

548548
verifyEquals.accept(javaValue,
549549
awaitOne(Flux.from(connection.createStatement(

src/test/java/oracle/r2dbc/test/OracleTestKit.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import io.r2dbc.spi.ConnectionFactories;
2929
import io.r2dbc.spi.ConnectionFactory;
3030
import io.r2dbc.spi.ConnectionFactoryOptions;
31+
import io.r2dbc.spi.R2dbcNonTransientException;
3132
import io.r2dbc.spi.Result;
3233
import io.r2dbc.spi.Row;
3334
import io.r2dbc.spi.Statement;
@@ -269,7 +270,7 @@ public void duplicateColumnNames() {
269270
* segments from a single {@code Result}. The default implementation expects
270271
* 10 {@code Result}s each with a single {@code UpdateCount}. Batch DML
271272
* execution is a single call to Oracle Database, and so Oracle R2DBC
272-
* returns a signle {@code Result}
273+
* returns a single {@code Result}
273274
* </p>
274275
*/
275276
@Override
@@ -280,8 +281,17 @@ public void prepareStatement() {
280281
Statement statement = connection.createStatement(expand(TestStatement.INSERT_VALUE_PLACEHOLDER, getPlaceholder(0)));
281282

282283
IntStream.range(0, 10)
283-
.forEach(i -> TestKit.bind(statement, getIdentifier(0), i).add());
284+
.forEach(i -> {
285+
TestKit.bind(statement, getIdentifier(0), i);
284286

287+
if (i != 9) {
288+
statement.add();
289+
}
290+
});
291+
292+
// The original TestKit implementation is modified below to call
293+
// Result.getRowsUpdated(), which returns a Publisher of 10
294+
// UpdateCount segments.
285295
return Flux.from(statement
286296
.execute())
287297
.flatMap(Result::getRowsUpdated);

0 commit comments

Comments
 (0)