Revert "HHH-16515 - Add o.h.exception to nullness checking"

This reverts commit c5c3bb8ac8.
This commit is contained in:
Jan Schatteman 2023-07-14 23:11:03 +02:00 committed by Jan Schatteman
parent 06ed2072ce
commit 314f2d7b7a
44 changed files with 149 additions and 249 deletions

View File

@ -544,7 +544,7 @@ checkerFramework {
extraJavacArgs = [ extraJavacArgs = [
'-AsuppressWarnings=initialization', '-AsuppressWarnings=initialization',
// stubs is passed directly through options.compilerArgumentProviders // stubs is passed directly through options.compilerArgumentProviders
'-AonlyDefs=^org\\.hibernate\\.(exception|integrator|jpamodelgen|service|spi|pretty|stat|engine\\.(config|jndi|profile|transaction)|(action|context|bytecode)\\.spi)\\.' '-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.(profile|transaction)|(action|context|bytecode)\\.spi)\\.'
] ]
} }

View File

@ -659,6 +659,10 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
this.sharedCacheMode = configService.getSetting( this.sharedCacheMode = configService.getSetting(
AvailableSettings.JAKARTA_SHARED_CACHE_MODE, AvailableSettings.JAKARTA_SHARED_CACHE_MODE,
value -> { value -> {
if ( value == null ) {
return null;
}
if ( value instanceof SharedCacheMode ) { if ( value instanceof SharedCacheMode ) {
return (SharedCacheMode) value; return (SharedCacheMode) value;
} }

View File

@ -187,7 +187,7 @@ public class BootstrapServiceRegistryBuilder {
classLoaderService = providedClassLoaderService; classLoaderService = providedClassLoaderService;
} }
final IntegratorServiceImpl integratorService = IntegratorServiceImpl.create( final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
providedIntegrators, providedIntegrators,
classLoaderService classLoaderService
); );

View File

@ -365,7 +365,7 @@ public class StandardServiceRegistryBuilder {
settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml ); settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml );
ConfigurationHelper.resolvePlaceHolders( settingsCopy ); ConfigurationHelper.resolvePlaceHolders( settingsCopy );
return StandardServiceRegistryImpl.create( return new StandardServiceRegistryImpl(
autoCloseRegistry, autoCloseRegistry,
bootstrapServiceRegistry, bootstrapServiceRegistry,
initiators, initiators,

View File

@ -29,8 +29,6 @@ import org.hibernate.service.spi.ServiceInitiator;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.Stoppable;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul> * {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul>
* <li>{@link ClassLoaderService}</li> * <li>{@link ClassLoaderService}</li>
@ -119,7 +117,7 @@ public class BootstrapServiceRegistryImpl
this.integratorServiceBinding = new ServiceBinding<>( this.integratorServiceBinding = new ServiceBinding<>(
this, this,
IntegratorService.class, IntegratorService.class,
IntegratorServiceImpl.create( providedIntegrators, classLoaderService ) new IntegratorServiceImpl( providedIntegrators, classLoaderService )
); );
} }
@ -187,7 +185,7 @@ public class BootstrapServiceRegistryImpl
@Override @Override
public <R extends Service> @Nullable R getService(Class<R> serviceRole) { public <R extends Service> R getService(Class<R> serviceRole) {
final ServiceBinding<R> binding = locateServiceBinding( serviceRole ); final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
return binding == null ? null : binding.getService(); return binding == null ? null : binding.getService();
} }
@ -237,7 +235,7 @@ public class BootstrapServiceRegistryImpl
} }
@Override @Override
public @Nullable ServiceRegistry getParentServiceRegistry() { public ServiceRegistry getParentServiceRegistry() {
return null; return null;
} }

View File

