Skip to content

Commit ae30a68

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 a01cb1a commit ae30a68

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
@@ -2279,6 +2279,31 @@ default <T> Uni<T> withStatelessTransaction(Function<StatelessSession, Uni<T>> w
22792279
*/
22802280
Statistics getStatistics();
22812281

2282+
/**
2283+
* Return the current instance of {@link Session}, if any.
2284+
* A current session exists only when this method is called
2285+
* from within an invocation of {@link #withSession(Function)}
2286+
* or {@link #withTransaction(Function)}.
2287+
*
2288+
* @return the current instance, if any, or {@code null}
2289+
*
2290+
* @since 2.4.7
2291+
*/
2292+
Session getCurrentSession();
2293+
2294+
/**
2295+
* Return the current instance of {@link Session}, if any.
2296+
* A current session exists only when this method is called
2297+
* from within an invocation of
2298+
* {@link #withStatelessSession(Function)} or
2299+
* {@link #withStatelessTransaction(Function)}.
2300+
*
2301+
* @return the current instance, if any, or {@code null}
2302+
*
2303+
* @since 2.4.7
2304+
*/
2305+
StatelessSession getCurrentStatelessSession();
2306+
22822307
/**
22832308
* Destroy the session factory and clean up its connection pool.
22842309
*/

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
@@ -2314,6 +2314,31 @@ default <T> CompletionStage<T> withStatelessTransaction(Function<StatelessSessio
23142314
*/
23152315
Statistics getStatistics();
23162316

2317+
/**
2318+
* Return the current instance of {@link Session}, if any.
2319+
* A current session exists only when this method is called
2320+
* from within an invocation of {@link #withSession(Function)}
2321+
* or {@link #withTransaction(Function)}.
2322+
*
2323+
* @return the current instance, if any, or {@code null}
2324+
*
2325+
* @since 2.4.7
2326+
*/
2327+
Session getCurrentSession();
2328+
2329+
/**
2330+
* Return the current instance of {@link Session}, if any.
2331+
* A current session exists only when this method is called
2332+
* from within an invocation of
2333+
* {@link #withStatelessSession(Function)} or
2334+
* {@link #withStatelessTransaction(Function)}.
2335+
*
2336+
* @return the current instance, if any, or {@code null}
2337+
*
2338+
* @since 2.4.7
2339+
*/
2340+
StatelessSession getCurrentStatelessSession();
2341+
23172342
/**
23182343
* Destroy the session factory and clean up its connection pool.
23192344
*/

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)