remove deprecated ExtendedBeanManager
This commit is contained in:
parent
5dbf9aedf9
commit
8f8ae50e0b
|
@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
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 {
|
||||
}
|
||||
}
|
|
@ -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<? extends BeanContainer> containerClass;
|
||||
final Class ctorArgType;
|
||||
final Class<?> ctorArgType;
|
||||
|
||||
if ( extendedBeanManagerClass.isInstance( beanManagerRef ) ) {
|
||||
containerClass = getHibernateClass( CONTAINER_FQN_EXTENDED );
|
||||
|
|
|
@ -148,9 +148,8 @@ public class ContainerManagedLifecycleStrategy implements BeanLifecycleStrategy
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Instance<B> resolveContainerInstance() {
|
||||
final Instance root;
|
||||
final Instance<Object> root;
|
||||
try {
|
||||
root = beanManager.createInstance();
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class JpaCompliantLifecycleStrategy implements BeanLifecycleStrategy {
|
|||
private static class BeanImpl<B> implements ContainedBeanImplementor<B> {
|
||||
private final Class<B> beanType;
|
||||
|
||||
private BeanInstanceProducer fallbackProducer;
|
||||
private final BeanInstanceProducer fallbackProducer;
|
||||
|
||||
private BeanManager beanManager;
|
||||
private InjectionTarget<B> injectionTarget;
|
||||
|
@ -189,7 +189,7 @@ public class JpaCompliantLifecycleStrategy implements BeanLifecycleStrategy {
|
|||
private final Class<B> beanType;
|
||||
private final String beanName;
|
||||
|
||||
private BeanInstanceProducer fallbackProducer;
|
||||
private final BeanInstanceProducer fallbackProducer;
|
||||
|
||||
private BeanManager beanManager;
|
||||
private Bean<B> bean;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ import org.hibernate.service.spi.Stoppable;
|
|||
* @author Steve Ebersole
|
||||
*/
|
||||
public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContainer.LifecycleOptions, Stoppable {
|
||||
private Map<String,ManagedBean<?>> registrations = new HashMap<>();
|
||||
private final Map<String,ManagedBean<?>> registrations = new HashMap<>();
|
||||
|
||||
private final BeanContainer beanContainer;
|
||||
|
||||
|
@ -47,21 +47,21 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain
|
|||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> ManagedBean<T> getBean(Class<T> beanClass) {
|
||||
return getBean( beanClass, FallbackBeanInstanceProducer.INSTANCE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> ManagedBean<T> getBean(Class<T> 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<T>) existing;
|
||||
}
|
||||
|
||||
final ManagedBean bean;
|
||||
final ManagedBean<T> bean;
|
||||
if ( beanContainer == null ) {
|
||||
bean = new FallbackContainedBean( beanClass, fallbackBeanInstanceProducer );
|
||||
bean = new FallbackContainedBean<>( beanClass, fallbackBeanInstanceProducer );
|
||||
}
|
||||
else {
|
||||
final ContainedBean<T> containedBean = beanContainer.getBean(
|
||||
|
@ -71,10 +71,11 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain
|
|||
);
|
||||
|
||||
if ( containedBean instanceof ManagedBean ) {
|
||||
bean = (ManagedBean) containedBean;
|
||||
//noinspection unchecked
|
||||
bean = (ManagedBean<T>) 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 <T> ManagedBean<T> getBean(
|
||||
String beanName,
|
||||
Class<T> 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<T>) existing;
|
||||
}
|
||||
|
||||
final ManagedBean bean;
|
||||
final ManagedBean<T> bean;
|
||||
if ( beanContainer == null ) {
|
||||
bean = new FallbackContainedBean( beanName, beanContract, fallbackBeanInstanceProducer );
|
||||
bean = new FallbackContainedBean<>( beanName, beanContract, fallbackBeanInstanceProducer );
|
||||
}
|
||||
else {
|
||||
final ContainedBean<T> containedBean = beanContainer.getBean(
|
||||
|
@ -114,10 +115,11 @@ public class ManagedBeanRegistryImpl implements ManagedBeanRegistry, BeanContain
|
|||
);
|
||||
|
||||
if ( containedBean instanceof ManagedBean ) {
|
||||
bean = (ManagedBean) containedBean;
|
||||
//noinspection unchecked
|
||||
bean = (ManagedBean<T>) containedBean;
|
||||
}
|
||||
else {
|
||||
bean = new ContainedBeanManagedBeanAdapter( beanContract, containedBean );
|
||||
bean = new ContainedBeanManagedBeanAdapter<>( beanContract, containedBean );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -18,8 +18,4 @@ public interface TestingExtendedBeanManager {
|
|||
return new TestingExtendedBeanManagerImpl();
|
||||
}
|
||||
|
||||
static TestingExtendedBeanManager createLegacy() {
|
||||
return new TestingLegacyExtendedBeanManagerImpl();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue