Skip to content

Commit b2be07c

Browse files
committed
Polishing
1 parent ce2689e commit b2be07c

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed

framework-docs/src/docs/asciidoc/data-access.adoc

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,26 +1030,28 @@ marks a transaction for rollback only in the case of runtime, unchecked exceptio
10301030
That is, when the thrown exception is an instance or subclass of `RuntimeException`.
10311031
(`Error` instances also, by default, result in a rollback).
10321032

1033-
However, starting with Spring Framework 5.2.0 the default configuration also provides support for Vavr's `Try` method to trigger transaction rollbacks when it returns a 'Failure'. This allows you to handle functional-style errors using Try and have the transaction automatically rolled back in case of a failure.
1033+
As of Spring Framework 5.2, the default configuration also provides support for
1034+
Vavr's `Try` method to trigger transaction rollbacks when it returns a 'Failure'.
1035+
This allows you to handle functional-style errors using Try and have the transaction
1036+
automatically rolled back in case of a failure. For more information on Vavr's Try,
1037+
refer to the [official Vavr documentation](https://www.vavr.io/vavr-docs/#_try).
10341038

1035-
Here's an example of how to use Vavr's Try:
1039+
Here's an example of how to use Vavr's Try with a transactional method:
10361040
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
10371041
.Java
10381042
----
1039-
@Transactional
1040-
public Try<String> myTransactionalMethod() {
1041-
// If transactionMethod throws an exception, it will be caught by the Try instance created with Try.of() and wrapped inside the Failure class, which can be checked using the isFailure() method on the Try instance.
1042-
return Try.of(serviceA::transactionalMethod);
1043-
}
1043+
@Transactional
1044+
public Try<String> myTransactionalMethod() {
1045+
// If myDataAccessOperation throws an exception, it will be caught by the
1046+
// Try instance created with Try.of() and wrapped inside the Failure class
1047+
// which can be checked using the isFailure() method on the Try instance.
1048+
return Try.of(delegate::myDataAccessOperation);
1049+
}
10441050
----
1045-
For more information on Vavr's Try, refer to the [official Vavr documentation](https://www.vavr.io/vavr-docs/#_try).
1046-
1047-
Checked exceptions that are
1048-
thrown from a transactional method do not result in rollback in the default
1049-
configuration.
10501051

1051-
You can configure exactly which `Exception` types mark a transaction for rollback,
1052-
including checked exceptions by specifying _rollback rules_.
1052+
Checked exceptions that are thrown from a transactional method do not result in a rollback
1053+
in the default configuration. You can configure exactly which `Exception` types mark a
1054+
transaction for rollback, including checked exceptions by specifying _rollback rules_.
10531055

10541056
.Rollback rules
10551057
[[transaction-declarative-rollback-rules]]

spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -281,11 +281,11 @@ public ScheduledFuture<?> schedule(Runnable task, Trigger trigger) {
281281
return executor.schedule(task, new TriggerAdapter(trigger));
282282
}
283283

284+
284285
private static class TriggerAdapter implements jakarta.enterprise.concurrent.Trigger {
285286

286287
private final Trigger adaptee;
287288

288-
289289
public TriggerAdapter(Trigger adaptee) {
290290
this.adaptee = adaptee;
291291
}
@@ -294,48 +294,45 @@ public TriggerAdapter(Trigger adaptee) {
294294
@Nullable
295295
public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) {
296296
Instant instant = this.adaptee.nextExecution(new LastExecutionAdapter(le));
297-
return instant != null ? Date.from(instant) : null;
297+
return (instant != null ? Date.from(instant) : null);
298298
}
299299

300-
@Nullable
301-
private static Instant toInstant(@Nullable Date date) {
302-
return date != null ? date.toInstant() : null;
303-
}
304-
305-
306300
@Override
307301
public boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) {
308302
return false;
309303
}
310304

305+
311306
private static class LastExecutionAdapter implements TriggerContext {
312307

313308
@Nullable
314309
private final LastExecution le;
315310

316-
317311
public LastExecutionAdapter(@Nullable LastExecution le) {
318312
this.le = le;
319313
}
320314

321315
@Override
322316
public Instant lastScheduledExecution() {
323-
return (this.le != null) ? toInstant(this.le.getScheduledStart()) : null;
317+
return (this.le != null ? toInstant(this.le.getScheduledStart()) : null);
324318
}
325319

326320
@Override
327321
public Instant lastActualExecution() {
328-
return (this.le != null) ? toInstant(this.le.getRunStart()) : null;
322+
return (this.le != null ? toInstant(this.le.getRunStart()) : null);
329323
}
330324

331325
@Override
332326
public Instant lastCompletion() {
333-
return (this.le != null) ? toInstant(this.le.getRunEnd()) : null;
327+
return (this.le != null ? toInstant(this.le.getRunEnd()) : null);
328+
}
329+
330+
@Nullable
331+
private static Instant toInstant(@Nullable Date date) {
332+
return (date != null ? date.toInstant() : null);
334333
}
335334
}
336335
}
337-
338-
339336
}
340337

341338
}

0 commit comments

Comments
 (0)