Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
import org.hibernate.boot.registry.selector.StrategyRegistration;
import org.hibernate.boot.registry.selector.StrategyRegistrationProvider;
import org.hibernate.boot.registry.selector.internal.StrategySelectorBuilder;
import org.hibernate.integrator.internal.IntegratorServiceImpl;
Expand Down Expand Up @@ -129,7 +128,7 @@ public <T> BootstrapServiceRegistryBuilder applyStrategySelector(Class<T> strate
* @see org.hibernate.boot.registry.selector.spi.StrategySelector#registerStrategyImplementor(Class, String, Class)
*/
public BootstrapServiceRegistryBuilder applyStrategySelectors(StrategyRegistrationProvider strategyRegistrationProvider) {
for ( StrategyRegistration<?> strategyRegistration : strategyRegistrationProvider.getStrategyRegistrations() ) {
for ( var strategyRegistration : strategyRegistrationProvider.getStrategyRegistrations() ) {
this.strategySelectorBuilder.addExplicitStrategyRegistration( strategyRegistration );
}
return this;
Expand Down Expand Up @@ -169,33 +168,28 @@ public BootstrapServiceRegistryBuilder enableAutoClose() {
* @return The built bootstrap registry
*/
public BootstrapServiceRegistry build() {
final ClassLoaderService classLoaderService;
final var classLoaderService = classLoaderService();
return new BootstrapServiceRegistryImpl(
autoCloseRegistry,
classLoaderService,
strategySelectorBuilder.buildSelector( classLoaderService ),
new IntegratorServiceImpl( providedIntegrators, classLoaderService )
);
}

private ClassLoaderService classLoaderService() {
if ( providedClassLoaderService == null ) {
// Use a set. As an example, in JPA, OsgiClassLoader may be in both
// the providedClassLoaders and the overriddenClassLoader.
final Set<ClassLoader> classLoaders = new HashSet<>();

if ( providedClassLoaders != null ) {
classLoaders.addAll( providedClassLoaders );
}

classLoaderService = new ClassLoaderServiceImpl( classLoaders,tcclLookupPrecedence );
return new ClassLoaderServiceImpl( classLoaders,tcclLookupPrecedence );
}
else {
classLoaderService = providedClassLoaderService;
return providedClassLoaderService;
}

final IntegratorServiceImpl integratorService = IntegratorServiceImpl.create(
providedIntegrators,
classLoaderService
);

return new BootstrapServiceRegistryImpl(
autoCloseRegistry,
classLoaderService,
strategySelectorBuilder.buildSelector( classLoaderService ),
integratorService
);
}

/**
Expand All @@ -204,10 +198,8 @@ public BootstrapServiceRegistry build() {
* @param serviceRegistry The registry to be closed.
*/
public static void destroy(ServiceRegistry serviceRegistry) {
if ( serviceRegistry == null ) {
return;
if ( serviceRegistry != null ) {
((BootstrapServiceRegistryImpl) serviceRegistry).destroy();
}

( (BootstrapServiceRegistryImpl) serviceRegistry ).destroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,16 @@ public BootstrapServiceRegistryImpl(
classLoaderService
);

final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );
this.strategySelectorBinding = new ServiceBinding<>(
this,
StrategySelector.class,
strategySelector
new StrategySelectorImpl( classLoaderService )
);

this.integratorServiceBinding = new ServiceBinding<>(
this,
IntegratorService.class,
IntegratorServiceImpl.create( providedIntegrators, classLoaderService )
new IntegratorServiceImpl( providedIntegrators, classLoaderService )
);
}

Expand Down Expand Up @@ -184,7 +183,7 @@ public BootstrapServiceRegistryImpl(

@Override
public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
final var binding = locateServiceBinding( serviceRole );
return binding == null ? null : binding.getService();
}

Expand All @@ -206,24 +205,20 @@ else if ( IntegratorService.class.equals( serviceRole ) ) {

@Override
public synchronized void destroy() {
if ( !active ) {
return;
}
active = false;
destroy( classLoaderServiceBinding );
destroy( strategySelectorBinding );
destroy( integratorServiceBinding );

if ( childRegistries != null ) {
for ( ServiceRegistry serviceRegistry : childRegistries ) {
if ( serviceRegistry instanceof ServiceRegistryImplementor serviceRegistryImplementor ) {
serviceRegistryImplementor.destroy();
if ( active ) {
active = false;
destroy( classLoaderServiceBinding );
destroy( strategySelectorBinding );
destroy( integratorServiceBinding );
if ( childRegistries != null ) {
for ( var serviceRegistry : childRegistries ) {
serviceRegistry.destroy();
}
}
}
}

private synchronized void destroy(ServiceBinding serviceBinding) {
private synchronized void destroy(ServiceBinding<?> serviceBinding) {
serviceBinding.getLifecycleOwner().stopService( serviceBinding );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,33 @@
import org.hibernate.integrator.spi.Integrator;
import org.hibernate.integrator.spi.IntegratorService;

import org.jboss.logging.Logger;
import static org.hibernate.service.internal.ServiceLogger.SERVICE_LOGGER;

/**
* @author Steve Ebersole
*/
public class IntegratorServiceImpl implements IntegratorService {

private static final Logger LOG = Logger.getLogger( IntegratorServiceImpl.class );

private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();

private IntegratorServiceImpl() {
}

public static IntegratorServiceImpl create(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
IntegratorServiceImpl instance = new IntegratorServiceImpl();

// register standard integrators. Envers and JPA, for example, need to be handled by discovery because in
// separate project/jars.
instance.addIntegrator( new BeanValidationIntegrator() );
instance.addIntegrator( new CollectionCacheInvalidator() );
public IntegratorServiceImpl(Iterable<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
// Register standard integrators.
// Envers, for example, needs to be handled by discovery because in separate project/jar.
addIntegrator( integrators, new BeanValidationIntegrator() );
addIntegrator( integrators, new CollectionCacheInvalidator() );

// register provided integrators
for ( Integrator integrator : providedIntegrators ) {
instance.addIntegrator( integrator );
for ( var integrator : providedIntegrators ) {
addIntegrator( integrators, integrator );
}
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
instance.addIntegrator( integrator );
for ( var integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
addIntegrator( integrators, integrator );
}

return instance;
}

private void addIntegrator(Integrator integrator) {
if ( LOG.isDebugEnabled() ) {
LOG.debugf( "Adding Integrator [%s]", integrator.getClass().getName() );
private static void addIntegrator(LinkedHashSet<Integrator> integrators, Integrator integrator) {
if ( SERVICE_LOGGER.isDebugEnabled() ) {
SERVICE_LOGGER.addingIntegrator( integrator.getClass().getName() );
}
integrators.add( integrator );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* @author Andrea Boriero
*/
public class NullServiceException extends ServiceException {
public final Class serviceRole;
public final Class<?> serviceRole;

public NullServiceException(Class serviceRole) {
public NullServiceException(Class<?> serviceRole) {
super( "Unknown service requested [" + serviceRole.getName() + "]" );
this.serviceRole = serviceRole;
}

public Class getServiceRole() {
public Class<?> getServiceRole() {
return serviceRole;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private static List<StandardServiceInitiator<?>> buildStandardServiceInitiatorLi

// Please do not rearrange - it's useful to maintain this particular order
// so to simplify comparisons with custom initiator lists in other projects;
// for example we customize this list in Hibernate Reactive and Quarkus.
// for example, we customize this list in Hibernate Reactive and Quarkus.

final ArrayList<StandardServiceInitiator<?>> serviceInitiators = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
* @author Steve Ebersole
*/
public class UnknownServiceException extends ServiceException {
public final Class serviceRole;
public final Class<?> serviceRole;

public UnknownServiceException(Class serviceRole) {
public UnknownServiceException(Class<?> serviceRole) {
super( "Unknown service requested [" + serviceRole.getName() + "]" );
this.serviceRole = serviceRole;
}

public Class getServiceRole() {
public Class<?> getServiceRole() {
return serviceRole;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
* @author Steve Ebersole
*/
public class UnknownUnwrapTypeException extends HibernateException {
public UnknownUnwrapTypeException(Class unwrapType) {
public UnknownUnwrapTypeException(Class<?> unwrapType) {
super( "Cannot unwrap to requested type [" + unwrapType.getName() + "]" );
}

public UnknownUnwrapTypeException(Class unwrapType, Throwable root) {
public UnknownUnwrapTypeException(Class<?> unwrapType, Throwable root) {
this( unwrapType );
super.initCause( root );
}
Expand Down
Loading
Loading