Skip to content

Commit 02db560

Browse files
committed
[#2207] Provide access to the contextual data map
We store the session in the Vert.x local context. But, Quarkus needs a way to access the same context when using Panache. See quarkus issue: quarkusio/quarkus#47314
1 parent 5adf123 commit 02db560

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl/ContextualDataStorage.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
package org.hibernate.reactive.context.impl;
77

8+
import org.hibernate.reactive.context.Context;
9+
10+
import io.vertx.core.impl.ContextInternal;
11+
import io.vertx.core.spi.context.storage.AccessMode;
12+
import java.util.Map;
13+
import java.util.concurrent.ConcurrentHashMap;
814
import java.util.concurrent.ConcurrentMap;
915

1016
import io.vertx.core.impl.VertxBuilder;
@@ -17,9 +23,18 @@
1723
public class ContextualDataStorage implements VertxServiceProvider {
1824

1925
@SuppressWarnings("rawtypes")
20-
final static ContextLocal<ConcurrentMap> CONTEXTUAL_DATA_KEY = ContextLocal.registerLocal( ConcurrentMap.class );
26+
private final static ContextLocal<ConcurrentMap> CONTEXTUAL_DATA_KEY = ContextLocal.registerLocal( ConcurrentMap.class );
2127

2228
@Override
2329
public void init(VertxBuilder vertxBuilder) {
2430
}
31+
32+
@SuppressWarnings({ "unchecked" })
33+
public static <T> Map<Context.Key<T>, T> contextualDataMap(ContextInternal vertxContext) {
34+
return vertxContext.getLocal(
35+
ContextualDataStorage.CONTEXTUAL_DATA_KEY,
36+
AccessMode.CONCURRENT,
37+
ConcurrentHashMap::new
38+
);
39+
}
2540
}

hibernate-reactive-core/src/main/java/org/hibernate/reactive/context/impl/VertxContext.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66
package org.hibernate.reactive.context.impl;
77

88
import java.lang.invoke.MethodHandles;
9-
import java.util.concurrent.ConcurrentHashMap;
10-
import java.util.concurrent.ConcurrentMap;
119

1210
import io.vertx.core.Vertx;
1311
import io.vertx.core.impl.ContextInternal;
14-
import io.vertx.core.spi.context.storage.AccessMode;
1512

1613
import org.hibernate.reactive.context.Context;
1714
import org.hibernate.reactive.logging.impl.Log;
@@ -20,6 +17,8 @@
2017
import org.hibernate.service.spi.ServiceRegistryAwareService;
2118
import org.hibernate.service.spi.ServiceRegistryImplementor;
2219

20+
import static org.hibernate.reactive.context.impl.ContextualDataStorage.contextualDataMap;
21+
2322
/**
2423
* An adaptor for the Vert.x {@link io.vertx.core.Context}.
2524
*
@@ -42,7 +41,7 @@ public <T> void put(Key<T> key, T instance) {
4241
final ContextInternal context = ContextInternal.current();
4342
if ( context != null ) {
4443
if ( trace ) LOG.tracef( "Putting key,value in context: [%1$s, %2$s]", key, instance );
45-
VertxContext.<T>contextualDataMap( context ).put( key, instance );
44+
ContextualDataStorage.<T>contextualDataMap( context ).put( key, instance );
4645
}
4746
else {
4847
if ( trace ) LOG.tracef( "Context is null for key,value: [%1$s, %2$s]", key, instance );
@@ -54,7 +53,7 @@ public <T> void put(Key<T> key, T instance) {
5453
public <T> T get(Key<T> key) {
5554
final ContextInternal context = ContextInternal.current();
5655
if ( context != null ) {
57-
T local = VertxContext.<T>contextualDataMap( context ).get( key );
56+
T local = ContextualDataStorage.<T>contextualDataMap( context ).get( key );
5857
if ( trace ) LOG.tracef( "Getting value %2$s from context for key %1$s", key, local );
5958
return local;
6059
}
@@ -94,13 +93,4 @@ public void execute(Runnable runnable) {
9493
runnable.run();
9594
}
9695
}
97-
98-
@SuppressWarnings({ "unchecked" })
99-
private static <T> ConcurrentMap<Key<T>, T> contextualDataMap(ContextInternal vertxContext) {
100-
return vertxContext.getLocal(
101-
ContextualDataStorage.CONTEXTUAL_DATA_KEY,
102-
AccessMode.CONCURRENT,
103-
ConcurrentHashMap::new
104-
);
105-
}
10696
}

0 commit comments

Comments
 (0)