From 8f8ae50e0b278b85000451bde91ba746f22e43d9 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Tue, 25 Jan 2022 22:30:32 +0100 Subject: [PATCH] remove deprecated ExtendedBeanManager --- .../event/spi/jpa/ExtendedBeanManager.java | 44 ------------------- .../internal/CdiBeanContainerBuilder.java | 9 ++-- .../ContainerManagedLifecycleStrategy.java | 3 +- .../JpaCompliantLifecycleStrategy.java | 4 +- .../resource/beans/internal/Helper.java | 13 +++--- .../internal/ManagedBeanRegistryImpl.java | 32 +++++++------- .../InvalidExtendedCdiSupportTest.java | 9 ---- .../extended/ValidExtendedCdiSupportTest.java | 9 ---- .../mixed/ExtendedMixedAccessTest.java | 9 ---- ...RegistryManagedExtendedCdiSupportTest.java | 9 ---- .../TestingExtendedBeanManager.java | 4 -- .../TestingLegacyExtendedBeanManagerImpl.java | 35 --------------- 12 files changed, 29 insertions(+), 151 deletions(-) delete mode 100644 hibernate-core/src/main/java/org/hibernate/jpa/event/spi/jpa/ExtendedBeanManager.java delete mode 100644 hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingLegacyExtendedBeanManagerImpl.java diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/jpa/ExtendedBeanManager.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/jpa/ExtendedBeanManager.java deleted file mode 100644 index 793a353084..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/spi/jpa/ExtendedBeanManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.jpa.event.spi.jpa; - -import jakarta.enterprise.inject.spi.BeanManager; - -/** - * @deprecated Use {@link org.hibernate.resource.beans.container.spi.ExtendedBeanManager} instead - */ -@Deprecated -public interface ExtendedBeanManager extends org.hibernate.resource.beans.container.spi.ExtendedBeanManager { - void registerLifecycleListener(LifecycleListener lifecycleListener); - - @Override - default void registerLifecycleListener(org.hibernate.resource.beans.container.spi.ExtendedBeanManager.LifecycleListener lifecycleListener) { - /* - * Casting the argument to our own LifecycleListener interface won't work here, - * since we would be down-casting and the argument may not implement the correct interface. - * Just use an adaptor. - */ - registerLifecycleListener( new LifecycleListener() { - @Override - public void beanManagerInitialized(BeanManager beanManager) { - lifecycleListener.beanManagerInitialized( beanManager ); - } - - @Override - public void beforeBeanManagerDestroyed(BeanManager beanManager) { - lifecycleListener.beforeBeanManagerDestroyed( beanManager ); - } - } ); - } - - /** - * @deprecated Use {@link org.hibernate.resource.beans.container.spi.ExtendedBeanManager.LifecycleListener} instead - */ - @Deprecated - interface LifecycleListener extends org.hibernate.resource.beans.container.spi.ExtendedBeanManager.LifecycleListener { - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/CdiBeanContainerBuilder.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/CdiBeanContainerBuilder.java index f32de1409c..4d01f55d97 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/CdiBeanContainerBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/CdiBeanContainerBuilder.java @@ -25,7 +25,7 @@ import org.hibernate.service.ServiceRegistry; * in terms of building CDI-based {@link BeanContainer} * instance * - * We need to to avoid statically linking CDI classed into the ClassLoader which + * We need to avoid statically linking CDI classed into the ClassLoader which * would lead to errors if CDI is not available on the classpath. * * @author Steve Ebersole @@ -37,16 +37,15 @@ public class CdiBeanContainerBuilder { private static final String BEAN_MANAGER_EXTENSION_FQN = "org.hibernate.resource.beans.container.spi.ExtendedBeanManager"; - @SuppressWarnings("unchecked") public static BeanContainer fromBeanManagerReference( Object beanManagerRef, ServiceRegistry serviceRegistry) { final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class ); - final Class beanManagerClass = ManagedBeanRegistryInitiator.cdiBeanManagerClass( classLoaderService ); - final Class extendedBeanManagerClass = getHibernateClass( BEAN_MANAGER_EXTENSION_FQN ); + final Class beanManagerClass = ManagedBeanRegistryInitiator.cdiBeanManagerClass( classLoaderService ); + final Class extendedBeanManagerClass = getHibernateClass( BEAN_MANAGER_EXTENSION_FQN ); final Class containerClass; - final Class ctorArgType; + final Class ctorArgType; if ( extendedBeanManagerClass.isInstance( beanManagerRef ) ) { containerClass = getHibernateClass( CONTAINER_FQN_EXTENDED ); diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java index de52a84cd5..4bfafc9062 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/ContainerManagedLifecycleStrategy.java @@ -148,9 +148,8 @@ public class ContainerManagedLifecycleStrategy implements BeanLifecycleStrategy } @Override - @SuppressWarnings("unchecked") protected Instance resolveContainerInstance() { - final Instance root; + final Instance root; try { root = beanManager.createInstance(); } diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java index ff7fd4fd1b..ad96901366 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/container/internal/JpaCompliantLifecycleStrategy.java @@ -72,7 +72,7 @@ public class JpaCompliantLifecycleStrategy implements BeanLifecycleStrategy { private static class BeanImpl implements ContainedBeanImplementor { private final Class beanType; - private BeanInstanceProducer fallbackProducer; + private final BeanInstanceProducer fallbackProducer; private BeanManager beanManager; private InjectionTarget injectionTarget; @@ -189,7 +189,7 @@ public class JpaCompliantLifecycleStrategy implements BeanLifecycleStrategy { private final Class beanType; private final String beanName; - private BeanInstanceProducer fallbackProducer; + private final BeanInstanceProducer fallbackProducer; private BeanManager beanManager; private Bean bean; diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java index 2c5c19b79d..9d23605f49 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/Helper.java @@ -22,21 +22,18 @@ public class Helper { private Helper() { } - public String determineBeanCacheKey(Class beanType) { + public String determineBeanCacheKey(Class beanType) { return beanType.getName(); } - public String determineBeanCacheKey(String name, Class beanType) { + public String determineBeanCacheKey(String name, Class beanType) { return beanType.getName() + ':' + name; } @SuppressWarnings("unused") public BeanLifecycleStrategy getLifecycleStrategy(boolean shouldRegistryManageLifecycle) { - if ( shouldRegistryManageLifecycle ) { - return JpaCompliantLifecycleStrategy.INSTANCE; - } - else { - return ContainerManagedLifecycleStrategy.INSTANCE; - } + return shouldRegistryManageLifecycle + ? JpaCompliantLifecycleStrategy.INSTANCE + : ContainerManagedLifecycleStrategy.INSTANCE; } } diff --git a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/ManagedBeanRegistryImpl.java b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/ManagedBeanRegistryImpl.java index 28f4151b7b..7073071841 100644 --- a/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/ManagedBeanRegistryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/resource/beans/internal/ManagedBeanRegistryImpl.java @@ -23,7 +23,7 @@ import org.hibernate.service.spi.Stoppable; * @author Steve Ebersole */ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContainer.LifecycleOptions, Stoppable { - private Map> registrations = new HashMap<>(); + private final Map> registrations = new HashMap<>(); private final BeanContainer beanContainer; @@ -47,21 +47,21 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain } @Override - @SuppressWarnings("unchecked") public ManagedBean getBean(Class beanClass) { return getBean( beanClass, FallbackBeanInstanceProducer.INSTANCE ); } @Override public ManagedBean getBean(Class beanClass, BeanInstanceProducer fallbackBeanInstanceProducer) { - final ManagedBean existing = registrations.get( beanClass.getName() ); + final ManagedBean existing = registrations.get( beanClass.getName() ); if ( existing != null ) { - return existing; + //noinspection unchecked + return (ManagedBean) existing; } - final ManagedBean bean; + final ManagedBean bean; if ( beanContainer == null ) { - bean = new FallbackContainedBean( beanClass, fallbackBeanInstanceProducer ); + bean = new FallbackContainedBean<>( beanClass, fallbackBeanInstanceProducer ); } else { final ContainedBean containedBean = beanContainer.getBean( @@ -71,10 +71,11 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain ); if ( containedBean instanceof ManagedBean ) { - bean = (ManagedBean) containedBean; + //noinspection unchecked + bean = (ManagedBean) containedBean; } else { - bean = new ContainedBeanManagedBeanAdapter( beanClass, containedBean ); + bean = new ContainedBeanManagedBeanAdapter<>( beanClass, containedBean ); } } @@ -89,21 +90,21 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain } @Override - @SuppressWarnings("unchecked") public ManagedBean getBean( String beanName, Class beanContract, BeanInstanceProducer fallbackBeanInstanceProducer) { final String key = beanContract.getName() + ':' + beanName; - final ManagedBean existing = registrations.get( key ); + final ManagedBean existing = registrations.get( key ); if ( existing != null ) { - return existing; + //noinspection unchecked + return (ManagedBean) existing; } - final ManagedBean bean; + final ManagedBean bean; if ( beanContainer == null ) { - bean = new FallbackContainedBean( beanName, beanContract, fallbackBeanInstanceProducer ); + bean = new FallbackContainedBean<>( beanName, beanContract, fallbackBeanInstanceProducer ); } else { final ContainedBean containedBean = beanContainer.getBean( @@ -114,10 +115,11 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain ); if ( containedBean instanceof ManagedBean ) { - bean = (ManagedBean) containedBean; + //noinspection unchecked + bean = (ManagedBean) containedBean; } else { - bean = new ContainedBeanManagedBeanAdapter( beanContract, containedBean ); + bean = new ContainedBeanManagedBeanAdapter<>( beanContract, containedBean ); } } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/InvalidExtendedCdiSupportTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/InvalidExtendedCdiSupportTest.java index 48df53b462..d4851da653 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/InvalidExtendedCdiSupportTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/InvalidExtendedCdiSupportTest.java @@ -38,15 +38,6 @@ public class InvalidExtendedCdiSupportTest extends BaseUnitTestCase { doTest( TestingExtendedBeanManager.create() ); } - /** - * NOTE : we use the deprecated one here to make sure this continues to work. - * Scott still uses this in WildFly and we need it to continue to work there - */ - @Test - public void testLegacy() { - doTest( TestingExtendedBeanManager.createLegacy() ); - } - private void doTest(TestingExtendedBeanManager beanManager) { Monitor.reset(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/ValidExtendedCdiSupportTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/ValidExtendedCdiSupportTest.java index a4c8145e97..30fc4a5b57 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/ValidExtendedCdiSupportTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/events/extended/ValidExtendedCdiSupportTest.java @@ -43,15 +43,6 @@ public class ValidExtendedCdiSupportTest extends BaseUnitTestCase { doTest( TestingExtendedBeanManager.create() ); } - /** - * NOTE : we use the deprecated one here to make sure this continues to work. - * Scott still uses this in WildFly and we need it to continue to work there - */ - @Test - public void testLegacy() { - doTest( TestingExtendedBeanManager.createLegacy() ); - } - private void doTest(TestingExtendedBeanManager beanManager) { Monitor.reset(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/mixed/ExtendedMixedAccessTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/mixed/ExtendedMixedAccessTest.java index dfae438b39..9f7de923f8 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/mixed/ExtendedMixedAccessTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/mixed/ExtendedMixedAccessTest.java @@ -36,15 +36,6 @@ public class ExtendedMixedAccessTest implements BeanContainer.LifecycleOptions { doTest( TestingExtendedBeanManager.create() ); } - /** - * NOTE : we use the deprecated one here to make sure this continues to work. - * Scott still uses this in WildFly and we need it to continue to work there - */ - @Test - public void testLegacyExtendedMixedAccess() { - doTest( TestingExtendedBeanManager.createLegacy() ); - } - private void doTest(TestingExtendedBeanManager extendedBeanManager) { try (final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder() .applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP ) diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/nonregistrymanaged/extended/NonRegistryManagedExtendedCdiSupportTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/nonregistrymanaged/extended/NonRegistryManagedExtendedCdiSupportTest.java index 9cfce2d4f3..7aa5a0e9bd 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/nonregistrymanaged/extended/NonRegistryManagedExtendedCdiSupportTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/general/nonregistrymanaged/extended/NonRegistryManagedExtendedCdiSupportTest.java @@ -55,15 +55,6 @@ public class NonRegistryManagedExtendedCdiSupportTest extends BaseUnitTestCase { doTest( TestingExtendedBeanManager.create() ); } - /** - * NOTE : we use the deprecated one here to make sure this continues to work. - * Scott still uses this in WildFly and we need it to continue to work there - */ - @Test - public void testLegacy() { - doTest( TestingExtendedBeanManager.createLegacy() ); - } - private void doTest(TestingExtendedBeanManager beanManager) { Monitor.reset(); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingExtendedBeanManager.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingExtendedBeanManager.java index c2e4d87b1b..eb3b9387a4 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingExtendedBeanManager.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingExtendedBeanManager.java @@ -18,8 +18,4 @@ public interface TestingExtendedBeanManager { return new TestingExtendedBeanManagerImpl(); } - static TestingExtendedBeanManager createLegacy() { - return new TestingLegacyExtendedBeanManagerImpl(); - } - } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingLegacyExtendedBeanManagerImpl.java b/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingLegacyExtendedBeanManagerImpl.java deleted file mode 100644 index 4aba198886..0000000000 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/cdi/testsupport/TestingLegacyExtendedBeanManagerImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later - * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html - */ -package org.hibernate.orm.test.cdi.testsupport; - -import jakarta.enterprise.inject.spi.BeanManager; - -import org.hibernate.jpa.event.spi.jpa.ExtendedBeanManager; - -class TestingLegacyExtendedBeanManagerImpl - implements TestingExtendedBeanManager, ExtendedBeanManager { - - private LifecycleListener lifecycleListener; - - @Override - public void registerLifecycleListener(LifecycleListener lifecycleListener) { - if ( this.lifecycleListener != null ) { - throw new RuntimeException( "LifecycleListener already registered" ); - } - this.lifecycleListener = lifecycleListener; - } - - @Override - public void notifyListenerReady(BeanManager beanManager) { - lifecycleListener.beanManagerInitialized( beanManager ); - } - - @Override - public void notifyListenerShuttingDown(BeanManager beanManager) { - lifecycleListener.beforeBeanManagerDestroyed( beanManager ); - } -}