Revert "HHH-16515 - Add o.h.exception to nullness checking"
This reverts commit c5c3bb8ac8
.
This commit is contained in:
parent
06ed2072ce
commit
314f2d7b7a
|
@ -544,7 +544,7 @@ checkerFramework {
|
|||
extraJavacArgs = [
|
||||
'-AsuppressWarnings=initialization',
|
||||
// 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)\\.'
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -659,6 +659,10 @@ 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 = IntegratorServiceImpl.create(
|
||||
final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(
|
||||
providedIntegrators,
|
||||
classLoaderService
|
||||
);
|
||||
|
|
|
@ -365,7 +365,7 @@ public class StandardServiceRegistryBuilder {
|
|||
settingsCopy.put( LOADED_CONFIG_KEY, aggregatedCfgXml );
|
||||
ConfigurationHelper.resolvePlaceHolders( settingsCopy );
|
||||
|
||||
return StandardServiceRegistryImpl.create(
|
||||
return new StandardServiceRegistryImpl(
|
||||
autoCloseRegistry,
|
||||
bootstrapServiceRegistry,
|
||||
initiators,
|
||||
|
|
|
@ -29,8 +29,6 @@ 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>
|
||||
|
@ -119,7 +117,7 @@ public class BootstrapServiceRegistryImpl
|
|||
this.integratorServiceBinding = new ServiceBinding<>(
|
||||
this,
|
||||
IntegratorService.class,
|
||||
IntegratorServiceImpl.create( providedIntegrators, classLoaderService )
|
||||
new IntegratorServiceImpl( providedIntegrators, classLoaderService )
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -187,7 +185,7 @@ public class BootstrapServiceRegistryImpl
|
|||
|
||||
|
||||
@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 );
|
||||
return binding == null ? null : binding.getService();
|
||||
}
|
||||
|
@ -237,7 +235,7 @@ public class BootstrapServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ServiceRegistry getParentServiceRegistry() {
|
||||
public ServiceRegistry getParentServiceRegistry() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,14 +30,6 @@ 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
|
||||
|
@ -49,13 +41,12 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
|||
*
|
||||
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
|
||||
*/
|
||||
public static StandardServiceRegistryImpl create(
|
||||
public StandardServiceRegistryImpl(
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
List<StandardServiceInitiator<?>> serviceInitiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
Map<String,Object> configurationValues) {
|
||||
|
||||
return create( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
|
||||
this( true, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,21 +62,20 @@ public class StandardServiceRegistryImpl extends AbstractServiceRegistryImpl imp
|
|||
*
|
||||
* @see org.hibernate.boot.registry.StandardServiceRegistryBuilder
|
||||
*/
|
||||
public static StandardServiceRegistryImpl create(
|
||||
public StandardServiceRegistryImpl(
|
||||
boolean autoCloseRegistry,
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
List<StandardServiceInitiator<?>> serviceInitiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
Map<String,Object> configurationValues) {
|
||||
super( bootstrapServiceRegistry, autoCloseRegistry );
|
||||
|
||||
StandardServiceRegistryImpl instance = new StandardServiceRegistryImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
|
||||
instance.initialize();
|
||||
instance.applyServiceRegistrations( serviceInitiators, providedServices );
|
||||
this.configurationValues = configurationValues;
|
||||
|
||||
return instance;
|
||||
applyServiceRegistrations( serviceInitiators, providedServices );
|
||||
}
|
||||
|
||||
protected void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
|
||||
private void applyServiceRegistrations(List<StandardServiceInitiator<?>> serviceInitiators, List<ProvidedService<?>> providedServices) {
|
||||
try {
|
||||
// process initiators
|
||||
for ( ServiceInitiator<?> initiator : serviceInitiators ) {
|
||||
|
|
|
@ -8,8 +8,6 @@ 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.
|
||||
|
@ -72,7 +70,7 @@ public enum AccessType {
|
|||
*
|
||||
* @see #getExternalName()
|
||||
*/
|
||||
public static AccessType fromExternalName(@Nullable String externalName) {
|
||||
public static AccessType fromExternalName(String externalName) {
|
||||
if ( externalName == null ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -13,15 +13,11 @@ 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.
|
||||
*
|
||||
|
@ -56,12 +52,12 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
|
|||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
|
||||
@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 );
|
||||
if ( value == null ) {
|
||||
return defaultValue;
|
||||
|
@ -71,14 +67,14 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
|
|||
}
|
||||
|
||||
@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 T target = cast( expected, value );
|
||||
return target !=null ? target : defaultValue;
|
||||
}
|
||||
|
||||
@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) {
|
||||
return null;
|
||||
}
|
||||
|
@ -93,7 +89,7 @@ public class ConfigurationServiceImpl implements ConfigurationService, ServiceRe
|
|||
}
|
||||
else {
|
||||
try {
|
||||
target = NullnessUtil.castNonNull( serviceRegistry.getService( ClassLoaderService.class ) ).classForName( candidate.toString() );
|
||||
target = serviceRegistry.getService( ClassLoaderService.class ).classForName( candidate.toString() );
|
||||
}
|
||||
catch ( ClassLoadingException e ) {
|
||||
LOG.debugf( "Unable to locate %s implementation class %s", expected.getName(), candidate.toString() );
|
||||
|
|
|
@ -10,10 +10,6 @@ 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>
|
||||
|
@ -42,7 +38,7 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @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.
|
||||
|
@ -54,7 +50,7 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @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
|
||||
|
@ -67,7 +63,7 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @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.
|
||||
|
@ -82,6 +78,6 @@ public interface ConfigurationService extends Service {
|
|||
*
|
||||
* @return The converted (typed) value.
|
||||
*/
|
||||
@NonNull T convert(Object value);
|
||||
T convert(Object value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
package org.hibernate.engine.config.spi;
|
||||
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.PolyNull;
|
||||
|
||||
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 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() );
|
||||
|
@ -28,12 +30,20 @@ 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,7 +24,6 @@ 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;
|
||||
|
||||
|
@ -81,7 +80,7 @@ final class JndiServiceImpl implements JndiService {
|
|||
}
|
||||
else {
|
||||
final String passThruPropertyName = propertyName.substring( Environment.JNDI_PREFIX.length() + 1 );
|
||||
jndiProperties.put( passThruPropertyName, NullnessUtil.castNonNull( propertyValue ) );
|
||||
jndiProperties.put( passThruPropertyName, propertyValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ 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;
|
||||
|
@ -64,7 +63,7 @@ public abstract class AbstractJtaPlatform
|
|||
}
|
||||
|
||||
protected JndiService jndiService() {
|
||||
return NullnessUtil.castNonNull( serviceRegistry().getService( JndiService.class ) );
|
||||
return serviceRegistry().getService( JndiService.class );
|
||||
}
|
||||
|
||||
protected abstract TransactionManager locateTransactionManager();
|
||||
|
|
|
@ -11,7 +11,6 @@ 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
|
||||
|
@ -22,7 +21,7 @@ public class AtomikosJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
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();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
@ -12,7 +12,6 @@ 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 +22,7 @@ public class BitronixJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
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" );
|
||||
return (TransactionManager) getTransactionManagerMethod.invoke( null );
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ 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
|
||||
|
@ -38,8 +37,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
}
|
||||
|
||||
try {
|
||||
final Class jbossTmClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
final Class jbossTmClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( JBOSS_TM_CLASS_NAME );
|
||||
return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
|
||||
}
|
||||
|
@ -59,8 +58,8 @@ public class JBossStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
}
|
||||
|
||||
try {
|
||||
final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
final Class jbossUtClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( JBOSS_UT_CLASS_NAME );
|
||||
return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ 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
|
||||
|
@ -24,7 +23,7 @@ public class JOTMJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
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" );
|
||||
return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null );
|
||||
}
|
||||
|
|
|
@ -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.JtaPlatformResolver;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.NullnessUtil;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -39,11 +38,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 = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) ).resolveStrategy( JtaPlatform.class, setting );
|
||||
JtaPlatform platform = registry.getService( StrategySelector.class ).resolveStrategy( JtaPlatform.class, setting );
|
||||
|
||||
if ( platform == null ) {
|
||||
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 ) {
|
||||
|
|
|
@ -12,7 +12,6 @@ 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;
|
||||
|
@ -28,7 +27,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 = NullnessUtil.castNonNull( registry.getService( StrategySelector.class ) )
|
||||
final JtaPlatformResolver resolver = registry.getService( StrategySelector.class )
|
||||
.resolveStrategy( JtaPlatformResolver.class, setting );
|
||||
if ( resolver == null ) {
|
||||
log.debugf( "No JtaPlatformResolver was specified, using default [%s]", StandardJtaPlatformResolver.class.getName() );
|
||||
|
|
|
@ -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.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;
|
||||
|
@ -28,7 +27,7 @@ public class StandardJtaPlatformResolver implements JtaPlatformResolver {
|
|||
|
||||
@Override
|
||||
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
|
||||
for ( JtaPlatformProvider provider : classLoaderService.loadJavaServices( JtaPlatformProvider.class ) ) {
|
||||
|
|
|
@ -34,8 +34,8 @@ public class WebSphereLibertyJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class<?> TransactionManagerFactory = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
final Class<?> TransactionManagerFactory = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( TMF_CLASS_NAME );
|
||||
return (TransactionManager) TransactionManagerFactory.getMethod("getTransactionManager").invoke(null);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ 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
|
||||
|
@ -26,8 +25,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected TransactionManager locateTransactionManager() {
|
||||
try {
|
||||
final Class wildflyTmClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
final Class wildflyTmClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( WILDFLY_TM_CLASS_NAME );
|
||||
return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
|
||||
}
|
||||
|
@ -42,8 +41,8 @@ public class WildFlyStandAloneJtaPlatform extends AbstractJtaPlatform {
|
|||
@Override
|
||||
protected UserTransaction locateUserTransaction() {
|
||||
try {
|
||||
final Class jbossUtClass = NullnessUtil.castNonNull( serviceRegistry()
|
||||
.getService( ClassLoaderService.class ) )
|
||||
final Class jbossUtClass = serviceRegistry()
|
||||
.getService( ClassLoaderService.class )
|
||||
.classForName( WILDFLY_UT_CLASS_NAME );
|
||||
return (UserTransaction) jbossUtClass.getMethod( "getInstance" ).invoke( null );
|
||||
}
|
||||
|
|
|
@ -9,8 +9,6 @@ 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.
|
||||
|
@ -19,14 +17,14 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
*/
|
||||
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 );
|
||||
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 );
|
||||
this.constraintName = constraintName;
|
||||
}
|
||||
|
@ -36,7 +34,7 @@ public class ConstraintViolationException extends JDBCException {
|
|||
*
|
||||
* @return The name of the violated constraint, or null if not known.
|
||||
*/
|
||||
public @Nullable String getConstraintName() {
|
||||
public String getConstraintName() {
|
||||
return constraintName;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,6 @@ 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
|
||||
|
@ -43,7 +41,7 @@ public class SQLExceptionTypeDelegate extends AbstractSQLExceptionConversionDele
|
|||
}
|
||||
|
||||
@Override
|
||||
public @Nullable JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
public JDBCException convert(SQLException sqlException, String message, String sql) {
|
||||
if ( sqlException instanceof SQLClientInfoException
|
||||
|| sqlException instanceof SQLInvalidAuthorizationSpecException
|
||||
|| sqlException instanceof SQLNonTransientConnectionException
|
||||
|
|
|
@ -21,8 +21,6 @@ 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
|
||||
|
@ -79,7 +77,7 @@ public class SQLStateConversionDelegate extends AbstractSQLExceptionConversionDe
|
|||
}
|
||||
|
||||
@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 int errorCode = JdbcExceptionHelper.extractErrorCode( sqlException );
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ 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}.
|
||||
|
@ -46,7 +44,7 @@ public class StandardSQLExceptionConverter implements SQLExceptionConverter {
|
|||
* @deprecated use {@link #StandardSQLExceptionConverter(SQLExceptionConversionDelegate...)}
|
||||
*/
|
||||
@Deprecated(since = "6.0")
|
||||
public void addDelegate(@Nullable SQLExceptionConversionDelegate delegate) {
|
||||
public void addDelegate(SQLExceptionConversionDelegate delegate) {
|
||||
if ( delegate != null ) {
|
||||
this.delegates.add( delegate );
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ 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
|
||||
|
@ -33,6 +31,6 @@ public interface SQLExceptionConversionDelegate {
|
|||
* if this delegate does not know how to interpret the
|
||||
* given {@link SQLException}.
|
||||
*/
|
||||
@Nullable JDBCException convert(SQLException sqlException, String message, String sql);
|
||||
JDBCException convert(SQLException sqlException, String message, String sql);
|
||||
|
||||
}
|
||||
|
|
|
@ -9,10 +9,6 @@ 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.
|
||||
|
@ -29,7 +25,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
|
|||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String extractConstraintName(SQLException sqle) {
|
||||
public String extractConstraintName(SQLException sqle) {
|
||||
try {
|
||||
String constraintName = null;
|
||||
|
||||
|
@ -41,7 +37,7 @@ public class TemplatedViolatedConstraintNameExtractor implements ViolatedConstra
|
|||
break;
|
||||
}
|
||||
else {
|
||||
sqle = NullnessUtil.castNonNull( sqle.getNextException() );
|
||||
sqle = sqle.getNextException();
|
||||
}
|
||||
} while (constraintName == null);
|
||||
|
||||
|
@ -61,7 +57,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 @Nullable String extractUsingTemplate(String templateStart, String templateEnd, String message) {
|
||||
public static String extractUsingTemplate(String templateStart, String templateEnd, String message) {
|
||||
int templateStartPosition = message.indexOf( templateStart );
|
||||
if ( templateStartPosition < 0 ) {
|
||||
return null;
|
||||
|
|
|
@ -8,8 +8,6 @@ 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.
|
||||
|
@ -25,5 +23,5 @@ public interface ViolatedConstraintNameExtractor {
|
|||
* @param sqle The exception that was the result of the constraint violation.
|
||||
* @return The extracted constraint name.
|
||||
*/
|
||||
@Nullable String extractConstraintName(SQLException sqle);
|
||||
String extractConstraintName(SQLException sqle);
|
||||
}
|
||||
|
|
|
@ -8,8 +8,6 @@ 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.
|
||||
|
@ -55,7 +53,7 @@ public enum SequenceMismatchStrategy {
|
|||
*
|
||||
* @return associated {@link SequenceMismatchStrategy} object
|
||||
*/
|
||||
public static SequenceMismatchStrategy interpret(@Nullable Object sequenceMismatchStrategy) {
|
||||
public static SequenceMismatchStrategy interpret(Object sequenceMismatchStrategy) {
|
||||
if ( sequenceMismatchStrategy == null ) {
|
||||
return EXCEPTION;
|
||||
}
|
||||
|
|
|
@ -24,26 +24,20 @@ public class IntegratorServiceImpl implements IntegratorService {
|
|||
|
||||
private final LinkedHashSet<Integrator> integrators = new LinkedHashSet<>();
|
||||
|
||||
private IntegratorServiceImpl() {
|
||||
}
|
||||
|
||||
public static IntegratorServiceImpl create(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
|
||||
IntegratorServiceImpl instance = new IntegratorServiceImpl();
|
||||
|
||||
public IntegratorServiceImpl(LinkedHashSet<Integrator> providedIntegrators, ClassLoaderService classLoaderService) {
|
||||
// register standard integrators. Envers and JPA, for example, need to be handled by discovery because in
|
||||
// separate project/jars.
|
||||
instance.addIntegrator( new BeanValidationIntegrator() );
|
||||
instance.addIntegrator( new CollectionCacheInvalidator() );
|
||||
addIntegrator( new BeanValidationIntegrator() );
|
||||
addIntegrator( new CollectionCacheInvalidator() );
|
||||
|
||||
// register provided integrators
|
||||
for ( Integrator integrator : providedIntegrators ) {
|
||||
instance.addIntegrator( integrator );
|
||||
}
|
||||
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
|
||||
instance.addIntegrator( integrator );
|
||||
addIntegrator( integrator );
|
||||
}
|
||||
|
||||
return instance;
|
||||
for ( Integrator integrator : classLoaderService.loadJavaServices( Integrator.class ) ) {
|
||||
addIntegrator( integrator );
|
||||
}
|
||||
}
|
||||
|
||||
private void addIntegrator(Integrator integrator) {
|
||||
|
|
|
@ -592,6 +592,10 @@ 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,8 +6,6 @@
|
|||
*/
|
||||
package org.hibernate.service;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* A registry of {@linkplain Service services}. This interface abstracts
|
||||
* the operations of:
|
||||
|
@ -29,7 +27,7 @@ public interface ServiceRegistry extends AutoCloseable {
|
|||
*
|
||||
* @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
|
||||
|
@ -44,7 +42,7 @@ public interface ServiceRegistry extends AutoCloseable {
|
|||
*
|
||||
* @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
|
||||
|
|
|
@ -35,8 +35,6 @@ 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.
|
||||
*
|
||||
|
@ -50,7 +48,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
|
||||
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 ConcurrentMap<Class<?>,ServiceBinding<?>> serviceBindingMap = new ConcurrentHashMap<>();
|
||||
|
@ -72,17 +70,26 @@ public abstract class AbstractServiceRegistryImpl
|
|||
|
||||
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 );
|
||||
}
|
||||
|
||||
protected AbstractServiceRegistryImpl(
|
||||
@Nullable ServiceRegistryImplementor parent,
|
||||
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) {
|
||||
|
@ -92,21 +99,15 @@ 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;
|
||||
}
|
||||
|
||||
// For nullness checking purposes
|
||||
protected void initialize() {
|
||||
if ( this.parent != null ) {
|
||||
this.autoCloseRegistry = autoCloseRegistry;
|
||||
this.parent.registerChild( this );
|
||||
}
|
||||
}
|
||||
|
||||
protected <R extends Service> void createServiceBinding(ServiceInitiator<R> initiator) {
|
||||
final ServiceBinding<?> serviceBinding = new ServiceBinding<>( this, initiator );
|
||||
|
@ -127,17 +128,17 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ServiceRegistry getParentServiceRegistry() {
|
||||
public ServiceRegistry getParentServiceRegistry() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
|
||||
@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 );
|
||||
if ( serviceBinding == null && checkParent && parent != null ) {
|
||||
// look in parent
|
||||
|
@ -183,7 +184,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
|
||||
@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
|
||||
//(and after bootstrap service loading performance is less interesting as it's
|
||||
//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() ) {
|
||||
log.tracev( "Initializing service [role={0}]", serviceBinding.getServiceRole().getName() );
|
||||
}
|
||||
|
@ -252,7 +253,7 @@ public abstract class AbstractServiceRegistryImpl
|
|||
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();
|
||||
if ( serviceInitiator == null ) {
|
||||
// this condition should never ever occur
|
||||
|
@ -370,12 +371,10 @@ public abstract class AbstractServiceRegistryImpl
|
|||
serviceBindingMap.clear();
|
||||
}
|
||||
finally {
|
||||
if ( parent != null ) {
|
||||
parent.deRegisterChild( this );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
* 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 ) {
|
||||
this.parent.deRegisterChild( this );
|
||||
}
|
||||
|
@ -447,14 +446,14 @@ public abstract class AbstractServiceRegistryImpl
|
|||
}
|
||||
|
||||
@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 );
|
||||
}
|
||||
|
||||
public static <T extends Service> @Nullable T fromRegistryOrChildren(
|
||||
public static <T extends Service> T fromRegistryOrChildren(
|
||||
Class<T> serviceRole,
|
||||
ServiceRegistryImplementor serviceRegistry,
|
||||
@Nullable Set<ServiceRegistryImplementor> childRegistries) {
|
||||
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 SessionFactoryServiceRegistryImpl.create(
|
||||
return new SessionFactoryServiceRegistryImpl(
|
||||
parent,
|
||||
initiators,
|
||||
providedServices,
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
@ -32,7 +31,7 @@ public class SessionFactoryServiceRegistryFactoryImpl implements SessionFactoryS
|
|||
public SessionFactoryServiceRegistry buildServiceRegistry(
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
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 );
|
||||
|
||||
for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {
|
||||
|
|
|
@ -12,7 +12,6 @@ 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;
|
||||
|
@ -24,8 +23,6 @@ import org.hibernate.service.spi.SessionFactoryServiceRegistry;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -38,28 +35,17 @@ public class SessionFactoryServiceRegistryImpl
|
|||
private final SessionFactoryOptions sessionFactoryOptions;
|
||||
private final SessionFactoryImplementor sessionFactory;
|
||||
|
||||
private SessionFactoryServiceRegistryImpl(
|
||||
ServiceRegistryImplementor parent,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryOptions sessionFactoryOptions) {
|
||||
super( parent );
|
||||
this.sessionFactory = sessionFactory;
|
||||
this.sessionFactoryOptions = sessionFactoryOptions;
|
||||
}
|
||||
|
||||
public static SessionFactoryServiceRegistryImpl create(
|
||||
public SessionFactoryServiceRegistryImpl(
|
||||
ServiceRegistryImplementor parent,
|
||||
List<SessionFactoryServiceInitiator<?>> initiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
SessionFactoryImplementor sessionFactory,
|
||||
SessionFactoryOptions sessionFactoryOptions) {
|
||||
SessionFactoryServiceRegistryImpl instance = new SessionFactoryServiceRegistryImpl( parent, sessionFactory, sessionFactoryOptions);
|
||||
instance.initialize( initiators, providedServices );
|
||||
return instance;
|
||||
}
|
||||
super( parent );
|
||||
|
||||
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 ( SessionFactoryServiceInitiator<?> initiator : initiators ) {
|
||||
// create the bindings up front to help identify to which registry services belong
|
||||
|
@ -80,7 +66,7 @@ public class SessionFactoryServiceRegistryImpl
|
|||
@Override
|
||||
public <R extends Service> void configureService(ServiceBinding<R> serviceBinding) {
|
||||
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
|
||||
public <R extends Service> @Nullable R getService(Class<R> serviceRole) {
|
||||
public <R extends Service> R getService(Class<R> serviceRole) {
|
||||
if ( serviceRole.equals( EventListenerRegistry.class ) ) {
|
||||
log.debug(
|
||||
"EventListenerRegistry access via ServiceRegistry is deprecated. " +
|
||||
|
|
|
@ -10,8 +10,6 @@ import org.hibernate.service.Service;
|
|||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Models a binding for a particular service.
|
||||
*
|
||||
|
@ -32,7 +30,7 @@ public final class ServiceBinding<R extends Service> {
|
|||
|
||||
private final ServiceLifecycleOwner lifecycleOwner;
|
||||
private final Class<R> serviceRole;
|
||||
private final @Nullable ServiceInitiator<R> serviceInitiator;
|
||||
private final ServiceInitiator<R> serviceInitiator;
|
||||
private volatile R service;
|
||||
|
||||
public ServiceBinding(ServiceLifecycleOwner lifecycleOwner, Class<R> serviceRole, R service) {
|
||||
|
@ -56,7 +54,7 @@ public final class ServiceBinding<R extends Service> {
|
|||
return serviceRole;
|
||||
}
|
||||
|
||||
public @Nullable ServiceInitiator<R> getServiceInitiator() {
|
||||
public ServiceInitiator<R> getServiceInitiator() {
|
||||
return serviceInitiator;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,6 @@ 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.
|
||||
*
|
||||
|
@ -25,7 +23,7 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
|
|||
*
|
||||
* @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
|
||||
default void close() {
|
||||
|
@ -49,5 +47,5 @@ public interface ServiceRegistryImplementor extends ServiceRegistry {
|
|||
*/
|
||||
void deRegisterChild(ServiceRegistryImplementor child);
|
||||
|
||||
<T extends Service> @Nullable T fromRegistryOrChildren(Class<T> serviceRole);
|
||||
<T extends Service> T fromRegistryOrChildren(Class<T> serviceRole);
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
@ -43,8 +42,8 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
|
|||
|
||||
@Override
|
||||
public StatisticsImplementor initiateService(SessionFactoryServiceInitiatorContext context) {
|
||||
final Object configValue = NullnessUtil.castNonNull( context.getServiceRegistry()
|
||||
.getService( ConfigurationService.class ) )
|
||||
final Object configValue = context.getServiceRegistry()
|
||||
.getService( ConfigurationService.class )
|
||||
.getSettings()
|
||||
.get( STATS_BUILDER );
|
||||
return initiateServiceInternal( context.getSessionFactory(), configValue, context.getServiceRegistry() );
|
||||
|
@ -64,7 +63,7 @@ public class StatisticsInitiator implements SessionFactoryServiceInitiator<Stati
|
|||
}
|
||||
else {
|
||||
// assume it names the factory class
|
||||
final ClassLoaderService classLoaderService = NullnessUtil.castNonNull( registry.getService( ClassLoaderService.class ) );
|
||||
final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
|
||||
try {
|
||||
statisticsFactory = (StatisticsFactory) classLoaderService.classForName( configValue.toString() ).newInstance();
|
||||
}
|
||||
|
|
|
@ -12,8 +12,6 @@ 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.
|
||||
|
@ -72,7 +70,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(@Nullable Object value) {
|
||||
public static WrapperArrayHandling interpretExternalSettingLeniently(Object value) {
|
||||
if ( value == null ) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -9,11 +9,8 @@ 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;
|
||||
|
@ -23,9 +20,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.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 static org.junit.Assert.fail;
|
||||
|
@ -35,17 +32,27 @@ import static org.junit.Assert.fail;
|
|||
*/
|
||||
public class ConnectionCreatorTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
@JiraKey(value = "HHH-8621" )
|
||||
@TestForIssue( jiraKey = "HHH-8621" )
|
||||
public void testBadUrl() throws Exception {
|
||||
DriverConnectionCreator connectionCreator = new DriverConnectionCreator(
|
||||
(Driver) Class.forName( "org.h2.Driver" ).newInstance(),
|
||||
CCTStandardServiceRegistryImpl.create(
|
||||
new StandardServiceRegistryImpl(
|
||||
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,
|
||||
|
@ -61,37 +68,4 @@ 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,7 +85,8 @@ public class HibernateQueryMetrics implements MeterBinder {
|
|||
@Override
|
||||
public void bindTo(MeterRegistry meterRegistry) {
|
||||
if ( sessionFactory instanceof SessionFactoryImplementor ) {
|
||||
EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getEventEngine().getListenerRegistry();
|
||||
EventListenerRegistry eventListenerRegistry = ( (SessionFactoryImplementor) sessionFactory ).getServiceRegistry()
|
||||
.getService( EventListenerRegistry.class );
|
||||
MetricsEventHandler metricsEventHandler = new MetricsEventHandler( meterRegistry );
|
||||
eventListenerRegistry.appendListeners( EventType.POST_LOAD, metricsEventHandler );
|
||||
}
|
||||
|
|
|
@ -33,15 +33,8 @@ 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 ServiceRegistryTestingImpl.create(
|
||||
return new ServiceRegistryTestingImpl(
|
||||
true,
|
||||
new BootstrapServiceRegistryBuilder().build(),
|
||||
StandardServiceInitiators.LIST,
|
||||
|
@ -54,7 +47,7 @@ public class ServiceRegistryTestingImpl
|
|||
}
|
||||
|
||||
public static ServiceRegistryTestingImpl forUnitTesting(Map<String,Object> settings) {
|
||||
return ServiceRegistryTestingImpl.create(
|
||||
return new ServiceRegistryTestingImpl(
|
||||
true,
|
||||
new BootstrapServiceRegistryBuilder().build(),
|
||||
StandardServiceInitiators.LIST,
|
||||
|
@ -77,17 +70,12 @@ public class ServiceRegistryTestingImpl
|
|||
);
|
||||
}
|
||||
|
||||
public static ServiceRegistryTestingImpl create(
|
||||
public ServiceRegistryTestingImpl(
|
||||
boolean autoCloseRegistry,
|
||||
BootstrapServiceRegistry bootstrapServiceRegistry,
|
||||
List<StandardServiceInitiator<?>> serviceInitiators,
|
||||
List<ProvidedService<?>> providedServices,
|
||||
Map<String,Object> configurationValues) {
|
||||
|
||||
ServiceRegistryTestingImpl instance = new ServiceRegistryTestingImpl( autoCloseRegistry, bootstrapServiceRegistry, configurationValues );
|
||||
instance.initialize();
|
||||
instance.applyServiceRegistrations( serviceInitiators, providedServices );
|
||||
|
||||
return instance;
|
||||
super( autoCloseRegistry, bootstrapServiceRegistry, serviceInitiators, providedServices, configurationValues );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ public abstract class MockSessionFactory
|
|||
|
||||
public MockSessionFactory() {
|
||||
|
||||
serviceRegistry = StandardServiceRegistryImpl.create(
|
||||
serviceRegistry = new StandardServiceRegistryImpl(
|
||||
new BootstrapServiceRegistryBuilder().applyClassLoaderService(new ClassLoaderServiceImpl() {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
Loading…
Reference in New Issue