Skip to content

Commit 72106db

Browse files
committed
[#1780] add operations for obtaining the current sessions from the context
this will make it easier to implement the necessary Quarkus integration
1 parent 8248d08 commit 72106db

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/Mutiny.java

+25
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,31 @@ default <T> Uni<T> withStatelessTransaction(Function<StatelessSession, Uni<T>> w
22692269
*/
22702270
Statistics getStatistics();
22712271

2272+
/**
2273+
* Return the current instance of {@link Session}, if any.
2274+
* A current session exists only when this method is called
2275+
* from within an invocation of {@link #withSession(Function)}
2276+
* or {@link #withTransaction(Function)}.
2277+
*
2278+
* @return the current instance, if any, or {@code null}
2279+
*
2280+
* @since 3.0
2281+
*/
2282+
Session getCurrentSession();
2283+
2284+
/**
2285+
* Return the current instance of {@link Session}, if any.
2286+
* A current session exists only when this method is called
2287+
* from within an invocation of
2288+
* {@link #withStatelessSession(Function)} or
2289+
* {@link #withStatelessTransaction(Function)}.
2290+
*
2291+
* @return the current instance, if any, or {@code null}
2292+
*
2293+
* @since 3.0
2294+
*/
2295+
StatelessSession getCurrentStatelessSession();
2296+
22722297
/**
22732298
* Destroy the session factory and clean up its connection pool.
22742299
*/

hibernate-reactive-core/src/main/java/org/hibernate/reactive/mutiny/impl/MutinySessionFactoryImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,16 @@ private CompletionStage<ReactiveConnection> connection(String tenantId) {
148148
: connectionPool.getConnection( tenantId );
149149
}
150150

151+
@Override
152+
public Mutiny.Session getCurrentSession() {
153+
return context.get( contextKeyForSession );
154+
}
155+
156+
@Override
157+
public Mutiny.StatelessSession getCurrentStatelessSession() {
158+
return context.get( contextKeyForStatelessSession );
159+
}
160+
151161
@Override
152162
public <T> Uni<T> withSession(Function<Mutiny.Session, Uni<T>> work) {
153163
Objects.requireNonNull( work, "parameter 'work' is required" );

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/Stage.java

+25
Original file line numberDiff line numberDiff line change
@@ -2273,6 +2273,31 @@ default <T> CompletionStage<T> withStatelessTransaction(Function<StatelessSessio
22732273
*/
22742274
Statistics getStatistics();
22752275

2276+
/**
2277+
* Return the current instance of {@link Session}, if any.
2278+
* A current session exists only when this method is called
2279+
* from within an invocation of {@link #withSession(Function)}
2280+
* or {@link #withTransaction(Function)}.
2281+
*
2282+
* @return the current instance, if any, or {@code null}
2283+
*
2284+
* @since 3.0
2285+
*/
2286+
Session getCurrentSession();
2287+
2288+
/**
2289+
* Return the current instance of {@link Session}, if any.
2290+
* A current session exists only when this method is called
2291+
* from within an invocation of
2292+
* {@link #withStatelessSession(Function)} or
2293+
* {@link #withStatelessTransaction(Function)}.
2294+
*
2295+
* @return the current instance, if any, or {@code null}
2296+
*
2297+
* @since 3.0
2298+
*/
2299+
StatelessSession getCurrentStatelessSession();
2300+
22762301
/**
22772302
* Destroy the session factory and clean up its connection pool.
22782303
*/

hibernate-reactive-core/src/main/java/org/hibernate/reactive/stage/impl/StageSessionFactoryImpl.java

+10
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ private CompletionStage<ReactiveConnection> connection(String tenantId) {
138138
: connectionPool.getConnection( tenantId );
139139
}
140140

141+
@Override
142+
public Stage.Session getCurrentSession() {
143+
return context.get( contextKeyForSession );
144+
}
145+
146+
@Override
147+
public Stage.StatelessSession getCurrentStatelessSession() {
148+
return context.get( contextKeyForStatelessSession );
149+
}
150+
141151
@Override
142152
public <T> CompletionStage<T> withSession(Function<Stage.Session, CompletionStage<T>> work) {
143153
Objects.requireNonNull( work, "parameter 'work' is required" );

0 commit comments

Comments
 (0)