@ -30,14 +30,6 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
//Access to this field requires synchronization on -this- //Access to this field requires synchronization on -this-
private Map<String,Object> configurationValues; private Map<String,Object> configurationValues;
protected StandardServiceRegistryImpl(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String,Object> configurationValues) {
super( bootstrapServiceRegistry, autoCloseRegistry );
this.configurationValues = configurationValues;
}
/** /**
* Constructs a StandardServiceRegistryImpl. Should not be instantiated directly; use * Constructs a StandardServiceRegistryImpl. Should not be instantiated directly; use
* {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead * {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
@ -49,13 +41,12 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
* *
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder * @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
*/ */
public static StandardServiceRegistryImpl create( public StandardServiceRegistryImpl(
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators, List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) { Map<String,Object> configurationValues) {
this( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
return create( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
} }
/** /**
@ -71,21 +62,20 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
* *
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder * @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
*/ */
public static StandardServiceRegistryImpl create( public StandardServiceRegistryImpl(
boolean autoCloseRegistry, boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators, List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) { Map<String,Object> configurationValues) {
super( bootstrapServiceRegistry, autoCloseRegistry );
StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues ); this.configurationValues = configurationValues;
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );
return instance; applyServiceRegistrations( serviceInitiators, providedServices );
} }
protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) { private void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
try { try {
// process initiators // process initiators
for ( ServiceInitiator<?> initiator : serviceInitiators ) { for ( ServiceInitiator<?> initiator : serviceInitiators ) {

View File

@ -8,8 +8,6 @@ package org.hibernate.cache.spi.access;
import java.util.Locale; import java.util.Locale;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Enumerates the policies for managing concurrent access to the shared * Enumerates the policies for managing concurrent access to the shared
* second-level cache. * second-level cache.
@ -72,7 +70,7 @@ public enum AccessType {
* *
* @see #getExternalName() * @see #getExternalName()
*/ */
public static AccessType fromExternalName(@Nullable String externalName) { public static AccessType fromExternalName(String externalName) {
if ( externalName == null ) { if ( externalName == null ) {
return null; return null;
} }

View File

@ -13,15 +13,11 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryAwareService; import org.hibernate.service.spi.ServiceRegistryAwareService;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
/** /**
* The standard {@link ConfigurationService} implementation. * The standard {@link ConfigurationService} implementation.
* *
@ -56,12 +52,12 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
} }
@Override @Override
public <T> @Nullable T getSetting(String name, Converter<T> converter) { public <T> T getSetting(String name, Converter<T> converter) {
return getSetting( name, converter, null ); return getSetting( name, converter, null );
} }
@Override @Override
public <T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue) { public <T> T getSetting(String name, Converter<T> converter, T defaultValue) {
final Object value = settings.get( name ); final Object value = settings.get( name );
if ( value == null ) { if ( value == null ) {
return defaultValue; return defaultValue;
@ -71,14 +67,14 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
} }
@Override @Override
public <T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue) { public <T> T getSetting(String name, Class<T> expected, T defaultValue) {
final Object value = settings.get( name ); final Object value = settings.get( name );
final T target = cast( expected, value ); final T target = cast( expected, value );
return target !=null ? target : defaultValue; return target !=null ? target : defaultValue;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T> @Nullable T cast(Class<T> expected, @Nullable Object candidate){ public <T> T cast(Class<T> expected, Object candidate){
if (candidate == null) { if (candidate == null) {
return null; return null;
} }
@ -93,7 +89,7 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
} }
else { else {
try { try {
target = NullnessUtil.castNonNull( serviceRegistry.getService( ClassLoaderService.class ) ).classForName( candidate.toString() ); target = serviceRegistry.getService( ClassLoaderService.class ).classForName( candidate.toString() );
} }
catch ( ClassLoadingException e ) { catch ( ClassLoadingException e ) {
LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() ); LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() );

View File

@ -10,10 +10,6 @@ import java.util.Map;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.checker.nullness.qual.PolyNull;
/** /**
* Provides access to the initial user-provided configuration values. Generally speaking * Provides access to the initial user-provided configuration values. Generally speaking
* these values come from:<ul> * these values come from:<ul>
@ -42,7 +38,7 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) setting. May return {@code null} (see {@link #getSetting(String, Class, Object)}) * @return The converted (typed) setting. May return {@code null} (see {@link #getSetting(String, Class, Object)})
*/ */
<T> @Nullable T getSetting(String name, Converter<T> converter); <T> T getSetting(String name, Converter<T> converter);
/** /**
* Get the named setting, using the specified converter and default value. * Get the named setting, using the specified converter and default value.
@ -54,7 +50,7 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined. * @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
*/ */
<T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue); <T> T getSetting(String name, Converter<T> converter, T defaultValue);
/** /**
* Get the named setting. Differs from the form taking a Converter in that here we expect to have a simple * Get the named setting. Differs from the form taking a Converter in that here we expect to have a simple
@ -67,7 +63,7 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined. * @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
*/ */
<T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue); <T> T getSetting(String name, Class<T> expected, T defaultValue);
/** /**
* Simple conversion contract for converting an untyped object to a specified type. * Simple conversion contract for converting an untyped object to a specified type.
@ -82,6 +78,6 @@ public interface ConfigurationService extends Service {
* *
* @return The converted (typed) value. * @return The converted (typed) value.
*/ */
@NonNull T convert(Object value); T convert(Object value);
} }
} }

View File

@ -7,8 +7,6 @@
package org.hibernate.engine.config.spi; package org.hibernate.engine.config.spi;
import org.checkerframework.checker.nullness.qual.PolyNull;
import static org.hibernate.engine.config.spi.ConfigurationService.Converter; import static org.hibernate.engine.config.spi.ConfigurationService.Converter;
/** /**
@ -20,6 +18,10 @@ public class StandardConverters {
public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean; public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean;
public static Boolean asBoolean(Object value) { public static Boolean asBoolean(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
return value instanceof Boolean return value instanceof Boolean
? (Boolean) value ? (Boolean) value
: Boolean.parseBoolean( value.toString() ); : Boolean.parseBoolean( value.toString() );
@ -28,12 +30,20 @@ public class StandardConverters {
public static final Converter<String> STRING = StandardConverters::asString; public static final Converter<String> STRING = StandardConverters::asString;
public static String asString(Object value) { public static String asString(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
return value.toString(); return value.toString();
} }
public static final Converter<Integer> INTEGER = StandardConverters::asInteger; public static final Converter<Integer> INTEGER = StandardConverters::asInteger;
public static Integer asInteger(Object value) { public static Integer asInteger(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
if ( value instanceof Number ) { if ( value instanceof Number ) {
return ( (Number) value ).intValue(); return ( (Number) value ).intValue();
} }

View File

@ -24,7 +24,6 @@ import org.hibernate.engine.jndi.JndiException;
import org.hibernate.engine.jndi.JndiNameException; import org.hibernate.engine.jndi.JndiNameException;
import org.hibernate.engine.jndi.spi.JndiService; import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -81,7 +80,7 @@ final class JndiServiceImpl implements JndiService {
} }
else { else {
final String passThruPropertyName = propertyName.substring( Environment.JNDI_PREFIX.length() + 1 ); final String passThruPropertyName = propertyName.substring( Environment.JNDI_PREFIX.length() + 1 );
jndiProperties.put( passThruPropertyName, NullnessUtil.castNonNull( propertyValue ) ); jndiProperties.put( passThruPropertyName, propertyValue );
} }
} }
} }

View File

@ -18,7 +18,6 @@ import org.hibernate.engine.jndi.spi.JndiService;
import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.internal.util.config.ConfigurationHelper; import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Configurable;
@ -64,7 +63,7 @@ public abstract class AbstractJtaPlatform
} }
protected JndiService jndiService() { protected JndiService jndiService() {
return NullnessUtil.castNonNull( serviceRegistry().getService( JndiService.class ) ); return serviceRegistry().getService( JndiService.class );
} }
protected abstract TransactionManager locateTransactionManager(); protected abstract TransactionManager locateTransactionManager();

View File

@ -11,7 +11,6 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* @author Vlad Mihalcea * @author Vlad Mihalcea
@ -22,7 +21,7 @@ public class AtomikosJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
Class transactionManagerClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME ); Class transactionManagerClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
return (TransactionManager) transactionManagerClass.newInstance(); return (TransactionManager) transactionManagerClass.newInstance();
} }
catch (Exception e) { catch (Exception e) {

View File

@ -12,7 +12,6 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -23,7 +22,7 @@ public class BitronixJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
Class transactionManagerServicesClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME ); Class transactionManagerServicesClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
final Method getTransactionManagerMethod = transactionManagerServicesClass.getMethod( "getTransactionManager" ); final Method getTransactionManagerMethod = transactionManagerServicesClass.getMethod( "getTransactionManager" );
return (TransactionManager) getTransactionManagerMethod.invoke( null ); return (TransactionManager) getTransactionManagerMethod.invoke( null );
} }

View File

@ -11,7 +11,6 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* Return a standalone JTA transaction manager for JBoss (Arjuna) Transactions or WildFly transaction client * Return a standalone JTA transaction manager for JBoss (Arjuna) Transactions or WildFly transaction client
@ -38,8 +37,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
} }
try { try {
final Class jbossTmClass = NullnessUtil.castNonNull( serviceRegistry() final Class jbossTmClass = serviceRegistry()
.getService( ClassLoaderService.class ) ) .getService( ClassLoaderService.class )
.classForName( JBOSS_TM_CLASS_NAME ); .classForName( JBOSS_TM_CLASS_NAME );
return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null ); return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
} }
@ -59,8 +58,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
} }
try { try {
final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry() final Class jbossUtClass = serviceRegistry()
.getService( ClassLoaderService.class ) ) .getService( ClassLoaderService.class )
.classForName( JBOSS_UT_CLASS_NAME ); .classForName( JBOSS_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null ); return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
} }

View File

@ -12,7 +12,6 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
@ -24,7 +23,7 @@ public class JOTMJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
final Class tmClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME ); final Class tmClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" ); final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" );
return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null ); return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null );
} }

View File

@ -14,7 +14,6 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -39,11 +38,11 @@ public class JtaPlatformInitiator implements StandardServiceInitiator<JtaPlatfor
@Override @Override
public @Nullable JtaPlatform initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) { public @Nullable JtaPlatform initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM ); final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
JtaPlatform platform = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) ).resolveStrategy( JtaPlatform.class, setting ); JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
if ( platform == null ) { if ( platform == null ) {
LOG.debug( "No JtaPlatform was specified, checking resolver" ); LOG.debug( "No JtaPlatform was specified, checking resolver" );
platform = NullnessUtil.castNonNull( registry.getService( JtaPlatformResolver.class ) ).resolveJtaPlatform( configurationValues, registry ); platform = registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
} }
if ( platform == null ) { if ( platform == null ) {

View File

@ -12,7 +12,6 @@ import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.selector.spi.StrategySelector; import org.hibernate.boot.registry.selector.spi.StrategySelector;
import org.hibernate.cfg.AvailableSettings; import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -28,7 +27,7 @@ public class JtaPlatformResolverInitiator implements StandardServiceInitiator<Jt
@Override @Override
public JtaPlatformResolver initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) { public JtaPlatformResolver initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER ); final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER );
final JtaPlatformResolver resolver = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) ) final JtaPlatformResolver resolver = registry.getService( StrategySelector.class )
.resolveStrategy( JtaPlatformResolver.class, setting ); .resolveStrategy( JtaPlatformResolver.class, setting );
if ( resolver == null ) { if ( resolver == null ) {
log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() ); log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() );

View File

@ -13,7 +13,6 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformProvider;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
@ -28,7 +27,7 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
@Override @Override
public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) { public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) {
final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) ); final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
// Initially look for a JtaPlatformProvider // Initially look for a JtaPlatformProvider
for ( JtaPlatformProvider provider : classLoaderService.loadJavaServices( JtaPlatformProvider.class ) ) { for ( JtaPlatformProvider provider : classLoaderService.loadJavaServices( JtaPlatformProvider.class ) ) {

View File

@ -34,8 +34,8 @@ public class WebSphereLibertyJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
final Class<?> TransactionManagerFactory = NullnessUtil.castNonNull( serviceRegistry() final Class<?> TransactionManagerFactory = serviceRegistry()
.getService( ClassLoaderService.class ) ) .getService( ClassLoaderService.class )
.classForName( TMF_CLASS_NAME ); .classForName( TMF_CLASS_NAME );
return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null); return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null);
} }

View File

@ -11,7 +11,6 @@ import jakarta.transaction.UserTransaction;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
import org.hibernate.internal.util.NullnessUtil;
/** /**
* Return a standalone JTA transaction manager for WildFly transaction client * Return a standalone JTA transaction manager for WildFly transaction client
@ -26,8 +25,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected TransactionManager locateTransactionManager() { protected TransactionManager locateTransactionManager() {
try { try {
final Class wildflyTmClass = NullnessUtil.castNonNull( serviceRegistry() final Class wildflyTmClass = serviceRegistry()
.getService( ClassLoaderService.class ) ) .getService( ClassLoaderService.class )
.classForName( WILDFLY_TM_CLASS_NAME ); .classForName( WILDFLY_TM_CLASS_NAME );
return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null ); return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
} }
@ -42,8 +41,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
@Override @Override
protected UserTransaction locateUserTransaction() { protected UserTransaction locateUserTransaction() {
try { try {
final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry() final Class jbossUtClass = serviceRegistry()
.getService( ClassLoaderService.class ) ) .getService( ClassLoaderService.class )
.classForName( WILDFLY_UT_CLASS_NAME ); .classForName( WILDFLY_UT_CLASS_NAME );
return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null ); return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null );
} }

View File

@ -9,8 +9,6 @@ import java.sql.SQLException;
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link JDBCException} indicating that the requested DML operation * A {@link JDBCException} indicating that the requested DML operation
* resulted in violation of a defined integrity constraint. * resulted in violation of a defined integrity constraint.
@ -19,14 +17,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/ */
public class ConstraintViolationException extends JDBCException { public class ConstraintViolationException extends JDBCException {
private final @Nullable String constraintName; private final String constraintName;
public ConstraintViolationException(String message, SQLException root, @Nullable String constraintName) { public ConstraintViolationException(String message, SQLException root, String constraintName) {
super( message, root ); super( message, root );
this.constraintName = constraintName; this.constraintName = constraintName;
} }
public ConstraintViolationException(String message, SQLException root, String sql, @Nullable String constraintName) { public ConstraintViolationException(String message, SQLException root, String sql, String constraintName) {
super( message, root, sql ); super( message, root, sql );
this.constraintName = constraintName; this.constraintName = constraintName;
} }
@ -36,7 +34,7 @@ public class ConstraintViolationException extends JDBCException {
* *
* @return The name of the violated constraint, or null if not known. * @return The name of the violated constraint, or null if not known.
*/ */
public @Nullable String getConstraintName() { public String getConstraintName() {
return constraintName; return constraintName;
} }
} }

View File

@ -28,8 +28,6 @@ import org.hibernate.exception.SQLGrammarException;
import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate; import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate;
import org.hibernate.exception.spi.ConversionContext; import org.hibernate.exception.spi.ConversionContext;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation * A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation
* that does conversion based on the {@link SQLException} subtype hierarchy * that does conversion based on the {@link SQLException} subtype hierarchy
@ -43,7 +41,7 @@ public class SQLExceptionTypeDelegate extends AbstractSQLExceptionConversionDele
} }
@Override @Override
public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) { public JDBCException convert(SQLException sqlException, String message, String sql) {
if ( sqlException instanceof SQLClientInfoException if ( sqlException instanceof SQLClientInfoException
|| sqlException instanceof SQLInvalidAuthorizationSpecException || sqlException instanceof SQLInvalidAuthorizationSpecException
|| sqlException instanceof SQLNonTransientConnectionException || sqlException instanceof SQLNonTransientConnectionException

View File

@ -21,8 +21,6 @@ import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate;
import org.hibernate.exception.spi.ConversionContext; import org.hibernate.exception.spi.ConversionContext;
import org.hibernate.internal.util.JdbcExceptionHelper; import org.hibernate.internal.util.JdbcExceptionHelper;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation which performs conversion based * A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation which performs conversion based
* on the underlying SQLState. Interpretation of a SQL error based on SQLState is not nearly as accurate as * on the underlying SQLState. Interpretation of a SQL error based on SQLState is not nearly as accurate as
@ -79,7 +77,7 @@ public class SQLStateConversionDelegate extends AbstractSQLExceptionConversionDe
} }
@Override @Override
public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) { public JDBCException convert(SQLException sqlException, String message, String sql) {
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException ); final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException ); final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );

