Skip to content

Commit 08bc7ed

Browse files
committed
Polishing
1 parent 2ce75dc commit 08bc7ed

File tree

4 files changed

+36
-47
lines changed

4 files changed

+36
-47
lines changed

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,6 @@ private record ExtendedTransactionDefinition(@Nullable String transactionName,
433433
boolean readOnly, @Nullable IsolationLevel isolationLevel, Duration lockWaitTimeout)
434434
implements io.r2dbc.spi.TransactionDefinition {
435435

436-
private ExtendedTransactionDefinition(@Nullable String transactionName, boolean readOnly,
437-
@Nullable IsolationLevel isolationLevel, Duration lockWaitTimeout) {
438-
439-
this.transactionName = transactionName;
440-
this.readOnly = readOnly;
441-
this.isolationLevel = isolationLevel;
442-
this.lockWaitTimeout = lockWaitTimeout;
443-
}
444-
445436
@SuppressWarnings("unchecked")
446437
@Override
447438
public <T> T getAttribute(Option<T> option) {
@@ -459,16 +450,16 @@ private Object doGetValue(Option<?> option) {
459450
if (io.r2dbc.spi.TransactionDefinition.READ_ONLY.equals(option)) {
460451
return this.readOnly;
461452
}
462-
if (io.r2dbc.spi.TransactionDefinition.LOCK_WAIT_TIMEOUT.equals(option)
463-
&& !this.lockWaitTimeout.isZero()) {
453+
if (io.r2dbc.spi.TransactionDefinition.LOCK_WAIT_TIMEOUT.equals(option) &&
454+
!this.lockWaitTimeout.isZero()) {
464455
return this.lockWaitTimeout;
465456
}
466457
return null;
467458
}
468459

469460
@Override
470461
public String toString() {
471-
StringBuilder sb = new StringBuilder();
462+
StringBuilder sb = new StringBuilder(128);
472463
sb.append(getClass().getSimpleName());
473464
sb.append(" [transactionName='").append(this.transactionName).append('\'');
474465
sb.append(", readOnly=").append(this.readOnly);

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DatabaseClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ default GenericExecuteSpec filter(Function<? super Statement, ? extends Statemen
222222
* Configure a result mapping {@link Function function} and enter the execution stage.
223223
* @param mappingFunction a function that maps from {@link Readable} to the result type
224224
* @param <R> the result type
225-
* @return a {@link FetchSpec} for configuration what to fetch
225+
* @return a {@link RowsFetchSpec} for configuration what to fetch
226226
* @since 6.0
227227
*/
228228
<R> RowsFetchSpec<R> map(Function<? super Readable, R> mappingFunction);
@@ -232,12 +232,12 @@ default GenericExecuteSpec filter(Function<? super Statement, ? extends Statemen
232232
* @param mappingFunction a function that maps from {@link Row} and {@link RowMetadata}
233233
* to the result type
234234
* @param <R> the result type
235-
* @return a {@link FetchSpec} for configuration what to fetch
235+
* @return a {@link RowsFetchSpec} for configuration what to fetch
236236
*/
237237
<R> RowsFetchSpec<R> map(BiFunction<Row, RowMetadata, R> mappingFunction);
238238

239239
/**
240-
* Perform the SQL call and apply {@link BiFunction function} to the {@link Result}.
240+
* Perform the SQL call and apply {@link BiFunction function} to the {@link Result}.
241241
* @param mappingFunction a function that maps from {@link Result} into a result publisher
242242
* @param <R> the result type
243243
* @return a {@link Flux} that emits mapped elements

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -392,24 +392,20 @@ private ResultFunction getResultFunction(Supplier<String> sqlSupplier) {
392392
return statement;
393393
};
394394

395-
return new ResultFunction(sqlSupplier, statementFunction, this.filterFunction, DefaultDatabaseClient.this.executeFunction);
395+
return new ResultFunction(sqlSupplier, statementFunction, this.filterFunction,
396+
DefaultDatabaseClient.this.executeFunction);
396397
}
397398

398399
private <T> FetchSpec<T> execute(Supplier<String> sqlSupplier, Function<Result, Publisher<T>> resultAdapter) {
399400
ResultFunction resultHandler = getResultFunction(sqlSupplier);
400-
401-
return new DefaultFetchSpec<>(
402-
DefaultDatabaseClient.this,
403-
resultHandler,
404-
connection -> sumRowsUpdated(resultHandler, connection),
405-
resultAdapter);
401+
return new DefaultFetchSpec<>(DefaultDatabaseClient.this, resultHandler,
402+
connection -> sumRowsUpdated(resultHandler, connection), resultAdapter);
406403
}
407404

408405
private <T> Flux<T> flatMap(Supplier<String> sqlSupplier, Function<Result, Publisher<T>> mappingFunction) {
409406
ResultFunction resultHandler = getResultFunction(sqlSupplier);
410-
ConnectionFunction<Flux<T>> connectionFunction = new DelegateConnectionFunction<>(resultHandler, cx -> resultHandler
411-
.apply(cx)
412-
.flatMap(mappingFunction));
407+
ConnectionFunction<Flux<T>> connectionFunction = new DelegateConnectionFunction<>(resultHandler,
408+
cx -> resultHandler.apply(cx).flatMap(mappingFunction));
413409
return inConnectionMany(connectionFunction);
414410
}
415411

@@ -448,8 +444,7 @@ private Parameter getParameter(Map<String, Parameter> remainderByName,
448444

449445
private void assertNotPreparedOperation() {
450446
if (this.sqlSupplier instanceof PreparedOperation<?>) {
451-
throw new InvalidDataAccessApiUsageException(
452-
"Cannot add bindings to a PreparedOperation");
447+
throw new InvalidDataAccessApiUsageException("Cannot add bindings to a PreparedOperation");
453448
}
454449
}
455450

@@ -497,8 +492,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
497492
return this.target;
498493
case "close":
499494
// Handle close method: suppress, not valid.
500-
return Mono.error(
501-
new UnsupportedOperationException("Close is not supported!"));
495+
return Mono.error(new UnsupportedOperationException("Close is not supported!"));
502496
}
503497

504498
// Invoke method on target Connection.

spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientUnitTests.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void shouldCloseConnectionOnlyOnce() {
103103
DefaultDatabaseClient databaseClient = (DefaultDatabaseClient) databaseClientBuilder.build();
104104
Flux<Object> flux = databaseClient.inConnectionMany(connection -> Flux.empty());
105105

106-
flux.subscribe(new CoreSubscriber<Object>() {
106+
flux.subscribe(new CoreSubscriber<>() {
107107

108108
Subscription subscription;
109109

@@ -136,13 +136,15 @@ void executeShouldBindNullValues() {
136136

137137
DatabaseClient databaseClient = databaseClientBuilder.namedParameters(false).build();
138138

139-
databaseClient.sql("SELECT * FROM table WHERE key = $1").bindNull(0,
140-
String.class).then().as(StepVerifier::create).verifyComplete();
139+
databaseClient.sql("SELECT * FROM table WHERE key = $1")
140+
.bindNull(0, String.class)
141+
.then().as(StepVerifier::create).verifyComplete();
141142

142143
verify(statement).bind(0, Parameters.in(String.class));
143144

144-
databaseClient.sql("SELECT * FROM table WHERE key = $1").bindNull("$1",
145-
String.class).then().as(StepVerifier::create).verifyComplete();
145+
databaseClient.sql("SELECT * FROM table WHERE key = $1")
146+
.bindNull("$1", String.class)
147+
.then().as(StepVerifier::create).verifyComplete();
146148

147149
verify(statement).bind("$1", Parameters.in(String.class));
148150
}
@@ -153,15 +155,15 @@ void executeShouldBindSettableValues() {
153155
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
154156
DatabaseClient databaseClient = databaseClientBuilder.namedParameters(false).build();
155157

156-
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind(0,
157-
Parameter.empty(String.class)).then().as(
158-
StepVerifier::create).verifyComplete();
158+
databaseClient.sql("SELECT * FROM table WHERE key = $1")
159+
.bind(0, Parameter.empty(String.class))
160+
.then().as(StepVerifier::create).verifyComplete();
159161

160162
verify(statement).bind(0, Parameters.in(String.class));
161163

162-
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind("$1",
163-
Parameter.empty(String.class)).then().as(
164-
StepVerifier::create).verifyComplete();
164+
databaseClient.sql("SELECT * FROM table WHERE key = $1")
165+
.bind("$1", Parameter.empty(String.class))
166+
.then().as(StepVerifier::create).verifyComplete();
165167

166168
verify(statement).bind("$1", Parameters.in(String.class));
167169
}
@@ -171,8 +173,9 @@ void executeShouldBindNamedNullValues() {
171173
Statement statement = mockStatementFor("SELECT * FROM table WHERE key = $1");
172174
DatabaseClient databaseClient = databaseClientBuilder.build();
173175

174-
databaseClient.sql("SELECT * FROM table WHERE key = :key").bindNull("key",
175-
String.class).then().as(StepVerifier::create).verifyComplete();
176+
databaseClient.sql("SELECT * FROM table WHERE key = :key")
177+
.bindNull("key", String.class)
178+
.then().as(StepVerifier::create).verifyComplete();
176179

177180
verify(statement).bind(0, Parameters.in(String.class));
178181
}
@@ -185,9 +188,9 @@ void executeShouldBindNamedValuesFromIndexes() {
185188
DatabaseClient databaseClient = databaseClientBuilder.build();
186189

187190
databaseClient.sql(
188-
"SELECT id, name, manual FROM legoset WHERE name IN (:name)").bind(0,
189-
Arrays.asList("unknown", "dunno", "other")).then().as(
190-
StepVerifier::create).verifyComplete();
191+
"SELECT id, name, manual FROM legoset WHERE name IN (:name)")
192+
.bind(0, Arrays.asList("unknown", "dunno", "other"))
193+
.then().as(StepVerifier::create).verifyComplete();
191194

192195
verify(statement).bind(0, "unknown");
193196
verify(statement).bind(1, "dunno");
@@ -207,8 +210,9 @@ void executeShouldBindValues() {
207210

208211
verify(statement).bind(0, Parameters.in("foo"));
209212

210-
databaseClient.sql("SELECT * FROM table WHERE key = $1").bind("$1",
211-
"foo").then().as(StepVerifier::create).verifyComplete();
213+
databaseClient.sql("SELECT * FROM table WHERE key = $1")
214+
.bind("$1", "foo")
215+
.then().as(StepVerifier::create).verifyComplete();
212216

213217
verify(statement).bind("$1", Parameters.in("foo"));
214218
}

0 commit comments

Comments
 (0)