Skip to content

Commit a29061e

Browse files
committed
[#36582] Minor clean up around lambdas
1 parent b44a56c commit a29061e

File tree

2 files changed

+6
-10
lines changed
  • extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime
  • test-framework/hibernate-reactive-panache/src/main/java/io/quarkus/test/hibernate/reactive/panache

2 files changed

+6
-10
lines changed

extensions/panache/hibernate-reactive-panache-common/runtime/src/main/java/io/quarkus/hibernate/reactive/panache/common/runtime/SessionOperations.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,7 @@ static <T> Uni<T> withSessionOnDemand(Supplier<Uni<T>> work) {
8585
* @return a new {@link Uni}
8686
*/
8787
public static <T> Uni<T> withTransaction(Supplier<Uni<T>> work) {
88-
return withSession(s -> {
89-
return s.withTransaction(t -> work.get());
90-
});
88+
return withSession(s -> s.withTransaction(t -> work.get()));
9189
}
9290

9391
/**
@@ -98,9 +96,7 @@ public static <T> Uni<T> withTransaction(Supplier<Uni<T>> work) {
9896
* @return a new {@link Uni}
9997
*/
10098
public static <T> Uni<T> withTransaction(Function<Transaction, Uni<T>> work) {
101-
return withSession(s -> {
102-
return s.withTransaction(t -> work.apply(t));
103-
});
99+
return withSession(s -> s.withTransaction(work));
104100
}
105101

106102
/**
@@ -122,8 +118,8 @@ public static <T> Uni<T> withSession(Function<Mutiny.Session, Uni<T>> work) {
122118
return getSessionFactory()
123119
.openSession()
124120
.invoke(s -> context.putLocal(key, s))
125-
.chain(s -> work.apply(s))
126-
.eventually(() -> closeSession());
121+
.chain(work::apply)
122+
.eventually(SessionOperations::closeSession);
127123
}
128124
}
129125

@@ -152,7 +148,7 @@ public static Uni<Mutiny.Session> getSession() {
152148
if (context.getLocal(SESSION_ON_DEMAND_KEY) != null) {
153149
if (context.getLocal(SESSION_ON_DEMAND_OPENED_KEY) != null) {
154150
// a new reactive session is opened in a previous stage
155-
return Uni.createFrom().item(() -> getCurrentSession());
151+
return Uni.createFrom().item(SessionOperations::getCurrentSession);
156152
} else {
157153
// open a new reactive session and store it in the vertx duplicated context
158154
// the context was marked as "lazy" which means that the session will be eventually closed

test-framework/hibernate-reactive-panache/src/main/java/io/quarkus/test/hibernate/reactive/panache/TransactionalUniAsserter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class TransactionalUniAsserter extends UniAsserterInterceptor {
2020

2121
@Override
2222
protected <T> Supplier<Uni<T>> transformUni(Supplier<Uni<T>> uniSupplier) {
23-
return () -> SessionOperations.withTransaction(() -> uniSupplier.get());
23+
return () -> SessionOperations.withTransaction(uniSupplier);
2424
}
2525

2626
}

0 commit comments

Comments
 (0)