Skip to content

Commit d24c1bd

Browse files
Merge pull request #14 from oracle/11_non_empty_update_count
11 Result.getRowsUpdated() Emits 0
2 parents a4c8dc4 + 718f733 commit d24c1bd

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,21 @@ private OracleResultImpl() { }
6868

6969
/**
7070
* Creates a {@code Result} that publishes either an empty stream of row
71-
* data, or publishes an {@code updateCount} if it is greater than zero. An
72-
* {@code updateCount} less than 1 is published as an empty stream.
71+
* data, or publishes an {@code updateCount} if it is greater than or equal
72+
* to zero. An {@code updateCount} less than zero is published as an empty
73+
* stream.
7374
* @param updateCount Update count to publish
7475
* @return An update count {@code Result}
7576
*/
7677
public static Result createUpdateCountResult(int updateCount) {
7778
return new OracleResultImpl() {
7879

80+
final Publisher<Integer> updateCountPublisher =
81+
updateCount < 0 ? Mono.empty() : Mono.just(updateCount);
82+
7983
@Override
8084
Publisher<Integer> publishUpdateCount() {
81-
return updateCount < 1 ? Mono.empty() : Mono.just(updateCount);
85+
return updateCountPublisher;
8286
}
8387

8488
@Override

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,21 @@ public void testGetRowsUpdated() {
9898
// Expect update count publisher to support multiple subscribers
9999
awaitOne(1, insertCountPublisher1);
100100

101-
// Expect no update count from UPDATE of zero rows
101+
// Expect an update count of zero from UPDATE of zero rows
102102
Result noUpdateResult = awaitOne(connection.createStatement(
103103
"UPDATE testGetRowsUpdated SET y = 99 WHERE x = 99")
104104
.execute());
105105
Publisher<Integer> noUpdateCountPublisher =
106106
noUpdateResult.getRowsUpdated();
107-
awaitNone(noUpdateCountPublisher);
107+
awaitOne(0, noUpdateCountPublisher);
108108

109109
// Expect IllegalStateException from multiple Result consumptions.
110110
assertThrows(IllegalStateException.class,
111111
() -> noUpdateResult.map((row, metadata) -> "unexpected"));
112112
assertThrows(IllegalStateException.class, noUpdateResult::getRowsUpdated);
113113

114114
// Expect update count publisher to support multiple subscribers
115-
awaitNone(noUpdateCountPublisher);
115+
awaitOne(0, noUpdateCountPublisher);
116116

117117
// Expect update count of 2 from UPDATE of 2 rows
118118
Result updateResult = awaitOne(connection.createStatement(

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,11 +811,9 @@ public void testExecute() {
811811
Connection connection =
812812
Mono.from(sharedConnection()).block(connectTimeout());
813813
try {
814-
// Expect DDL to result in no update count
815-
awaitUpdate(
816-
Collections.emptyList(),
817-
connection.createStatement(
818-
"CREATE TABLE testExecute (x NUMBER)"));
814+
// Expect DDL to result in an update count of zero
815+
awaitUpdate(0, connection.createStatement(
816+
"CREATE TABLE testExecute (x NUMBER)"));
819817
// Expect DDL to result in no row data
820818
awaitQuery(
821819
Collections.emptyList(),

src/test/java/oracle/r2dbc/util/Awaits.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,12 @@ public static <T> List<T> awaitMany(Publisher<T> multiPublisher) {
132132
/**
133133
* Executes a {@code statement} and blocks until the execution
134134
* completes. This method verifies that the execution produces a
135-
* {@link Result} with no count of updated rows.
136-
* @param statement A statement that does not update rows.
135+
* {@link Result} with a count of zero updated rows.
136+
* @param statement A statement that does updates zero rows.
137137
* @throws Throwable If the statement execution results in an error.
138138
*/
139139
public static void awaitExecution(Statement statement) {
140-
assertNull(
141-
Mono.from(statement.execute())
142-
.flatMap(result -> Mono.from(result.getRowsUpdated()))
143-
.block(sqlTimeout()),
144-
"Expected no update count when not updating rows");
140+
awaitUpdate(0, statement);
145141
}
146142

147143
/**

0 commit comments

Comments
 (0)