HHH-16515 - Add o.h.exception to nullness checking
HHH-16515 - Add o.h.integrator to nullness checking HHH-16515 - Add o.h.service to nullness checking HHH-16515 - Add o.h.engine.jndi to nullness checking HHH-16515 - Add o.h.engine.config to nullness checking Signed-off-by: Jan Schatteman <jschatte@redhat.com>
This commit is contained in:
parent
781cdc8804
commit
c5c3bb8ac8
|
@ -544,7 +544,7 @@ checkerFramework {
|
|||
extraJavacArgs = [
|
||||
'-AsuppressWarnings=initialization',
|
||||
// stubs is passed directly through options.compilerArgumentProviders
|
||||
'-AonlyDefs=^org\\.hibernate\\.(jpamodelgen|spi|pretty|stat|engine\\.(profile|transaction)|(action|context|bytecode)\\.spi)\\.'
|
||||
'-AonlyDefs=^org\\.hibernate\\.(exception|integrator|jpamodelgen|service|spi|pretty|stat|engine\\.(config|jndi|profile|transaction)|(action|context|bytecode)\\.spi)\\.'
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -659,10 +659,6 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
this.sharedCacheMode = configService.getSetting(
|
||||
AvailableSettings.JAKARTA_SHARED_CACHE_MODE,
|
||||
value -> {
|
||||
if ( value == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ( value instanceof SharedCacheMode ) {
|
||||
return (SharedCacheMode) value;
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ public class BootstrapServiceRegistryBuilder {
|
|||
classLoaderService = providedClassLoaderService;
|
||||
}
|
||||
|
||||
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
|
||||
final IntegratorServiceImpl integratorService = IntegratorServiceImpl.create(
|
||||
providedIntegrators,
|
||||
classLoaderService
|
||||
);
|
||||
|
|
|
@ -365,7 +365,7 @@ public class StandardServiceRegistryBuilder {
|
|||
settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml );
|
||||
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
|
||||
|
||||
return new StandardServiceRegistryImpl(
|
||||
return StandardServiceRegistryImpl.create(
|
||||
autoCloseRegistry,
|
||||
bootstrapServiceRegistry,
|
||||
initiators,
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.hibernate.service.spi.ServiceInitiator;
|
|||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* {@link ServiceRegistry} implementation containing specialized "bootstrap" services, specifically:<ul>
|
||||
* <li>{@link ClassLoaderService}</li>
|
||||
|
@ -117,7 +119,7 @@ public class BootstrapServiceRegistryImpl
|
|||
this.integratorServiceBinding = new ServiceBinding<>(
|
||||
this,
|
||||
IntegratorService.class,
|
||||
new IntegratorServiceImpl( providedIntegrators, classLoaderService )
|
||||
IntegratorServiceImpl.create( providedIntegrators, classLoaderService )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -185,7 +187,7 @@ public class BootstrapServiceRegistryImpl
|
|||
|
||||
|
||||
@Override
|
||||
public <R extends Service> R getService(Class<R> serviceRole) {
|
||||
public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
|
||||
final ServiceBinding<R> binding = locateServiceBinding( serviceRole );
|
||||
return binding == null ? null : binding.getService();
|
||||
}
|
||||
|
@ -235,7 +237,7 @@ public class BootstrapServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public ServiceRegistry getParentServiceRegistry() {
|
||||
public @Nullable ServiceRegistry getParentServiceRegistry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,14 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
|||
//Access to this field requires synchronization on -this-
|
||||
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
|
||||
* {@link org.hibernate.boot.registry.StandardServiceRegistryBuilder} instead
|
||||
|
@ -41,12 +49,13 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
|||
*
|
||||
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
|
||||
*/
|
||||
public StandardServiceRegistryImpl(
|
||||
public static StandardServiceRegistryImpl create(
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
List<StandardServiceInitiator<?>> serviceInitiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
Map<String,Object> configurationValues) {
|
||||
this( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
|
||||
|
||||
return create( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,20 +71,21 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
|||
*
|
||||
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
|
||||
*/
|
||||
public StandardServiceRegistryImpl(
|
||||
public static StandardServiceRegistryImpl create(
|
||||
boolean autoCloseRegistry,
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
List<StandardServiceInitiator<?>> serviceInitiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
Map<String,Object> configurationValues) {
|
||||
super( bootstrapServiceRegistry, autoCloseRegistry );
|
||||
|
||||
this.configurationValues = configurationValues;
|
||||
StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
|
||||
instance.initialize();
|
||||
instance.applyServiceRegistrations( serviceInitiators, providedServices );
|
||||
|
||||
applyServiceRegistrations( serviceInitiators, providedServices );
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
|
||||
protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
|
||||
try {
|
||||
// process initiators
|
||||
for ( ServiceInitiator<?> initiator : serviceInitiators ) {
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.hibernate.cache.spi.access;
|
|||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Enumerates the policies for managing concurrent access to the shared
|
||||
* second-level cache.
|
||||
|
@ -70,7 +72,7 @@ public enum AccessType {
|
|||
*
|
||||
* @see #getExternalName()
|
||||
*/
|
||||
public static AccessType fromExternalName(String externalName) {
|
||||
public static AccessType fromExternalName(@Nullable String externalName) {
|
||||
if ( externalName == null ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,11 +13,15 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryAwareService;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.checker.nullness.qual.PolyNull;
|
||||
|
||||
/**
|
||||
* The standard {@link ConfigurationService} implementation.
|
||||
*
|
||||
|
@ -52,12 +56,12 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T getSetting(String name, Converter<T> converter) {
|
||||
public <T> @Nullable T getSetting(String name, Converter<T> converter) {
|
||||
return getSetting( name, converter, null );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getSetting(String name, Converter<T> converter, T defaultValue) {
|
||||
public <T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue) {
|
||||
final Object value = settings.get( name );
|
||||
if ( value == null ) {
|
||||
return defaultValue;
|
||||
|
@ -67,14 +71,14 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T> T getSetting(String name, Class<T> expected, T defaultValue) {
|
||||
public <T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue) {
|
||||
final Object value = settings.get( name );
|
||||
final T target = cast( expected, value );
|
||||
return target !=null ? target : defaultValue;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T cast(Class<T> expected, Object candidate){
|
||||
public <T> @Nullable T cast(Class<T> expected, @Nullable Object candidate){
|
||||
if (candidate == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -89,7 +93,7 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
|
|||
}
|
||||
else {
|
||||
try {
|
||||
target = serviceRegistry.getService( ClassLoaderService.class ).classForName( candidate.toString() );
|
||||
target = NullnessUtil.castNonNull( serviceRegistry.getService( ClassLoaderService.class ) ).classForName( candidate.toString() );
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() );
|
||||
|
|
|
@ -10,6 +10,10 @@ import java.util.Map;
|
|||
|
||||
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
|
||||
* these values come from:<ul>
|
||||
|
@ -38,7 +42,7 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @return The converted (typed) setting. May return {@code null} (see {@link #getSetting(String, Class, Object)})
|
||||
*/
|
||||
<T> T getSetting(String name, Converter<T> converter);
|
||||
<T> @Nullable T getSetting(String name, Converter<T> converter);
|
||||
|
||||
/**
|
||||
* Get the named setting, using the specified converter and default value.
|
||||
|
@ -50,7 +54,7 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
|
||||
*/
|
||||
<T> T getSetting(String name, Converter<T> converter, T defaultValue);
|
||||
<T> @PolyNull T getSetting(String name, Converter<T> converter, @PolyNull T defaultValue);
|
||||
|
||||
/**
|
||||
* Get the named setting. Differs from the form taking a Converter in that here we expect to have a simple
|
||||
|
@ -63,7 +67,7 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @return The converted (typed) setting. Will be the defaultValue if no such setting was defined.
|
||||
*/
|
||||
<T> T getSetting(String name, Class<T> expected, T defaultValue);
|
||||
<T> @PolyNull T getSetting(String name, Class<T> expected, @PolyNull T defaultValue);
|
||||
|
||||
/**
|
||||
* Simple conversion contract for converting an untyped object to a specified type.
|
||||
|
@ -78,6 +82,6 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @return The converted (typed) value.
|
||||
*/
|
||||
T convert(Object value);
|
||||
@NonNull T convert(Object value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.engine.config.spi;
|
||||
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.PolyNull;
|
||||
|
||||
import static org.hibernate.engine.config.spi.ConfigurationService.Converter;
|
||||
|
||||
/**
|
||||
|
@ -18,10 +20,6 @@ public class StandardConverters {
|
|||
public static final Converter<Boolean> BOOLEAN = StandardConverters::asBoolean;
|
||||
|
||||
public static Boolean asBoolean(Object value) {
|
||||
if ( value == null ) {
|
||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||
}
|
||||
|
||||
return value instanceof Boolean
|
||||
? (Boolean) value
|
||||
: Boolean.parseBoolean( value.toString() );
|
||||
|
@ -30,20 +28,12 @@ public class StandardConverters {
|
|||
public static final Converter<String> STRING = StandardConverters::asString;
|
||||
|
||||
public static String asString(Object value) {
|
||||
if ( value == null ) {
|
||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||
}
|
||||
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
public static final Converter<Integer> INTEGER = StandardConverters::asInteger;
|
||||
|
||||
public static Integer asInteger(Object value) {
|
||||
if ( value == null ) {
|
||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||
}
|
||||
|
||||
if ( value instanceof Number ) {
|
||||
return ( (Number) value ).intValue();
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.hibernate.engine.jndi.JndiException;
|
|||
import org.hibernate.engine.jndi.JndiNameException;
|
||||
import org.hibernate.engine.jndi.spi.JndiService;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
@ -80,7 +81,7 @@ final class JndiServiceImpl implements JndiService {
|
|||
}
|
||||
else {
|
||||
final String passThruPropertyName = propertyName.substring( Environment.JNDI_PREFIX.length() + 1 );
|
||||
jndiProperties.put( passThruPropertyName, propertyValue );
|
||||
jndiProperties.put( passThruPropertyName, NullnessUtil.castNonNull( propertyValue ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.hibernate.engine.jndi.spi.JndiService;
|
|||
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.JtaPlatformException;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.service.spi.Configurable;
|
||||
|
@ -63,7 +64,7 @@ public abstract class AbstractJtaPlatform
|
|||
}
|
||||
|
||||
protected JndiService jndiService() {
|
||||
return serviceRegistry().getService( JndiService.class );
|
||||
return NullnessUtil.castNonNull( serviceRegistry().getService( JndiService.class ) );
|
||||
}
|
||||
|
||||
protected abstract TransactionManager locateTransactionManager();
|
||||
|
|
|
@ -11,6 +11,7 @@ import jakarta.transaction.UserTransaction;
|
|||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
|
@ -21,7 +22,7 @@ public class AtomikosJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
Class transactionManagerClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
|
||||
Class transactionManagerClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME );
|
||||
return (TransactionManager) transactionManagerClass.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import jakarta.transaction.UserTransaction;
|
|||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -22,7 +23,7 @@ public class BitronixJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
Class transactionManagerServicesClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
|
||||
Class transactionManagerServicesClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME );
|
||||
final Method getTransactionManagerMethod = transactionManagerServicesClass.getMethod( "getTransactionManager" );
|
||||
return (TransactionManager) getTransactionManagerMethod.invoke( null );
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import jakarta.transaction.UserTransaction;
|
|||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
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
|
||||
|
@ -37,8 +38,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
}
|
||||
|
||||
try {
|
||||
final Class jbossTmClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
final Class jbossTmClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
.classForName( JBOSS_TM_CLASS_NAME );
|
||||
return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
|
||||
}
|
||||
|
@ -58,8 +59,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
}
|
||||
|
||||
try {
|
||||
final Class jbossUtClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
.classForName( JBOSS_UT_CLASS_NAME );
|
||||
return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import jakarta.transaction.UserTransaction;
|
|||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformException;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -23,7 +24,7 @@ public class JOTMJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class tmClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
|
||||
final Class tmClass = NullnessUtil.castNonNull( serviceRegistry().getService( ClassLoaderService.class ) ).classForName( TM_CLASS_NAME );
|
||||
final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" );
|
||||
return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null );
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -38,11 +39,11 @@ public class JtaPlatformInitiator implements StandardServiceInitiator<JtaPlatfor
|
|||
@Override
|
||||
public @Nullable JtaPlatform initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
|
||||
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM );
|
||||
JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
|
||||
JtaPlatform platform = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) ).resolveStrategy( JtaPlatform.class, setting );
|
||||
|
||||
if ( platform == null ) {
|
||||
LOG.debug( "No JtaPlatform was specified, checking resolver" );
|
||||
platform = registry.getService( JtaPlatformResolver.class ).resolveJtaPlatform( configurationValues, registry );
|
||||
platform = NullnessUtil.castNonNull( registry.getService( JtaPlatformResolver.class ) ).resolveJtaPlatform( configurationValues, registry );
|
||||
}
|
||||
|
||||
if ( platform == null ) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.hibernate.boot.registry.StandardServiceInitiator;
|
|||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -27,7 +28,7 @@ public class JtaPlatformResolverInitiator implements StandardServiceInitiator<Jt
|
|||
@Override
|
||||
public JtaPlatformResolver initiateService(Map<String, Object> configurationValues, ServiceRegistryImplementor registry) {
|
||||
final Object setting = configurationValues.get( AvailableSettings.JTA_PLATFORM_RESOLVER );
|
||||
final JtaPlatformResolver resolver = registry.getService( StrategySelector.class )
|
||||
final JtaPlatformResolver resolver = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) )
|
||||
.resolveStrategy( JtaPlatformResolver.class, setting );
|
||||
if ( resolver == null ) {
|
||||
log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() );
|
||||
|
|
|
@ -13,6 +13,7 @@ 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.JtaPlatformProvider;
|
||||
import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatformResolver;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -27,7 +28,7 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
|
|||
|
||||
@Override
|
||||
public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) {
|
||||
final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
|
||||
final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) );
|
||||
|
||||
// Initially look for a JtaPlatformProvider
|
||||
for ( JtaPlatformProvider provider : classLoaderService.loadJavaServices( JtaPlatformProvider.class ) ) {
|
||||
|
|
|
@ -34,8 +34,8 @@ public class WebSphereLibertyJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class<?> TransactionManagerFactory = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
final Class<?> TransactionManagerFactory = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
.classForName( TMF_CLASS_NAME );
|
||||
return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import jakarta.transaction.UserTransaction;
|
|||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
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
|
||||
|
@ -25,8 +26,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class wildflyTmClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
final Class wildflyTmClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
.classForName( WILDFLY_TM_CLASS_NAME );
|
||||
return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
|
||||
}
|
||||
|
@ -41,8 +42,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected UserTransaction locateUserTransaction() {
|
||||
try {
|
||||
final Class jbossUtClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
.classForName( WILDFLY_UT_CLASS_NAME );
|
||||
return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null );
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import java.sql.SQLException;
|
|||
|
||||
import org.hibernate.JDBCException;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link JDBCException} indicating that the requested DML operation
|
||||
* resulted in violation of a defined integrity constraint.
|
||||
|
@ -17,14 +19,14 @@ import org.hibernate.JDBCException;
|
|||
*/
|
||||
public class ConstraintViolationException extends JDBCException {
|
||||
|
||||
private final String constraintName;
|
||||
private final @Nullable String constraintName;
|
||||
|
||||
public ConstraintViolationException(String message, SQLException root, String constraintName) {
|
||||
public ConstraintViolationException(String message, SQLException root, @Nullable String constraintName) {
|
||||
super( message, root );
|
||||
this.constraintName = constraintName;
|
||||
}
|
||||
|
||||
public ConstraintViolationException(String message, SQLException root, String sql, String constraintName) {
|
||||
public ConstraintViolationException(String message, SQLException root, String sql, @Nullable String constraintName) {
|
||||
super( message, root, sql );
|
||||
this.constraintName = constraintName;
|
||||
}
|
||||
|
@ -34,7 +36,7 @@ public class ConstraintViolationException extends JDBCException {
|
|||
*
|
||||
* @return The name of the violated constraint, or null if not known.
|
||||
*/
|
||||
public String getConstraintName() {
|
||||
public @Nullable String getConstraintName() {
|
||||
return constraintName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,6 +28,8 @@ import org.hibernate.exception.SQLGrammarException;
|
|||
import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate;
|
||||
import org.hibernate.exception.spi.ConversionContext;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link org.hibernate.exception.spi.SQLExceptionConverter} implementation
|
||||
* that does conversion based on the {@link SQLException} subtype hierarchy
|
||||
|
@ -41,7 +43,7 @@ public class SQLExceptionTypeDelegate extends AbstractSQLExceptionConversionDele
|
|||
}
|
||||
|
||||
@Override
|
||||
public JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
if ( sqlException instanceof SQLClientInfoException
|
||||
|| sqlException instanceof SQLInvalidAuthorizationSpecException
|
||||
|| sqlException instanceof SQLNonTransientConnectionException
|
||||
|
|
|
@ -21,6 +21,8 @@ import org.hibernate.exception.spi.AbstractSQLExceptionConversionDelegate;
|
|||
import org.hibernate.exception.spi.ConversionContext;
|
||||
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
|
||||
* on the underlying SQLState. Interpretation of a SQL error based on SQLState is not nearly as accurate as
|
||||
|
@ -77,7 +79,7 @@ public class SQLStateConversionDelegate extends AbstractSQLExceptionConversionDe
|
|||
}
|
||||
|
||||
@Override
|
||||
public JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
final String sqlState = JdbcExceptionHelper.extractSqlState( sqlException );
|
||||
final int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* A {@link SQLExceptionConverter} that delegates to a chain of
|
||||
* {@link SQLExceptionConversionDelegate}.
|
||||
|
@ -44,7 +46,7 @@ public class StandardSQLExceptionConverter implements SQLExceptionConverter {
|
|||
* @deprecated use {@link #StandardSQLExceptionConverter(SQLExceptionConversionDelegate...)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
public void addDelegate(SQLExceptionConversionDelegate delegate) {
|
||||
public void addDelegate(@Nullable SQLExceptionConversionDelegate delegate) {
|
||||
if ( delegate != null ) {
|
||||
this.delegates.add( delegate );
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import java.sql.SQLException;
|
|||
|
||||
import org.hibernate.JDBCException;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Allow a {@link SQLExceptionConverter} to work by chaining together
|
||||
* multiple delegates. The main difference between a delegate and a
|
||||
|
@ -31,6 +33,6 @@ public interface SQLExceptionConversionDelegate {
|
|||
* if this delegate does not know how to interpret the
|
||||
* given {@link SQLException}.
|
||||
*/
|
||||
JDBCException convert(SQLException sqlException, String message, String sql);
|
||||
@Nullable JDBCException convert(SQLException sqlException, String message, String sql);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,10 @@ package org.hibernate.exception.spi;
|
|||
import java.sql.SQLException;
|
||||
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
|
||||
* by matching the error message against a template.
|
||||
|
@ -25,7 +29,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
|
|||
}
|
||||
|
||||
@Override
|
||||
public String extractConstraintName(SQLException sqle) {
|
||||
public @Nullable String extractConstraintName(SQLException sqle) {
|
||||
try {
|
||||
String constraintName = null;
|
||||
|
||||
|
@ -37,7 +41,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
|
|||
break;
|
||||
}
|
||||
else {
|
||||
sqle = sqle.getNextException();
|
||||
sqle = NullnessUtil.castNonNull( sqle.getNextException() );
|
||||
}
|
||||
} while (constraintName == null);
|
||||
|
||||
|
@ -57,7 +61,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
|
|||
* @param message The templated error message containing the constraint name.
|
||||
* @return The found constraint name, or null.
|
||||
*/
|
||||
public static String extractUsingTemplate(String templateStart, String templateEnd, String message) {
|
||||
public static @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message) {
|
||||
int templateStartPosition = message.indexOf( templateStart );
|
||||
if ( templateStartPosition < 0 ) {
|
||||
return null;
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.hibernate.exception.spi;
|
|||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* An object that can extract the name of a violated database constraint
|
||||
* from a {@link SQLException} that results from the constraint violation.
|
||||
|
@ -23,5 +25,5 @@ public interface ViolatedConstraintNameExtractor {
|
|||
* @param sqle The exception that was the result of the constraint violation.
|
||||
* @return The extracted constraint name.
|
||||
*/
|
||||
String extractConstraintName(SQLException sqle);
|
||||
@Nullable String extractConstraintName(SQLException sqle);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@ package org.hibernate.id;
|
|||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Describes the strategy for handling the mismatch between a database sequence configuration and
|
||||
* the one defined by the entity mapping.
|
||||
|
@ -53,7 +55,7 @@ public enum SequenceMismatchStrategy {
|
|||
*
|
||||
* @return associated {@link SequenceMismatchStrategy} object
|
||||
*/
|
||||
public static SequenceMismatchStrategy interpret(Object sequenceMismatchStrategy) {
|
||||
public static SequenceMismatchStrategy interpret(@Nullable Object sequenceMismatchStrategy) {
|
||||
if ( sequenceMismatchStrategy == null ) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
|
|
@ -24,20 +24,26 @@ public class IntegratorServiceImpl implements IntegratorService {
|
|||
|
||||
private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();
|
||||
|
||||
public IntegratorServiceImpl(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
|
||||
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.
|
||||
addIntegrator( new BeanValidationIntegrator() );
|
||||
addIntegrator( new CollectionCacheInvalidator() );
|
||||
instance.addIntegrator( new BeanValidationIntegrator() );
|
||||
instance.addIntegrator( new CollectionCacheInvalidator() );
|
||||
|
||||
// register provided integrators
|
||||
for ( Integrator integrator : providedIntegrators ) {
|
||||
addIntegrator( integrator );
|
||||
instance.addIntegrator( integrator );
|
||||
}
|
||||
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
|
||||
instance.addIntegrator( integrator );
|
||||
}
|
||||
|
||||
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
|
||||
addIntegrator( integrator );
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void addIntegrator(Integrator integrator) {
|
||||
|
|
|
@ -592,10 +592,6 @@ public final class ConfigurationHelper {
|
|||
|
||||
@Override
|
||||
public Integer convert(Object value) {
|
||||
if ( value == null ) {
|
||||
throw new IllegalArgumentException( "Null value passed to convert" );
|
||||
}
|
||||
|
||||
if ( value instanceof Number ) {
|
||||
return ( (Number) value ).intValue();
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.service;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* A registry of {@linkplain Service services}. This interface abstracts
|
||||
* the operations of:
|
||||
|
@ -27,7 +29,7 @@ public interface ServiceRegistry extends AutoCloseable {
|
|||
*
|
||||
* @return The parent registry. May be null.
|
||||
*/
|
||||
ServiceRegistry getParentServiceRegistry();
|
||||
@Nullable ServiceRegistry getParentServiceRegistry();
|
||||
|
||||
/**
|
||||
* Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is
|
||||
|
@ -42,7 +44,7 @@ public interface ServiceRegistry extends AutoCloseable {
|
|||
*
|
||||
* @throws UnknownServiceException Indicates the service was not known.
|
||||
*/
|
||||
<R extends Service> R getService(Class<R> serviceRole);
|
||||
<R extends Service> @Nullable R getService(Class<R> serviceRole);
|
||||
|
||||
/**
|
||||
* Retrieve a service by role. If service is not found, but a {@link org.hibernate.service.spi.ServiceInitiator} is
|
||||
|
|
|
@ -35,6 +35,8 @@ import org.hibernate.service.spi.ServiceRegistryImplementor;
|
|||
import org.hibernate.service.spi.Startable;
|
||||
import org.hibernate.service.spi.Stoppable;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Basic implementation of the {@link ServiceRegistry} and {@link ServiceRegistryImplementor} contracts.
|
||||
*
|
||||
|
@ -48,7 +50,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
|
||||
public static final String ALLOW_CRAWLING = "hibernate.service.allow_crawling";
|
||||
|
||||
private volatile ServiceRegistryImplementor parent;
|
||||
private volatile @Nullable ServiceRegistryImplementor parent;
|
||||
private final boolean allowCrawling;
|
||||
|
||||
private final ConcurrentMap<Class<?>,ServiceBinding<?>> serviceBindingMap = new ConcurrentHashMap<>();
|
||||
|
@ -70,26 +72,17 @@ public abstract class AbstractServiceRegistryImpl
|
|||
|
||||
private final AtomicBoolean active = new AtomicBoolean( true );
|
||||
|
||||
protected AbstractServiceRegistryImpl() {
|
||||
this( (ServiceRegistryImplementor) null );
|
||||
}
|
||||
|
||||
protected AbstractServiceRegistryImpl(boolean autoCloseRegistry) {
|
||||
this( (ServiceRegistryImplementor) null, autoCloseRegistry );
|
||||
}
|
||||
|
||||
protected AbstractServiceRegistryImpl(ServiceRegistryImplementor parent) {
|
||||
protected AbstractServiceRegistryImpl(@Nullable ServiceRegistryImplementor parent) {
|
||||
this( parent, true );
|
||||
}
|
||||
|
||||
protected AbstractServiceRegistryImpl(
|
||||
ServiceRegistryImplementor parent,
|
||||
@Nullable ServiceRegistryImplementor parent,
|
||||
boolean autoCloseRegistry) {
|
||||
|
||||
this.parent = parent;
|
||||
this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );
|
||||
|
||||
this.autoCloseRegistry = autoCloseRegistry;
|
||||
this.parent.registerChild( this );
|
||||
}
|
||||
|
||||
public AbstractServiceRegistryImpl(BootstrapServiceRegistry bootstrapServiceRegistry) {
|
||||
|
@ -99,14 +92,20 @@ public abstract class AbstractServiceRegistryImpl
|
|||
public AbstractServiceRegistryImpl(
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
boolean autoCloseRegistry) {
|
||||
|
||||
if ( !(bootstrapServiceRegistry instanceof ServiceRegistryImplementor) ) {
|
||||
throw new IllegalArgumentException( "ServiceRegistry parent needs to implement ServiceRegistryImplementor" );
|
||||
}
|
||||
this.parent = (ServiceRegistryImplementor) bootstrapServiceRegistry;
|
||||
this.allowCrawling = ConfigurationHelper.getBoolean( ALLOW_CRAWLING, Environment.getProperties(), true );
|
||||
|
||||
this.autoCloseRegistry = autoCloseRegistry;
|
||||
this.parent.registerChild( this );
|
||||
}
|
||||
|
||||
// For nullness checking purposes
|
||||
protected void initialize() {
|
||||
if ( this.parent != null ) {
|
||||
this.parent.registerChild( this );
|
||||
}
|
||||
}
|
||||
|
||||
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
|
||||
|
@ -128,17 +127,17 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public ServiceRegistry getParentServiceRegistry() {
|
||||
public @Nullable ServiceRegistry getParentServiceRegistry() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
|
||||
public <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole) {
|
||||
return locateServiceBinding( serviceRole, true );
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) {
|
||||
protected <R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole, boolean checkParent) {
|
||||
ServiceBinding<R> serviceBinding = (ServiceBinding<R>) serviceBindingMap.get( serviceRole );
|
||||
if ( serviceBinding == null && checkParent && parent != null ) {
|
||||
// look in parent
|
||||
|
@ -184,7 +183,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public <R extends Service> R getService(Class<R> serviceRole) {
|
||||
public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
|
||||
//Fast-path for ClassLoaderService as it's extremely hot during bootstrap
|
||||
//(and after bootstrap service loading performance is less interesting as it's
|
||||
//ideally being cached by long term consumers)
|
||||
|
@ -230,7 +229,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
}
|
||||
|
||||
private <R extends Service> R initializeService(ServiceBinding<R> serviceBinding) {
|
||||
private <R extends Service> @Nullable R initializeService(ServiceBinding<R> serviceBinding) {
|
||||
if ( log.isTraceEnabled() ) {
|
||||
log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() );
|
||||
}
|
||||
|
@ -253,7 +252,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
return service;
|
||||
}
|
||||
|
||||
protected <R extends Service> R createService(ServiceBinding<R> serviceBinding) {
|
||||
protected <R extends Service> @Nullable R createService(ServiceBinding<R> serviceBinding) {
|
||||
final ServiceInitiator<R> serviceInitiator = serviceBinding.getServiceInitiator();
|
||||
if ( serviceInitiator == null ) {
|
||||
// this condition should never ever occur
|
||||
|
@ -371,7 +370,9 @@ public abstract class AbstractServiceRegistryImpl
|
|||
serviceBindingMap.clear();
|
||||
}
|
||||
finally {
|
||||
parent.deRegisterChild( this );
|
||||
if ( parent != null ) {
|
||||
parent.deRegisterChild( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -429,7 +430,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
* 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.
|
||||
*/
|
||||
public synchronized void resetParent(BootstrapServiceRegistry newParent) {
|
||||
public synchronized void resetParent(@Nullable BootstrapServiceRegistry newParent) {
|
||||
if ( this.parent != null ) {
|
||||
this.parent.deRegisterChild( this );
|
||||
}
|
||||
|
@ -446,14 +447,14 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public <T extends Service> T fromRegistryOrChildren(Class<T> serviceRole) {
|
||||
public <T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole) {
|
||||
return fromRegistryOrChildren( serviceRole, this, childRegistries );
|
||||
}
|
||||
|
||||
public static <T extends Service> T fromRegistryOrChildren(
|
||||
public static <T extends Service> @Nullable T fromRegistryOrChildren(
|
||||
Class<T> serviceRole,
|
||||
ServiceRegistryImplementor serviceRegistry,
|
||||
Set<ServiceRegistryImplementor> childRegistries) {
|
||||
@Nullable Set<ServiceRegistryImplementor> childRegistries) {
|
||||
// prefer `serviceRegistry`
|
||||
final T localService = serviceRegistry.getService( serviceRole );
|
||||
if ( localService != null ) {
|
||||
|
|
|
@ -60,7 +60,7 @@ public class SessionFactoryServiceRegistryBuilderImpl implements SessionFactoryS
|
|||
public SessionFactoryServiceRegistry buildSessionFactoryServiceRegistry(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryOptions options) {
|
||||
return new SessionFactoryServiceRegistryImpl(
|
||||
return SessionFactoryServiceRegistryImpl.create(
|
||||
parent,
|
||||
initiators,
|
||||
providedServices,
|
||||
|
|
|
@ -9,6 +9,7 @@ package org.hibernate.service.internal;
|
|||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceContributor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
||||
|
@ -31,7 +32,7 @@ public class SessionFactoryServiceRegistryFactoryImpl implements SessionFactoryS
|
|||
public SessionFactoryServiceRegistry buildServiceRegistry(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryOptions options) {
|
||||
final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
|
||||
final ClassLoaderService cls = NullnessUtil.castNonNull( options.getServiceRegistry().getService( ClassLoaderService.class ) );
|
||||
final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );
|
||||
|
||||
for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.hibernate.boot.spi.SessionFactoryOptions;
|
|||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.spi.Configurable;
|
||||
import org.hibernate.service.spi.ServiceBinding;
|
||||
|
@ -23,6 +24,8 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -35,17 +38,28 @@ public class SessionFactoryServiceRegistryImpl
|
|||
private final SessionFactoryOptions sessionFactoryOptions;
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
public SessionFactoryServiceRegistryImpl(
|
||||
private SessionFactoryServiceRegistryImpl(
|
||||
ServiceRegistryImplementor parent,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryOptions sessionFactoryOptions) {
|
||||
super( parent );
|
||||
this.sessionFactory = sessionFactory;
|
||||
this.sessionFactoryOptions = sessionFactoryOptions;
|
||||
}
|
||||
|
||||
public static SessionFactoryServiceRegistryImpl create(
|
||||
ServiceRegistryImplementor parent,
|
||||
List<SessionFactoryServiceInitiator<?>> initiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryOptions sessionFactoryOptions) {
|
||||
super( parent );
|
||||
|
||||
this.sessionFactory = sessionFactory;
|
||||
this.sessionFactoryOptions = sessionFactoryOptions;
|
||||
SessionFactoryServiceRegistryImpl instance = new SessionFactoryServiceRegistryImpl( parent, sessionFactory, sessionFactoryOptions);
|
||||
instance.initialize( initiators, providedServices );
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected void initialize(List<SessionFactoryServiceInitiator<?>> initiators, List<ProvidedService<?>> providedServices) {
|
||||
super.initialize();
|
||||
// for now, just use the standard initiator list
|
||||
for ( SessionFactoryServiceInitiator<?> initiator : initiators ) {
|
||||
// create the bindings up front to help identify to which registry services belong
|
||||
|
@ -66,7 +80,7 @@ public class SessionFactoryServiceRegistryImpl
|
|||
@Override
|
||||
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
|
||||
if ( serviceBinding.getService() instanceof Configurable ) {
|
||||
( (Configurable) serviceBinding.getService() ).configure( getService( ConfigurationService.class ).getSettings() );
|
||||
( (Configurable) serviceBinding.getService() ).configure( NullnessUtil.castNonNull( getService( ConfigurationService.class ) ).getSettings() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +100,7 @@ public class SessionFactoryServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public <R extends Service> R getService(Class<R> serviceRole) {
|
||||
public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
|
||||
if ( serviceRole.equals( EventListenerRegistry.class ) ) {
|
||||
log.debug(
|
||||
"EventListenerRegistry access via ServiceRegistry is deprecated. " +
|
||||
|
|
|
@ -10,6 +10,8 @@ import org.hibernate.service.Service;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Models a binding for a particular service.
|
||||
*
|
||||
|
@ -30,7 +32,7 @@ public final class ServiceBinding<R extends Service> {
|
|||
|
||||
private final ServiceLifecycleOwner lifecycleOwner;
|
||||
private final Class<R> serviceRole;
|
||||
private final ServiceInitiator<R> serviceInitiator;
|
||||
private final @Nullable ServiceInitiator<R> serviceInitiator;
|
||||
private volatile R service;
|
||||
|
||||
public ServiceBinding(ServiceLifecycleOwner lifecycleOwner, Class<R> serviceRole, R service) {
|
||||
|
@ -54,7 +56,7 @@ public final class ServiceBinding<R extends Service> {
|
|||
return serviceRole;
|
||||
}
|
||||
|
||||
public ServiceInitiator<R> getServiceInitiator() {
|
||||
public @Nullable ServiceInitiator<R> getServiceInitiator() {
|
||||
return serviceInitiator;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,8 @@ package org.hibernate.service.spi;
|
|||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Additional integration contracts for a service registry.
|
||||
*
|
||||
|
@ -23,7 +25,7 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
|
|||
*
|
||||
* @return The located binding; may be {@code null}
|
||||
*/
|
||||
<R extends Service> ServiceBinding<R> locateServiceBinding(Class<R> serviceRole);
|
||||
<R extends Service> @Nullable ServiceBinding<R> locateServiceBinding(Class<R> serviceRole);
|
||||
|
||||
@Override
|
||||
default void close() {
|
||||
|
@ -47,5 +49,5 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
|
|||
*/
|
||||
void deRegisterChild(ServiceRegistryImplementor child);
|
||||
|
||||
<T extends Service> T fromRegistryOrChildren(Class<T> serviceRole);
|
||||
<T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole);
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
|||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceInitiator;
|
||||
import org.hibernate.service.spi.SessionFactoryServiceInitiatorContext;
|
||||
|
@ -42,8 +43,8 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
|
|||
|
||||
@Override
|
||||
public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) {
|
||||
final Object configValue = context.getServiceRegistry()
|
||||
.getService( ConfigurationService.class )
|
||||
final Object configValue = NullnessUtil.castNonNull( context.getServiceRegistry()
|
||||
.getService( ConfigurationService.class ) )
|
||||
.getSettings()
|
||||
.get( STATS_BUILDER );
|
||||
return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() );
|
||||
|
@ -63,7 +64,7 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
|
|||
}
|
||||
else {
|
||||
// assume it names the factory class
|
||||
final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
|
||||
final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) );
|
||||
try {
|
||||
statisticsFactory = (StatisticsFactory) classLoaderService.classForName( configValue.toString() ).newInstance();
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@ import org.hibernate.cfg.AvailableSettings;
|
|||
import org.hibernate.type.descriptor.java.ByteArrayJavaType;
|
||||
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
|
||||
* encountered in the application domain model.
|
||||
|
@ -70,7 +72,7 @@ public enum WrapperArrayHandling {
|
|||
* Form of {@link #interpretExternalSetting(Object)} which allows incoming {@code null} values and
|
||||
* simply returns {@code null}. Useful for chained resolutions
|
||||
*/
|
||||
public static WrapperArrayHandling interpretExternalSettingLeniently(Object value) {
|
||||
public static WrapperArrayHandling interpretExternalSettingLeniently(@Nullable Object value) {
|
||||
if ( value == null ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -9,8 +9,11 @@ package org.hibernate.orm.test.connection;
|
|||
import java.sql.Connection;
|
||||
import java.sql.Driver;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceInitiator;
|
||||
import org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl;
|
||||
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
|
||||
|
@ -20,9 +23,9 @@ import org.hibernate.engine.jdbc.spi.JdbcServices;
|
|||
import org.hibernate.exception.JDBCConnectionException;
|
||||
import org.hibernate.service.Service;
|
||||
import org.hibernate.service.internal.ProvidedService;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.hibernate.testing.orm.junit.JiraKey;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
@ -32,27 +35,17 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
public class ConnectionCreatorTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-8621" )
|
||||
@JiraKey(value = "HHH-8621" )
|
||||
public void testBadUrl() throws Exception {
|
||||
DriverConnectionCreator connectionCreator = new DriverConnectionCreator(
|
||||
(Driver) Class.forName( "org.h2.Driver" ).newInstance(),
|
||||
new StandardServiceRegistryImpl(
|
||||
CCTStandardServiceRegistryImpl.create(
|
||||
true,
|
||||
new BootstrapServiceRegistryImpl(),
|
||||
Collections.emptyList(),
|
||||
Collections.emptyList(),
|
||||
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",
|
||||
new Properties(),
|
||||
false,
|
||||
|
@ -68,4 +61,37 @@ public class ConnectionCreatorTest extends BaseUnitTestCase {
|
|||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,8 +85,7 @@ public class HibernateQueryMetrics implements MeterBinder {
|
|||
@Override
|
||||
public void bindTo(MeterRegistry meterRegistry) {
|
||||
if ( sessionFactory instanceof SessionFactoryImplementor ) {
|
||||
EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getServiceRegistry()
|
||||
.getService( EventListenerRegistry.class );
|
||||
EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getEventEngine().getListenerRegistry();
|
||||
MetricsEventHandler metricsEventHandler = new MetricsEventHandler( meterRegistry );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_LOAD, metricsEventHandler );
|
||||
}
|
||||
|
|
|
@ -33,8 +33,15 @@ public class ServiceRegistryTestingImpl
|
|||
extends StandardServiceRegistryImpl
|
||||
implements ServiceRegistryImplementor {
|
||||
|
||||
private ServiceRegistryTestingImpl(
|
||||
boolean autoCloseRegistry,
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
Map<String, Object> configurationValues) {
|
||||
super( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
|
||||
}
|
||||
|
||||
public static ServiceRegistryTestingImpl forUnitTesting() {
|
||||
return new ServiceRegistryTestingImpl(
|
||||
return ServiceRegistryTestingImpl.create(
|
||||
true,
|
||||
new BootstrapServiceRegistryBuilder().build(),
|
||||
StandardServiceInitiators.LIST,
|
||||
|
@ -47,7 +54,7 @@ public class ServiceRegistryTestingImpl
|
|||
}
|
||||
|
||||
public static ServiceRegistryTestingImpl forUnitTesting(Map<String,Object> settings) {
|
||||
return new ServiceRegistryTestingImpl(
|
||||
return ServiceRegistryTestingImpl.create(
|
||||
true,
|
||||
new BootstrapServiceRegistryBuilder().build(),
|
||||
StandardServiceInitiators.LIST,
|
||||
|
@ -70,12 +77,17 @@ public class ServiceRegistryTestingImpl
|
|||
);
|
||||
}
|
||||
|
||||
public ServiceRegistryTestingImpl(
|
||||
public static ServiceRegistryTestingImpl create(
|
||||
boolean autoCloseRegistry,
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
List<StandardServiceInitiator<?>> serviceInitiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ public abstract class MockSessionFactory
|
|||
|
||||
public MockSessionFactory() {
|
||||
|
||||
serviceRegistry = new StandardServiceRegistryImpl(
|
||||
serviceRegistry = StandardServiceRegistryImpl.create(
|
||||
new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue