Skip to content

Commit 98b3e22

Browse files
committed
use safe casts
1 parent c8bc1f6 commit 98b3e22

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.hibernate.LockMode;
1919
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
2020
import org.hibernate.collection.spi.AbstractPersistentCollection;
21-
import org.hibernate.collection.spi.PersistentCollection;
2221
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
2322
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
2423
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@@ -2452,18 +2451,18 @@ static <T> Uni<T> fetch(T association) {
24522451
}
24532452

24542453
final SharedSessionContractImplementor session;
2455-
if ( association instanceof HibernateProxy ) {
2456-
session = ( (HibernateProxy) association ).getHibernateLazyInitializer().getSession();
2454+
if ( association instanceof HibernateProxy proxy ) {
2455+
session = proxy.getHibernateLazyInitializer().getSession();
24572456
}
2458-
else if ( association instanceof PersistentCollection ) {
2457+
else if ( association instanceof AbstractPersistentCollection<?> collection ) {
24592458
//this unfortunately doesn't work for stateless session because the session ref gets set to null
2460-
session = ( (AbstractPersistentCollection<?>) association ).getSession();
2459+
session = collection.getSession();
24612460
}
24622461
else if ( isPersistentAttributeInterceptable( association ) ) {
24632462
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( association );
24642463
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
2465-
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) {
2466-
session = ( (EnhancementAsProxyLazinessInterceptor) interceptor ).getLinkedSession();
2464+
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor ) {
2465+
session = lazinessInterceptor.getLinkedSession();
24672466
}
24682467
else {
24692468
return Uni.createFrom().item( association );

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.hibernate.LockMode;
2020
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
2121
import org.hibernate.collection.spi.AbstractPersistentCollection;
22-
import org.hibernate.collection.spi.PersistentCollection;
2322
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
2423
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
2524
import org.hibernate.engine.spi.SharedSessionContractImplementor;
@@ -2499,17 +2498,17 @@ static <T> CompletionStage<T> fetch(T association) {
24992498
}
25002499

25012500
final SharedSessionContractImplementor session;
2502-
if ( association instanceof HibernateProxy) {
2503-
session = ( (HibernateProxy) association ).getHibernateLazyInitializer().getSession();
2501+
if ( association instanceof HibernateProxy proxy ) {
2502+
session = proxy.getHibernateLazyInitializer().getSession();
25042503
}
2505-
else if ( association instanceof PersistentCollection) {
2506-
session = ( (AbstractPersistentCollection<?>) association ).getSession();
2504+
else if ( association instanceof AbstractPersistentCollection<?> collection ) {
2505+
session = collection.getSession();
25072506
}
25082507
else if ( isPersistentAttributeInterceptable( association ) ) {
25092508
final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( association );
25102509
final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor();
2511-
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor) {
2512-
session = ( (EnhancementAsProxyLazinessInterceptor) interceptor ).getLinkedSession();
2510+
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor lazinessInterceptor) {
2511+
session = lazinessInterceptor.getLinkedSession();
25132512
}
25142513
else {
25152514
return CompletionStages.completedFuture( association );

0 commit comments

Comments
 (0)