Skip to content

Commit

Permalink
[quarkusio#36582] Minor clean up around lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideD committed Nov 2, 2023
1 parent b44a56c commit a29061e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ static <T> Uni<T> withSessionOnDemand(Supplier<Uni<T>> work) {
* @return a new {@link Uni}
*/
public static <T> Uni<T> withTransaction(Supplier<Uni<T>> work) {
return withSession(s -> {
return s.withTransaction(t -> work.get());
});
return withSession(s -> s.withTransaction(t -> work.get()));
}

/**
Expand All @@ -98,9 +96,7 @@ public static <T> Uni<T> withTransaction(Supplier<Uni<T>> work) {
* @return a new {@link Uni}
*/
public static <T> Uni<T> withTransaction(Function<Transaction, Uni<T>> work) {
return withSession(s -> {
return s.withTransaction(t -> work.apply(t));
});
return withSession(s -> s.withTransaction(work));
}

/**
Expand All @@ -122,8 +118,8 @@ public static <T> Uni<T> withSession(Function<Mutiny.Session, Uni<T>> work) {
return getSessionFactory()
.openSession()
.invoke(s -> context.putLocal(key, s))
.chain(s -> work.apply(s))
.eventually(() -> closeSession());
.chain(work::apply)
.eventually(SessionOperations::closeSession);
}
}

Expand Down Expand Up @@ -152,7 +148,7 @@ public static Uni<Mutiny.Session> getSession() {
if (context.getLocal(SESSION_ON_DEMAND_KEY) != null) {
if (context.getLocal(SESSION_ON_DEMAND_OPENED_KEY) != null) {
// a new reactive session is opened in a previous stage
return Uni.createFrom().item(() -> getCurrentSession());
return Uni.createFrom().item(SessionOperations::getCurrentSession);
} else {
// open a new reactive session and store it in the vertx duplicated context
// the context was marked as "lazy" which means that the session will be eventually closed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class TransactionalUniAsserter extends UniAsserterInterceptor {

@Override
protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) {
return () -> SessionOperations.withTransaction(() -> uniSupplier.get());
return () -> SessionOperations.withTransaction(uniSupplier);
}

}

0 comments on commit a29061e

Please sign in to comment.