Skip to content

Commit 6227d96

Browse files
committed
#75 - Polishing.
Clarified code a little. Added a warning to `AnonymousBindMarkers`: Anonymous bind markers are problematic because the have to appear in generated SQL in the same order they get generated. This might cause challenges in the future with complex generate statements. For example those containing subselects which limit the freedom of arranging bind markers. Original pull request: #84.
1 parent c9435c8 commit 6227d96

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/main/java/org/springframework/data/r2dbc/dialect/AnonymousBindMarkers.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@
2121
* Anonymous, index-based bind marker using a static placeholder. Instances are bound by the ordinal position ordered by
2222
* the appearance of the placeholder. This implementation creates indexed bind markers using an anonymous placeholder
2323
* that correlates with an index.
24+
* <p>
25+
* Note: Anonymous bind markers are problematic because the have to appear in generated SQL in the same order they get generated.
26+
*
27+
* This might cause challenges in the future with complex generate statements.
28+
* For example those containing subselects which limit the freedom of arranging bind markers.
29+
* </p>
2430
*
2531
* @author Mark Paluch
2632
*/

src/test/java/org/springframework/data/r2dbc/function/AbstractTransactionalDatabaseClientIntegrationTests.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -209,21 +209,27 @@ public void emitTransactionIds() {
209209

210210
Flux<Object> transactionIds = databaseClient.inTransaction(db -> {
211211

212+
// We have to execute a sql statement first.
213+
// Otherwise some databases (MySql) don't have a transaction id.
212214
Mono<Integer> insert = db.execute().sql(getInsertIntoLegosetStatement()) //
213215
.bind(0, 42055) //
214216
.bind(1, "SCHAUFELRADBAGGER") //
215217
.bindNull(2, Integer.class) //
216218
.fetch().rowsUpdated();
217219

218-
Flux<Object> txId = db.execute().sql(getCurrentTransactionIdStatement()).map((r, md) -> r.get(0)).all();
220+
Flux<Object> txId = db.execute() //
221+
.sql(getCurrentTransactionIdStatement()) //
222+
.map((row, md) -> row.get(0)) //
223+
.all();
224+
219225
return insert.thenMany(txId.concatWith(txId));
220226
});
221227

222228
transactionIds.collectList().as(StepVerifier::create) //
223229
.consumeNextWith(actual -> {
224230

225231
assertThat(actual).hasSize(2);
226-
assertThat(actual).containsExactly(actual.get(1), actual.get(0));
232+
assertThat(actual.get(0)).isEqualTo(actual.get(1));
227233
}) //
228234
.verifyComplete();
229235
}

0 commit comments

Comments
 (0)