View File

@ -16,8 +16,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A {@link SQLExceptionConverter} that delegates to a chain of * A {@link SQLExceptionConverter} that delegates to a chain of
* {@link SQLExceptionConversionDelegate}. * {@link SQLExceptionConversionDelegate}.
@ -46,7 +44,7 @@ public class StandardSQLExceptionConverter implements SQLExceptionConverter {
* @deprecated use {@link #StandardSQLExceptionConverter(SQLExceptionConversionDelegate...)} * @deprecated use {@link #StandardSQLExceptionConverter(SQLExceptionConversionDelegate...)}
*/ */
@Deprecated(since = "6.0") @Deprecated(since = "6.0")
public void addDelegate(@Nullable SQLExceptionConversionDelegate delegate) { public void addDelegate(SQLExceptionConversionDelegate delegate) {
if ( delegate != null ) { if ( delegate != null ) {
this.delegates.add( delegate ); this.delegates.add( delegate );
} }

View File

@ -10,8 +10,6 @@ import java.sql.SQLException;
import org.hibernate.JDBCException; import org.hibernate.JDBCException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Allow a {@link SQLExceptionConverter} to work by chaining together * Allow a {@link SQLExceptionConverter} to work by chaining together
* multiple delegates. The main difference between a delegate and a * multiple delegates. The main difference between a delegate and a
@ -33,6 +31,6 @@ public interface SQLExceptionConversionDelegate {
* if this delegate does not know how to interpret the * if this delegate does not know how to interpret the
* given {@link SQLException}. * given {@link SQLException}.
*/ */
@Nullable JDBCException convert(SQLException sqlException, String message, String sql); JDBCException convert(SQLException sqlException, String message, String sql);
} }

View File

@ -9,10 +9,6 @@ package org.hibernate.exception.spi;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.function.Function; import java.util.function.Function;
import org.hibernate.internal.util.NullnessUtil;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Extracts a violated database constraint name from an error message * Extracts a violated database constraint name from an error message
* by matching the error message against a template. * by matching the error message against a template.
@ -29,7 +25,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
} }
@Override @Override
public @Nullable String extractConstraintName(SQLException sqle) { public String extractConstraintName(SQLException sqle) {
try { try {
String constraintName = null; String constraintName = null;
@ -41,7 +37,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
break; break;
} }
else { else {
sqle = NullnessUtil.castNonNull( sqle.getNextException() ); sqle = sqle.getNextException();
} }
} while (constraintName == null); } while (constraintName == null);
@ -61,7 +57,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
* @param message The templated error message containing the constraint name. * @param message The templated error message containing the constraint name.
* @return The found constraint name, or null. * @return The found constraint name, or null.
*/ */
public static @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message) { public static String extractUsingTemplate(String templateStart, String templateEnd, String message) {
int templateStartPosition = message.indexOf( templateStart ); int templateStartPosition = message.indexOf( templateStart );
if ( templateStartPosition < 0 ) { if ( templateStartPosition < 0 ) {
return null; return null;

View File

@ -8,8 +8,6 @@ package org.hibernate.exception.spi;
import java.sql.SQLException; import java.sql.SQLException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* An object that can extract the name of a violated database constraint * An object that can extract the name of a violated database constraint
* from a {@link SQLException} that results from the constraint violation. * from a {@link SQLException} that results from the constraint violation.
@ -25,5 +23,5 @@ public interface ViolatedConstraintNameExtractor {
* @param sqle The exception that was the result of the constraint violation. * @param sqle The exception that was the result of the constraint violation.
* @return The extracted constraint name. * @return The extracted constraint name.
*/ */
@Nullable String extractConstraintName(SQLException sqle); String extractConstraintName(SQLException sqle);
} }

View File

@ -8,8 +8,6 @@ package org.hibernate.id;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Describes the strategy for handling the mismatch between a database sequence configuration and * Describes the strategy for handling the mismatch between a database sequence configuration and
* the one defined by the entity mapping. * the one defined by the entity mapping.
@ -55,7 +53,7 @@ public enum SequenceMismatchStrategy {
* *
* @return associated {@link SequenceMismatchStrategy} object * @return associated {@link SequenceMismatchStrategy} object
*/ */
public static SequenceMismatchStrategy interpret(@Nullable Object sequenceMismatchStrategy) { public static SequenceMismatchStrategy interpret(Object sequenceMismatchStrategy) {
if ( sequenceMismatchStrategy == null ) { if ( sequenceMismatchStrategy == null ) {
return EXCEPTION; return EXCEPTION;
} }

View File

@ -24,26 +24,20 @@ public class IntegratorServiceImpl implements IntegratorService {
private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>(); private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();
private IntegratorServiceImpl() { public IntegratorServiceImpl(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
}
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 // register standard integrators. Envers and JPA, for example, need to be handled by discovery because in
// separate project/jars. // separate project/jars.
instance.addIntegrator( new BeanValidationIntegrator() ); addIntegrator( new BeanValidationIntegrator() );
instance.addIntegrator( new CollectionCacheInvalidator() ); addIntegrator( new CollectionCacheInvalidator() );
// register provided integrators // register provided integrators
for ( Integrator integrator : providedIntegrators ) { for ( Integrator integrator : providedIntegrators ) {
instance.addIntegrator( integrator ); addIntegrator( integrator );
}
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
instance.addIntegrator( integrator );
} }
return instance; for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
addIntegrator( integrator );
}
} }
private void addIntegrator(Integrator integrator) { private void addIntegrator(Integrator integrator) {

View File

@ -592,6 +592,10 @@ public final class ConfigurationHelper {
@Override @Override
public Integer convert(Object value) { public Integer convert(Object value) {
if ( value == null ) {
throw new IllegalArgumentException( "Null value passed to convert" );
}
if ( value instanceof Number ) { if ( value instanceof Number ) {
return ( (Number) value ).intValue(); return ( (Number) value ).intValue();
} }

View File

@ -6,8 +6,6 @@
*/ */
package org.hibernate.service; package org.hibernate.service;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* A registry of {@linkplain Service services}. This interface abstracts * A registry of {@linkplain Service services}. This interface abstracts
* the operations of: * the operations of:
@ -29,7 +27,7 @@ public interface ServiceRegistry extends AutoCloseable {
* *
* @return The parent registry. May be null. * @return The parent registry. May be null.
*/ */
@Nullable ServiceRegistry getParentServiceRegistry(); ServiceRegistry getParentServiceRegistry();
/** /**
* Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is * Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is
@ -44,7 +42,7 @@ public interface ServiceRegistry extends AutoCloseable {
* *
* @throws UnknownServiceException Indicates the service was not known. * @throws UnknownServiceException Indicates the service was not known.
*/ */
<R extends Service> @Nullable R getService(Class<R> serviceRole); <R extends Service> R getService(Class<R> serviceRole);
/** /**
* Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is * Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is

View File

@ -35,8 +35,6 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.Startable; import org.hibernate.service.spi.Startable;
import org.hibernate.service.spi.Stoppable; import org.hibernate.service.spi.Stoppable;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Basic implementation of the {@link ServiceRegistry} and {@link ServiceRegistryImplementor} contracts. * Basic implementation of the {@link ServiceRegistry} and {@link ServiceRegistryImplementor} contracts.
* *
@ -50,7 +48,7 @@ public abstract class AbstractServiceRegistryImpl
public static final String ALLOW_CRAWLING = "hibernate.service.allow_crawling"; public static final String ALLOW_CRAWLING = "hibernate.service.allow_crawling";
private volatile @Nullable ServiceRegistryImplementor parent; private volatile ServiceRegistryImplementor parent;
private final boolean allowCrawling; private final boolean allowCrawling;
private final ConcurrentMap<Class<?>,ServiceBinding<?>> serviceBindingMap = new ConcurrentHashMap<>(); private final ConcurrentMap<Class<?>,ServiceBinding<?>> serviceBindingMap = new ConcurrentHashMap<>();
@ -72,17 +70,26 @@ public abstract class AbstractServiceRegistryImpl
private final AtomicBoolean active = new AtomicBoolean( true ); private final AtomicBoolean active = new AtomicBoolean( true );
protected AbstractServiceRegistryImpl(@Nullable ServiceRegistryImplementor parent) { protected AbstractServiceRegistryImpl() {
this( (ServiceRegistryImplementor) null );
}
protected AbstractServiceRegistryImpl(boolean autoCloseRegistry) {
this( (ServiceRegistryImplementor) null, autoCloseRegistry );
}
protected AbstractServiceRegistryImpl(ServiceRegistryImplementor parent) {
this( parent, true ); this( parent, true );
} }
protected AbstractServiceRegistryImpl( protected AbstractServiceRegistryImpl(
@Nullable ServiceRegistryImplementor parent, ServiceRegistryImplementor parent,
boolean autoCloseRegistry) { boolean autoCloseRegistry) {
this.parent = parent; this.parent = parent;
this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true ); this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );
this.autoCloseRegistry = autoCloseRegistry; this.autoCloseRegistry = autoCloseRegistry;
this.parent.registerChild( this );
} }
public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) { public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) {
@ -92,21 +99,15 @@ public abstract class AbstractServiceRegistryImpl
public AbstractServiceRegistryImpl( public AbstractServiceRegistryImpl(
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
boolean autoCloseRegistry) { boolean autoCloseRegistry) {
if ( !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor) ) { if ( !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor) ) {
throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" ); throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
} }
this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry; this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;
this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true ); this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );
this.autoCloseRegistry = autoCloseRegistry;
}
// For nullness checking purposes this.autoCloseRegistry = autoCloseRegistry;
protected void initialize() {
if ( this.parent != null ) {
this.parent.registerChild( this ); this.parent.registerChild( this );
} }
}
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) { protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
final ServiceBinding<?> serviceBinding = new ServiceBinding<>( this, initiator ); final ServiceBinding<?> serviceBinding = new ServiceBinding<>( this, initiator );
@ -127,17 +128,17 @@ public abstract class AbstractServiceRegistryImpl
} }
@Override @Override
public @Nullable ServiceRegistry getParentServiceRegistry() { public ServiceRegistry getParentServiceRegistry() {
return parent; return parent;
} }
@Override @Override
public <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) { public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
return locateServiceBinding( serviceRole, true ); return locateServiceBinding( serviceRole, true );
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) { protected <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) {
ServiceBinding<R> serviceBinding = (ServiceBinding<R>) serviceBindingMap.get( serviceRole ); ServiceBinding<R> serviceBinding = (ServiceBinding<R>) serviceBindingMap.get( serviceRole );
if ( serviceBinding == null && checkParent && parent != null ) { if ( serviceBinding == null && checkParent && parent != null ) {
// look in parent // look in parent
@ -183,7 +184,7 @@ public abstract class AbstractServiceRegistryImpl
} }
@Override @Override
public <R extends Service> @Nullable R getService(Class<R> serviceRole) { public <R extends Service> R getService(Class<R> serviceRole) {
//Fast-path for ClassLoaderService as it's extremely hot during bootstrap //Fast-path for ClassLoaderService as it's extremely hot during bootstrap
//(and after bootstrap service loading performance is less interesting as it's //(and after bootstrap service loading performance is less interesting as it's
//ideally being cached by long term consumers) //ideally being cached by long term consumers)
@ -229,7 +230,7 @@ public abstract class AbstractServiceRegistryImpl
} }
} }
private <R extends Service> @Nullable R initializeService(ServiceBinding<R> serviceBinding) { private <R extends Service> R initializeService(ServiceBinding<R> serviceBinding) {
if ( log.isTraceEnabled() ) { if ( log.isTraceEnabled() ) {
log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() ); log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() );
} }
@ -252,7 +253,7 @@ public abstract class AbstractServiceRegistryImpl
return service; return service;
} }
protected <R extends Service> @Nullable R createService(ServiceBinding<R> serviceBinding) { protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) {
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator(); final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
if ( serviceInitiator == null ) { if ( serviceInitiator == null ) {
// this condition should never ever occur // this condition should never ever occur
@ -370,12 +371,10 @@ public abstract class AbstractServiceRegistryImpl
serviceBindingMap.clear(); serviceBindingMap.clear();
} }
finally { finally {
if ( parent != null ) {
parent.deRegisterChild( this ); parent.deRegisterChild( this );
} }
} }
} }
}
@Override @Override
public synchronized <R extends Service> void stopService(ServiceBinding<R> binding) { public synchronized <R extends Service> void stopService(ServiceBinding<R> binding) {
@ -430,7 +429,7 @@ public abstract class AbstractServiceRegistryImpl
* Not intended for general use. We need the ability to stop and "reactivate" a registry to allow * Not intended for general use. We need the ability to stop and "reactivate" a registry to allow
* experimentation with technologies such as GraalVM, Quarkus and Cri-O. * experimentation with technologies such as GraalVM, Quarkus and Cri-O.
*/ */
public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParent) { public synchronized void resetParent(BootstrapServiceRegistry newParent) {
if ( this.parent != null ) { if ( this.parent != null ) {
this.parent.deRegisterChild( this ); this.parent.deRegisterChild( this );
} }
@ -447,14 +446,14 @@ public abstract class AbstractServiceRegistryImpl
} }
@Override @Override
public <T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole) { public <T extends Service> T fromRegistryOrChildren(Class<T> serviceRole) {
return fromRegistryOrChildren( serviceRole, this, childRegistries ); return fromRegistryOrChildren( serviceRole, this, childRegistries );
} }
public static <T extends Service> @Nullable T fromRegistryOrChildren( public static <T extends Service> T fromRegistryOrChildren(
Class<T> serviceRole, Class<T> serviceRole,
ServiceRegistryImplementor serviceRegistry, ServiceRegistryImplementor serviceRegistry,
@Nullable Set<ServiceRegistryImplementor> childRegistries) { Set<ServiceRegistryImplementor> childRegistries) {
// prefer `serviceRegistry` // prefer `serviceRegistry`
final T localService = serviceRegistry.getService( serviceRole ); final T localService = serviceRegistry.getService( serviceRole );
if ( localService != null ) { if ( localService != null ) {

View File

@ -60,7 +60,7 @@ public class SessionFactoryServiceRegistryBuilderImpl implements SessionFactoryS
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry( public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
SessionFactoryOptions options) { SessionFactoryOptions options) {
return SessionFactoryServiceRegistryImpl.create( return new SessionFactoryServiceRegistryImpl(
parent, parent,
initiators, initiators,
providedServices, providedServices,

View File

@ -9,7 +9,6 @@ package org.hibernate.service.internal;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.spi.SessionFactoryOptions; import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceContributor; import org.hibernate.service.spi.SessionFactoryServiceContributor;
import org.hibernate.service.spi.SessionFactoryServiceRegistry; import org.hibernate.service.spi.SessionFactoryServiceRegistry;
@ -32,7 +31,7 @@ public class SessionFactoryServiceRegistryFactoryImpl implements SessionFactoryS
public SessionFactoryServiceRegistry buildServiceRegistry( public SessionFactoryServiceRegistry buildServiceRegistry(
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
SessionFactoryOptions options) { SessionFactoryOptions options) {
final ClassLoaderService cls = NullnessUtil.castNonNull( options.getServiceRegistry().getService( ClassLoaderService.class ) ); final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry ); final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );
for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) { for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {

View File

@ -12,7 +12,6 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.event.service.spi.EventListenerRegistry; import org.hibernate.event.service.spi.EventListenerRegistry;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.hibernate.service.spi.Configurable; import org.hibernate.service.spi.Configurable;
import org.hibernate.service.spi.ServiceBinding; import org.hibernate.service.spi.ServiceBinding;
@ -24,8 +23,6 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@ -38,28 +35,17 @@ public class SessionFactoryServiceRegistryImpl
private final SessionFactoryOptions sessionFactoryOptions; private final SessionFactoryOptions sessionFactoryOptions;
private final SessionFactoryImplementor sessionFactory; private final SessionFactoryImplementor sessionFactory;
private SessionFactoryServiceRegistryImpl( public SessionFactoryServiceRegistryImpl(
ServiceRegistryImplementor parent,
SessionFactoryImplementor sessionFactory,
SessionFactoryOptions sessionFactoryOptions) {
super( parent );
this.sessionFactory = sessionFactory;
this.sessionFactoryOptions = sessionFactoryOptions;
}
public static SessionFactoryServiceRegistryImpl create(
ServiceRegistryImplementor parent, ServiceRegistryImplementor parent,
List<SessionFactoryServiceInitiator<?>> initiators, List<SessionFactoryServiceInitiator<?>> initiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
SessionFactoryImplementor sessionFactory, SessionFactoryImplementor sessionFactory,
SessionFactoryOptions sessionFactoryOptions) { SessionFactoryOptions sessionFactoryOptions) {
SessionFactoryServiceRegistryImpl instance = new SessionFactoryServiceRegistryImpl( parent, sessionFactory, sessionFactoryOptions); super( parent );
instance.initialize( initiators, providedServices );
return instance; this.sessionFactory = sessionFactory;
} this.sessionFactoryOptions = sessionFactoryOptions;
protected void initialize(List<SessionFactoryServiceInitiator<?>> initiators, List<ProvidedService<?>> providedServices) {
super.initialize();
// for now, just use the standard initiator list // for now, just use the standard initiator list
for ( SessionFactoryServiceInitiator<?> initiator : initiators ) { for ( SessionFactoryServiceInitiator<?> initiator : initiators ) {
// create the bindings up front to help identify to which registry services belong // create the bindings up front to help identify to which registry services belong
@ -80,7 +66,7 @@ public class SessionFactoryServiceRegistryImpl
@Override @Override
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) { public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
if ( serviceBinding.getService() instanceof Configurable ) { if ( serviceBinding.getService() instanceof Configurable ) {
( (Configurable) serviceBinding.getService() ).configure( NullnessUtil.castNonNull( getService( ConfigurationService.class ) ).getSettings() ); ( (Configurable) serviceBinding.getService() ).configure( getService( ConfigurationService.class ).getSettings() );
} }
} }
@ -100,7 +86,7 @@ public class SessionFactoryServiceRegistryImpl
} }
@Override @Override
public <R extends Service> @Nullable R getService(Class<R> serviceRole) { public <R extends Service> R getService(Class<R> serviceRole) {
if ( serviceRole.equals( EventListenerRegistry.class ) ) { if ( serviceRole.equals( EventListenerRegistry.class ) ) {
log.debug( log.debug(
"EventListenerRegistry access via ServiceRegistry is deprecated. " + "EventListenerRegistry access via ServiceRegistry is deprecated. " +

View File

@ -10,8 +10,6 @@ import org.hibernate.service.Service;
import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Models a binding for a particular service. * Models a binding for a particular service.
* *
@ -32,7 +30,7 @@ public final class ServiceBinding<R extends Service> {
private final ServiceLifecycleOwner lifecycleOwner; private final ServiceLifecycleOwner lifecycleOwner;
private final Class<R> serviceRole; private final Class<R> serviceRole;
private final @Nullable ServiceInitiator<R> serviceInitiator; private final ServiceInitiator<R> serviceInitiator;
private volatile R service; private volatile R service;
public ServiceBinding(ServiceLifecycleOwner lifecycleOwner, Class<R> serviceRole, R service) { public ServiceBinding(ServiceLifecycleOwner lifecycleOwner, Class<R> serviceRole, R service) {
@ -56,7 +54,7 @@ public final class ServiceBinding<R extends Service> {
return serviceRole; return serviceRole;
} }
public @Nullable ServiceInitiator<R> getServiceInitiator() { public ServiceInitiator<R> getServiceInitiator() {
return serviceInitiator; return serviceInitiator;
} }

View File

@ -9,8 +9,6 @@ package org.hibernate.service.spi;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistry;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Additional integration contracts for a service registry. * Additional integration contracts for a service registry.
* *
@ -25,7 +23,7 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
* *
* @return The located binding; may be {@code null} * @return The located binding; may be {@code null}
*/ */
<R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole); <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole);
@Override @Override
default void close() { default void close() {
@ -49,5 +47,5 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
*/ */
void deRegisterChild(ServiceRegistryImplementor child); void deRegisterChild(ServiceRegistryImplementor child);
<T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole); <T extends Service> T fromRegistryOrChildren(Class<T> serviceRole);
} }

View File

@ -11,7 +11,6 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.engine.config.spi.ConfigurationService; import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.NullnessUtil;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.hibernate.service.spi.SessionFactoryServiceInitiator; import org.hibernate.service.spi.SessionFactoryServiceInitiator;
import org.hibernate.service.spi.SessionFactoryServiceInitiatorContext; import org.hibernate.service.spi.SessionFactoryServiceInitiatorContext;
@ -43,8 +42,8 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
@Override @Override
public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) { public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) {
final Object configValue = NullnessUtil.castNonNull( context.getServiceRegistry() final Object configValue = context.getServiceRegistry()
.getService( ConfigurationService.class ) ) .getService( ConfigurationService.class )
.getSettings() .getSettings()
.get( STATS_BUILDER ); .get( STATS_BUILDER );
return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() ); return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() );
@ -64,7 +63,7 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
} }
else { else {
// assume it names the factory class // assume it names the factory class
final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) ); final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
try { try {
statisticsFactory = (StatisticsFactory) classLoaderService.classForName( configValue.toString() ).newInstance(); statisticsFactory = (StatisticsFactory) classLoaderService.classForName( configValue.toString() ).newInstance();
} }

View File

@ -12,8 +12,6 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.type.descriptor.java.ByteArrayJavaType; import org.hibernate.type.descriptor.java.ByteArrayJavaType;
import org.hibernate.type.descriptor.java.CharacterArrayJavaType; import org.hibernate.type.descriptor.java.CharacterArrayJavaType;
import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
* Possible options for how to handle {@code Byte[]} and {@code Character[]} basic mappings * Possible options for how to handle {@code Byte[]} and {@code Character[]} basic mappings
* encountered in the application domain model. * encountered in the application domain model.
@ -72,7 +70,7 @@ public enum WrapperArrayHandling {
* Form of {@link #interpretExternalSetting(Object)} which allows incoming {@code null} values and * Form of {@link #interpretExternalSetting(Object)} which allows incoming {@code null} values and
* simply returns {@code null}. Useful for chained resolutions * simply returns {@code null}. Useful for chained resolutions
*/ */
public static WrapperArrayHandling interpretExternalSettingLeniently(@Nullable Object value) { public static WrapperArrayHandling interpretExternalSettingLeniently(Object value) {
if ( value == null ) { if ( value == null ) {
return null; return null;
} }

View File

@ -9,11 +9,8 @@ package org.hibernate.orm.test.connection;
import java.sql.Connection; import java.sql.Connection;
import java.sql.Driver; import java.sql.Driver;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import org.hibernate.boot.registry.BootstrapServiceRegistry;
import org.hibernate.boot.registry.StandardServiceInitiator; import org.hibernate.boot.registry.StandardServiceInitiator;
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl; import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl; import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
@ -23,9 +20,9 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.exception.JDBCConnectionException; import org.hibernate.exception.JDBCConnectionException;
import org.hibernate.service.Service; import org.hibernate.service.Service;
import org.hibernate.service.internal.ProvidedService; import org.hibernate.service.internal.ProvidedService;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.testing.orm.junit.JiraKey;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -35,17 +32,27 @@ import static org.junit.Assert.fail;
*/ */
public class ConnectionCreatorTest extends BaseUnitTestCase { public class ConnectionCreatorTest extends BaseUnitTestCase {
@Test @Test
@JiraKey(value = "HHH-8621" ) @TestForIssue( jiraKey = "HHH-8621" )
public void testBadUrl() throws Exception { public void testBadUrl() throws Exception {
DriverConnectionCreator connectionCreator = new DriverConnectionCreator( DriverConnectionCreator connectionCreator = new DriverConnectionCreator(
(Driver) Class.forName( "org.h2.Driver" ).newInstance(), (Driver) Class.forName( "org.h2.Driver" ).newInstance(),
CCTStandardServiceRegistryImpl.create( new StandardServiceRegistryImpl(
true, true,
new BootstrapServiceRegistryImpl(), new BootstrapServiceRegistryImpl(),
Collections.emptyList(), Collections.emptyList(),
Collections.emptyList(), Collections.emptyList(),
Collections.emptyMap() Collections.emptyMap()
), ) {
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if ( JdbcServices.class.equals( serviceRole ) ) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService( serviceRole );
}
},
"jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat", "jdbc:h2:mem:test-bad-urls;nosuchparam=saywhat",
new Properties(), new Properties(),
false, false,
@ -61,37 +68,4 @@ public class ConnectionCreatorTest extends BaseUnitTestCase {
catch (JDBCConnectionException expected) { catch (JDBCConnectionException expected) {
} }
} }
private final static class CCTStandardServiceRegistryImpl extends StandardServiceRegistryImpl {
private CCTStandardServiceRegistryImpl(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String, Object> configurationValues) {
super( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
}
@Override
@SuppressWarnings("unchecked")
public <R extends Service> R getService(Class<R> serviceRole) {
if ( JdbcServices.class.equals( serviceRole ) ) {
// return a new, not fully initialized JdbcServicesImpl
return (R) new JdbcServicesImpl();
}
return super.getService( serviceRole );
}
public static CCTStandardServiceRegistryImpl create(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) {
CCTStandardServiceRegistryImpl instance = new CCTStandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );
return instance;
}
}
} }

View File

@ -85,7 +85,8 @@ public class HibernateQueryMetrics implements MeterBinder {
@Override @Override
public void bindTo(MeterRegistry meterRegistry) { public void bindTo(MeterRegistry meterRegistry) {
if ( sessionFactory instanceof SessionFactoryImplementor ) { if ( sessionFactory instanceof SessionFactoryImplementor ) {
EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getEventEngine().getListenerRegistry(); EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getServiceRegistry()
.getService( EventListenerRegistry.class );
MetricsEventHandler metricsEventHandler = new MetricsEventHandler( meterRegistry ); MetricsEventHandler metricsEventHandler = new MetricsEventHandler( meterRegistry );
eventListenerRegistry.appendListeners( EventType.POST_LOAD, metricsEventHandler ); eventListenerRegistry.appendListeners( EventType.POST_LOAD, metricsEventHandler );
} }

View File

@ -33,15 +33,8 @@ public class ServiceRegistryTestingImpl
extends StandardServiceRegistryImpl extends StandardServiceRegistryImpl
implements ServiceRegistryImplementor { implements ServiceRegistryImplementor {
private ServiceRegistryTestingImpl(
boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry,
Map<String, Object> configurationValues) {
super( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
}
public static ServiceRegistryTestingImpl forUnitTesting() { public static ServiceRegistryTestingImpl forUnitTesting() {
return ServiceRegistryTestingImpl.create( return new ServiceRegistryTestingImpl(
true, true,
new BootstrapServiceRegistryBuilder().build(), new BootstrapServiceRegistryBuilder().build(),
StandardServiceInitiators.LIST, StandardServiceInitiators.LIST,
@ -54,7 +47,7 @@ public class ServiceRegistryTestingImpl
} }
public static ServiceRegistryTestingImpl forUnitTesting(Map<String,Object> settings) { public static ServiceRegistryTestingImpl forUnitTesting(Map<String,Object> settings) {
return ServiceRegistryTestingImpl.create( return new ServiceRegistryTestingImpl(
true, true,
new BootstrapServiceRegistryBuilder().build(), new BootstrapServiceRegistryBuilder().build(),
StandardServiceInitiators.LIST, StandardServiceInitiators.LIST,
@ -77,17 +70,12 @@ public class ServiceRegistryTestingImpl
); );
} }
public static ServiceRegistryTestingImpl create( public ServiceRegistryTestingImpl(
boolean autoCloseRegistry, boolean autoCloseRegistry,
BootstrapServiceRegistry bootstrapServiceRegistry, BootstrapServiceRegistry bootstrapServiceRegistry,
List<StandardServiceInitiator<?>> serviceInitiators, List<StandardServiceInitiator<?>> serviceInitiators,
List<ProvidedService<?>> providedServices, List<ProvidedService<?>> providedServices,
Map<String,Object> configurationValues) { Map<String,Object> configurationValues) {
super( autoCloseRegistry, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
ServiceRegistryTestingImpl instance = new ServiceRegistryTestingImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
instance.initialize();
instance.applyServiceRegistrations( serviceInitiators, providedServices );
return instance;
} }
} }

View File

@ -150,7 +150,7 @@ public abstract class MockSessionFactory
public MockSessionFactory() { public MockSessionFactory() {
serviceRegistry = StandardServiceRegistryImpl.create( serviceRegistry = new StandardServiceRegistryImpl(
new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() { new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() {
@Override @Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")