squash a bunch of warnings

This commit is contained in:
Gavin King 2022-01-25 10:23:13 +01:00
parent c44e0519b9
commit 03a3f96c62
4 changed files with 94 additions and 126 deletions

View File

@ -68,7 +68,7 @@ class TypeSafeActivator {
*/ */
@SuppressWarnings( {"UnusedDeclaration"}) @SuppressWarnings( {"UnusedDeclaration"})
public static void validateSuppliedFactory(Object object) { public static void validateSuppliedFactory(Object object) {
if ( ! ValidatorFactory.class.isInstance( object ) ) { if ( !(object instanceof ValidatorFactory) ) {
throw new IntegrationException( throw new IntegrationException(
"Given object was not an instance of " + ValidatorFactory.class.getName() "Given object was not an instance of " + ValidatorFactory.class.getName()
+ "[" + object.getClass().getName() + "]" + "[" + object.getClass().getName() + "]"
@ -133,7 +133,6 @@ class TypeSafeActivator {
listener.initialize( cfgService.getSettings(), classLoaderService ); listener.initialize( cfgService.getSettings(), classLoaderService );
} }
@SuppressWarnings({"unchecked", "UnusedParameters"})
private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) { private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) {
final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class ); final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class );
if ( !cfgService.getSetting( BeanValidationIntegrator.APPLY_CONSTRAINTS, StandardConverters.BOOLEAN, true ) ) { if ( !cfgService.getSetting( BeanValidationIntegrator.APPLY_CONSTRAINTS, StandardConverters.BOOLEAN, true ) ) {
@ -281,11 +280,10 @@ class TypeSafeActivator {
ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor; ConstraintDescriptor<Min> minConstraint = (ConstraintDescriptor<Min>) descriptor;
long min = minConstraint.getAnnotation().value(); long min = minConstraint.getAnnotation().value();
@SuppressWarnings("unchecked")
final Iterator<Selectable> itor = property.getColumnIterator(); final Iterator<Selectable> itor = property.getColumnIterator();
if ( itor.hasNext() ) { if ( itor.hasNext() ) {
final Selectable selectable = itor.next(); final Selectable selectable = itor.next();
if ( Column.class.isInstance( selectable ) ) { if ( selectable instanceof Column ) {
Column col = (Column) selectable; Column col = (Column) selectable;
String checkConstraint = col.getQuotedName(dialect) + ">=" + min; String checkConstraint = col.getQuotedName(dialect) + ">=" + min;
applySQLCheck( col, checkConstraint ); applySQLCheck( col, checkConstraint );
@ -300,11 +298,10 @@ class TypeSafeActivator {
ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor; ConstraintDescriptor<Max> maxConstraint = (ConstraintDescriptor<Max>) descriptor;
long max = maxConstraint.getAnnotation().value(); long max = maxConstraint.getAnnotation().value();
@SuppressWarnings("unchecked")
final Iterator<Selectable> itor = property.getColumnIterator(); final Iterator<Selectable> itor = property.getColumnIterator();
if ( itor.hasNext() ) { if ( itor.hasNext() ) {
final Selectable selectable = itor.next(); final Selectable selectable = itor.next();
if ( Column.class.isInstance( selectable ) ) { if ( selectable instanceof Column ) {
Column col = (Column) selectable; Column col = (Column) selectable;
String checkConstraint = col.getQuotedName( dialect ) + "<=" + max; String checkConstraint = col.getQuotedName( dialect ) + "<=" + max;
applySQLCheck( col, checkConstraint ); applySQLCheck( col, checkConstraint );
@ -323,7 +320,6 @@ class TypeSafeActivator {
col.setCheckConstraint( checkConstraint ); col.setCheckConstraint( checkConstraint );
} }
@SuppressWarnings("unchecked")
private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) { private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) {
boolean hasNotNull = false; boolean hasNotNull = false;
if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) { if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) {
@ -334,8 +330,8 @@ class TypeSafeActivator {
final Iterator<Selectable> itr = property.getColumnIterator(); final Iterator<Selectable> itr = property.getColumnIterator();
while ( itr.hasNext() ) { while ( itr.hasNext() ) {
final Selectable selectable = itr.next(); final Selectable selectable = itr.next();
if ( Column.class.isInstance( selectable ) ) { if ( selectable instanceof Column ) {
Column.class.cast( selectable ).setNullable( false ); ((Column) selectable).setNullable( false );
} }
else { else {
LOG.debugf( LOG.debugf(
@ -360,11 +356,10 @@ class TypeSafeActivator {
int integerDigits = digitsConstraint.getAnnotation().integer(); int integerDigits = digitsConstraint.getAnnotation().integer();
int fractionalDigits = digitsConstraint.getAnnotation().fraction(); int fractionalDigits = digitsConstraint.getAnnotation().fraction();
@SuppressWarnings("unchecked")
final Iterator<Selectable> itor = property.getColumnIterator(); final Iterator<Selectable> itor = property.getColumnIterator();
if ( itor.hasNext() ) { if ( itor.hasNext() ) {
final Selectable selectable = itor.next(); final Selectable selectable = itor.next();
if ( Column.class.isInstance( selectable ) ) { if ( selectable instanceof Column ) {
Column col = (Column) selectable; Column col = (Column) selectable;
col.setPrecision( integerDigits + fractionalDigits ); col.setPrecision( integerDigits + fractionalDigits );
col.setScale( fractionalDigits ); col.setScale( fractionalDigits );
@ -381,7 +376,6 @@ class TypeSafeActivator {
ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor; ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
int max = sizeConstraint.getAnnotation().max(); int max = sizeConstraint.getAnnotation().max();
@SuppressWarnings("unchecked")
final Iterator<Selectable> itor = property.getColumnIterator(); final Iterator<Selectable> itor = property.getColumnIterator();
if ( itor.hasNext() ) { if ( itor.hasNext() ) {
final Selectable selectable = itor.next(); final Selectable selectable = itor.next();
@ -398,14 +392,12 @@ class TypeSafeActivator {
descriptor.getAnnotation().annotationType().getName() descriptor.getAnnotation().annotationType().getName()
) )
&& String.class.equals( propertyDescriptor.getElementClass() ) ) { && String.class.equals( propertyDescriptor.getElementClass() ) ) {
@SuppressWarnings("unchecked")
int max = (Integer) descriptor.getAttributes().get( "max" ); int max = (Integer) descriptor.getAttributes().get( "max" );
@SuppressWarnings("unchecked")
final Iterator<Selectable> itor = property.getColumnIterator(); final Iterator<Selectable> itor = property.getColumnIterator();
if ( itor.hasNext() ) { if ( itor.hasNext() ) {
final Selectable selectable = itor.next(); final Selectable selectable = itor.next();
if ( Column.class.isInstance( selectable ) ) { if ( selectable instanceof Column ) {
Column col = (Column) selectable; Column col = (Column) selectable;
if ( max < Integer.MAX_VALUE ) { if ( max < Integer.MAX_VALUE ) {
col.setLength( max ); col.setLength( max );
@ -518,7 +510,7 @@ class TypeSafeActivator {
} }
try { try {
return ValidatorFactory.class.cast( validatorFactoryReference ); return (ValidatorFactory) validatorFactoryReference;
} }
catch ( ClassCastException e ) { catch ( ClassCastException e ) {
throw new IntegrationException( throw new IntegrationException(
@ -533,48 +525,41 @@ class TypeSafeActivator {
} }
} }
@SuppressWarnings("unchecked")
private static ValidatorFactory resolveProvidedFactory(ConfigurationService cfgService) { private static ValidatorFactory resolveProvidedFactory(ConfigurationService cfgService) {
return cfgService.getSetting( return cfgService.getSetting(
AvailableSettings.JPA_VALIDATION_FACTORY, AvailableSettings.JPA_VALIDATION_FACTORY,
new ConfigurationService.Converter<ValidatorFactory>() { value -> {
@Override try {
public ValidatorFactory convert(Object value) { return (ValidatorFactory) value;
try { }
return ValidatorFactory.class.cast( value ); catch ( ClassCastException e ) {
} throw new IntegrationException(
catch ( ClassCastException e ) { String.format(
throw new IntegrationException( Locale.ENGLISH,
String.format( "ValidatorFactory reference (provided via `%s` setting) was not castable to %s : %s",
Locale.ENGLISH, AvailableSettings.JPA_VALIDATION_FACTORY,
"ValidatorFactory reference (provided via `%s` setting) was not castable to %s : %s", ValidatorFactory.class.getName(),
AvailableSettings.JPA_VALIDATION_FACTORY, value.getClass().getName()
ValidatorFactory.class.getName(), )
value.getClass().getName() );
)
);
}
} }
}, },
cfgService.getSetting( cfgService.getSetting(
AvailableSettings.JAKARTA_VALIDATION_FACTORY, AvailableSettings.JAKARTA_VALIDATION_FACTORY,
new ConfigurationService.Converter<ValidatorFactory>() { value -> {
@Override try {
public ValidatorFactory convert(Object value) { return (ValidatorFactory) value;
try { }
return ValidatorFactory.class.cast( value ); catch ( ClassCastException e ) {
} throw new IntegrationException(
catch ( ClassCastException e ) { String.format(
throw new IntegrationException( Locale.ENGLISH,
String.format( "ValidatorFactory reference (provided via `%s` setting) was not castable to %s : %s",
Locale.ENGLISH, AvailableSettings.JAKARTA_VALIDATION_FACTORY,
"ValidatorFactory reference (provided via `%s` setting) was not castable to %s : %s", ValidatorFactory.class.getName(),
AvailableSettings.JAKARTA_VALIDATION_FACTORY, value.getClass().getName()
ValidatorFactory.class.getName(), )
value.getClass().getName() );
)
);
}
} }
}, },
null null

View File

@ -27,7 +27,6 @@ import javax.naming.StringRefAddr;
import jakarta.persistence.Cache; import jakarta.persistence.Cache;
import jakarta.persistence.EntityGraph; import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.PersistenceContextType;
import jakarta.persistence.PersistenceException; import jakarta.persistence.PersistenceException;
import jakarta.persistence.PersistenceUnitUtil; import jakarta.persistence.PersistenceUnitUtil;
import jakarta.persistence.Query; import jakarta.persistence.Query;
@ -607,13 +606,6 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
// todo : (5.2) review synchronizationType, persistenceContextType, transactionType usage // todo : (5.2) review synchronizationType, persistenceContextType, transactionType usage
// SynchronizationType -> should we auto enlist in transactions
private transient SynchronizationType synchronizationType;
// PersistenceContextType -> influences FlushMode and 'autoClose'
private transient PersistenceContextType persistenceContextType;
@Override @Override
public Session createEntityManager() { public Session createEntityManager() {
validateNotClosed(); validateNotClosed();
@ -1266,80 +1258,74 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
return new SessionImpl( sessionFactory, this ); return new SessionImpl( sessionFactory, this );
} }
@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private T getThis() {
return (T) this;
}
@Override
public T interceptor(Interceptor interceptor) { public T interceptor(Interceptor interceptor) {
this.interceptor = interceptor; this.interceptor = interceptor;
this.explicitNoInterceptor = false; this.explicitNoInterceptor = false;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T noInterceptor() { public T noInterceptor() {
this.interceptor = EmptyInterceptor.INSTANCE; this.interceptor = EmptyInterceptor.INSTANCE;
this.explicitNoInterceptor = true; this.explicitNoInterceptor = true;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T statementInspector(StatementInspector statementInspector) { public T statementInspector(StatementInspector statementInspector) {
this.statementInspector = statementInspector; this.statementInspector = statementInspector;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T connection(Connection connection) { public T connection(Connection connection) {
this.connection = connection; this.connection = connection;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T connectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) { public T connectionHandlingMode(PhysicalConnectionHandlingMode connectionHandlingMode) {
this.connectionHandlingMode = connectionHandlingMode; this.connectionHandlingMode = connectionHandlingMode;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T autoJoinTransactions(boolean autoJoinTransactions) { public T autoJoinTransactions(boolean autoJoinTransactions) {
this.autoJoinTransactions = autoJoinTransactions; this.autoJoinTransactions = autoJoinTransactions;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T autoClose(boolean autoClose) { public T autoClose(boolean autoClose) {
this.autoClose = autoClose; this.autoClose = autoClose;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T autoClear(boolean autoClear) { public T autoClear(boolean autoClear) {
this.autoClear = autoClear; this.autoClear = autoClear;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T flushMode(FlushMode flushMode) { public T flushMode(FlushMode flushMode) {
this.flushMode = flushMode; this.flushMode = flushMode;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T tenantIdentifier(String tenantIdentifier) { public T tenantIdentifier(String tenantIdentifier) {
this.tenantIdentifier = tenantIdentifier; this.tenantIdentifier = tenantIdentifier;
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T eventListeners(SessionEventListener... listeners) { public T eventListeners(SessionEventListener... listeners) {
if ( this.listeners == null ) { if ( this.listeners == null ) {
this.listeners = sessionFactory.getSessionFactoryOptions() this.listeners = sessionFactory.getSessionFactoryOptions()
@ -1347,11 +1333,10 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
.buildBaselineList(); .buildBaselineList();
} }
Collections.addAll( this.listeners, listeners ); Collections.addAll( this.listeners, listeners );
return (T) this; return getThis();
} }
@Override @Override
@SuppressWarnings("unchecked")
public T clearEventListeners() { public T clearEventListeners() {
if ( listeners == null ) { if ( listeners == null ) {
//Needs to initialize explicitly to an empty list as otherwise "null" implies the default listeners will be applied //Needs to initialize explicitly to an empty list as otherwise "null" implies the default listeners will be applied
@ -1360,13 +1345,13 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
else { else {
listeners.clear(); listeners.clear();
} }
return (T) this; return getThis();
} }
@Override @SuppressWarnings("unchecked") @Override
public T jdbcTimeZone(TimeZone timeZone) { public T jdbcTimeZone(TimeZone timeZone) {
jdbcTimeZone = timeZone; jdbcTimeZone = timeZone;
return (T) this; return getThis();
} }
} }
@ -1561,9 +1546,8 @@ public class SessionFactoryImpl implements SessionFactoryImplementor {
* @param ois The stream from which to "read" the factory * @param ois The stream from which to "read" the factory
* @return The deserialized factory * @return The deserialized factory
* @throws IOException indicates problems reading back serial data stream * @throws IOException indicates problems reading back serial data stream
* @throws ClassNotFoundException indicates problems reading back serial data stream
*/ */
static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException { static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException {
LOG.trace( "Deserializing SessionFactory from Session" ); LOG.trace( "Deserializing SessionFactory from Session" );
final String uuid = ois.readUTF(); final String uuid = ois.readUTF();
boolean isNamed = ois.readBoolean(); boolean isNamed = ois.readBoolean();

View File

@ -8,6 +8,7 @@ package org.hibernate.jpa.boot.internal;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -127,6 +128,7 @@ import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
/** /**
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings("deprecation")
public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuilder { public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuilder {
private static final EntityManagerMessageLogger LOG = messageLogger( EntityManagerFactoryBuilderImpl.class ); private static final EntityManagerMessageLogger LOG = messageLogger( EntityManagerFactoryBuilderImpl.class );
@ -163,8 +165,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private final PersistenceUnitDescriptor persistenceUnit; private final PersistenceUnitDescriptor persistenceUnit;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// things built in first phase, needed for second phase.. // things built in first phase, needed for second phase
private final Map configurationValues; private final Map<Object,Object> configurationValues;
private final StandardServiceRegistry standardServiceRegistry; private final StandardServiceRegistry standardServiceRegistry;
private final ManagedResources managedResources; private final ManagedResources managedResources;
private final MetadataBuilderImplementor metamodelBuilder; private final MetadataBuilderImplementor metamodelBuilder;
@ -180,20 +182,22 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
} }
public EntityManagerFactoryBuilderImpl(PersistenceUnitDescriptor persistenceUnit, Map integrationSettings) { public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit,
Map<?,?> integrationSettings) {
this( persistenceUnit, integrationSettings, null, null, null ); this( persistenceUnit, integrationSettings, null, null, null );
} }
public EntityManagerFactoryBuilderImpl( public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit, PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings, Map<?,?> integrationSettings,
ClassLoader providedClassLoader ) { ClassLoader providedClassLoader ) {
this( persistenceUnit, integrationSettings, providedClassLoader, null, null ); this( persistenceUnit, integrationSettings, providedClassLoader, null, null );
} }
public EntityManagerFactoryBuilderImpl( public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit, PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings, Map<?,?> integrationSettings,
ClassLoaderService providedClassLoaderService ) { ClassLoaderService providedClassLoaderService ) {
this( persistenceUnit, integrationSettings, null, providedClassLoaderService, null ); this( persistenceUnit, integrationSettings, null, providedClassLoaderService, null );
} }
@ -204,14 +208,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
@Internal @Internal
public EntityManagerFactoryBuilderImpl( public EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnitDescriptor, PersistenceUnitDescriptor persistenceUnitDescriptor,
Map integration, Map<?,?> integration,
Consumer<MergedSettings> mergedSettingsBaseline) { Consumer<MergedSettings> mergedSettingsBaseline) {
this( persistenceUnitDescriptor, integration, null, null, mergedSettingsBaseline ); this( persistenceUnitDescriptor, integration, null, null, mergedSettingsBaseline );
} }
private EntityManagerFactoryBuilderImpl( private EntityManagerFactoryBuilderImpl(
PersistenceUnitDescriptor persistenceUnit, PersistenceUnitDescriptor persistenceUnit,
Map integrationSettings, Map<?,?> integrationSettings,
ClassLoader providedClassLoader, ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService, ClassLoaderService providedClassLoaderService,
Consumer<MergedSettings> mergedSettingsBaseline) { Consumer<MergedSettings> mergedSettingsBaseline) {
@ -221,14 +225,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
this.persistenceUnit = persistenceUnit; this.persistenceUnit = persistenceUnit;
if ( integrationSettings == null ) { if ( integrationSettings == null ) {
integrationSettings = new HashMap(); integrationSettings = new HashMap<>();
} }
Map mergedIntegrationSettings = null; Map<Object,Object> mergedIntegrationSettings = null;
Properties properties = persistenceUnit.getProperties(); Properties properties = persistenceUnit.getProperties();
if ( properties != null ) { if ( properties != null ) {
// original integration setting entries take precedence // original integration setting entries take precedence
mergedIntegrationSettings = new HashMap( properties ); mergedIntegrationSettings = new HashMap<>( properties );
mergedIntegrationSettings.putAll( integrationSettings ); mergedIntegrationSettings.putAll( integrationSettings );
} }
@ -352,7 +356,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// temporary! // temporary!
public Map getConfigurationValues() { public Map<Object,Object> getConfigurationValues() {
return Collections.unmodifiableMap( configurationValues ); return Collections.unmodifiableMap( configurationValues );
} }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -426,7 +430,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
* @return The built BootstrapServiceRegistry * @return The built BootstrapServiceRegistry
*/ */
private BootstrapServiceRegistry buildBootstrapServiceRegistry( private BootstrapServiceRegistry buildBootstrapServiceRegistry(
Map integrationSettings, Map<?,?> integrationSettings,
ClassLoader providedClassLoader, ClassLoader providedClassLoader,
ClassLoaderService providedClassLoaderService) { ClassLoaderService providedClassLoaderService) {
final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder(); final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder();
@ -460,8 +464,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
final Object classLoadersSetting = integrationSettings.get( CLASSLOADERS ); final Object classLoadersSetting = integrationSettings.get( CLASSLOADERS );
if ( classLoadersSetting != null ) { if ( classLoadersSetting != null ) {
if ( java.util.Collection.class.isInstance( classLoadersSetting ) ) { if ( classLoadersSetting instanceof Collection) {
for ( ClassLoader classLoader : (java.util.Collection<ClassLoader>) classLoadersSetting ) { @SuppressWarnings("unchecked")
Collection<ClassLoader> classLoaders = (Collection<ClassLoader>) classLoadersSetting;
for ( ClassLoader classLoader : classLoaders ) {
bsrBuilder.applyClassLoader( classLoader ); bsrBuilder.applyClassLoader( classLoader );
} }
} }
@ -470,7 +476,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
bsrBuilder.applyClassLoader( classLoader ); bsrBuilder.applyClassLoader( classLoader );
} }
} }
else if ( ClassLoader.class.isInstance( classLoadersSetting ) ) { else if ( classLoadersSetting instanceof ClassLoader ) {
bsrBuilder.applyClassLoader( (ClassLoader) classLoadersSetting ); bsrBuilder.applyClassLoader( (ClassLoader) classLoadersSetting );
} }
} }
@ -488,7 +494,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
return bsrBuilder.build(); return bsrBuilder.build();
} }
private void applyIntegrationProvider(Map integrationSettings, BootstrapServiceRegistryBuilder bsrBuilder) { private void applyIntegrationProvider(Map<?,?> integrationSettings, BootstrapServiceRegistryBuilder bsrBuilder) {
Object integrationSetting = integrationSettings.get( INTEGRATOR_PROVIDER ); Object integrationSetting = integrationSettings.get( INTEGRATOR_PROVIDER );
if ( integrationSetting == null ) { if ( integrationSetting == null ) {
return; return;
@ -506,7 +512,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
} }
@SuppressWarnings("unchecked")
private MergedSettings mergeSettings( private MergedSettings mergeSettings(
PersistenceUnitDescriptor persistenceUnit, PersistenceUnitDescriptor persistenceUnit,
Map<?,?> integrationSettings, Map<?,?> integrationSettings,
@ -536,16 +541,16 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// 2) additional cache region declarations // 2) additional cache region declarations
// //
// we will also clean up any references with null entries // we will also clean up any references with null entries
Iterator<Map.Entry> itr = mergedSettings.configurationValues.entrySet().iterator(); Iterator<Map.Entry<Object,Object>> itr = mergedSettings.configurationValues.entrySet().iterator();
while ( itr.hasNext() ) { while ( itr.hasNext() ) {
final Map.Entry entry = itr.next(); final Map.Entry<Object,Object> entry = itr.next();
if ( entry.getValue() == null ) { if ( entry.getValue() == null ) {
// remove entries with null values // remove entries with null values
itr.remove(); itr.remove();
break; break;
} }
if ( String.class.isInstance( entry.getKey() ) && String.class.isInstance( entry.getValue() ) ) { if ( entry.getKey() instanceof String && entry.getValue() instanceof String) {
final String keyString = (String) entry.getKey(); final String keyString = (String) entry.getKey();
final String valueString = (String) entry.getValue(); final String valueString = (String) entry.getValue();
@ -577,7 +582,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
/** /**
* Handles normalizing the settings coming from multiple sources, applying proper precedences * Handles normalizing the settings coming from multiple sources, applying proper precedences
*/ */
@SuppressWarnings("unchecked")
private void normalizeSettings( private void normalizeSettings(
PersistenceUnitDescriptor persistenceUnit, PersistenceUnitDescriptor persistenceUnit,
Map<?, ?> integrationSettings, Map<?, ?> integrationSettings,
@ -701,7 +705,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
return persistenceUnit.getProperties() == null ? null : (T) persistenceUnit.getProperties().get( propertyName ); return persistenceUnit.getProperties() == null ? null : (T) persistenceUnit.getProperties().get( propertyName );
} }
@SuppressWarnings("unchecked")
private void applyUserAndPass(Object effectiveUser, Object effectivePass, MergedSettings mergedSettings) { private void applyUserAndPass(Object effectiveUser, Object effectivePass, MergedSettings mergedSettings) {
if ( effectiveUser != null ) { if ( effectiveUser != null ) {
mergedSettings.configurationValues.put( USER, effectiveUser ); mergedSettings.configurationValues.put( USER, effectiveUser );
@ -718,7 +721,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
private static final String IS_JTA_TXN_COORD = "local.setting.IS_JTA_TXN_COORD"; private static final String IS_JTA_TXN_COORD = "local.setting.IS_JTA_TXN_COORD";
@SuppressWarnings("unchecked")
private void normalizeTransactionCoordinator( private void normalizeTransactionCoordinator(
PersistenceUnitDescriptor persistenceUnit, PersistenceUnitDescriptor persistenceUnit,
HashMap<?, ?> integrationSettingsCopy, HashMap<?, ?> integrationSettingsCopy,
@ -760,7 +762,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
boolean hasTxStrategy = mergedSettings.configurationValues.containsKey( TRANSACTION_COORDINATOR_STRATEGY ); boolean hasTxStrategy = mergedSettings.configurationValues.containsKey( TRANSACTION_COORDINATOR_STRATEGY );
final Boolean definiteJtaCoordinator; final boolean definiteJtaCoordinator;
if ( hasTxStrategy ) { if ( hasTxStrategy ) {
LOG.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY ); LOG.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY );
@ -871,7 +873,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// hibernate-specific settings have precedence over the JPA ones // hibernate-specific settings have precedence over the JPA ones
final Object integrationJdbcUrl = integrationSettingsCopy.get( URL ); final Object integrationJdbcUrl = integrationSettingsCopy.get( URL );
if ( integrationJdbcUrl != null ) { if ( integrationJdbcUrl != null ) {
//noinspection unchecked
applyJdbcSettings( applyJdbcSettings(
integrationJdbcUrl, integrationJdbcUrl,
NullnessHelper.coalesceSuppliedValues( NullnessHelper.coalesceSuppliedValues(
@ -907,7 +908,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
final Object integrationJdbcUrl = integrationSettingsCopy.get( JAKARTA_JDBC_URL ); final Object integrationJdbcUrl = integrationSettingsCopy.get( JAKARTA_JDBC_URL );
if ( integrationJdbcUrl != null ) { if ( integrationJdbcUrl != null ) {
//noinspection unchecked
applyJdbcSettings( applyJdbcSettings(
integrationJdbcUrl, integrationJdbcUrl,
NullnessHelper.coalesceSuppliedValues( NullnessHelper.coalesceSuppliedValues(
@ -929,7 +929,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
final Object integrationJdbcUrl = integrationSettingsCopy.get( JPA_JDBC_URL ); final Object integrationJdbcUrl = integrationSettingsCopy.get( JPA_JDBC_URL );
if ( integrationJdbcUrl != null ) { if ( integrationJdbcUrl != null ) {
//noinspection unchecked
applyJdbcSettings( applyJdbcSettings(
integrationJdbcUrl, integrationJdbcUrl,
NullnessHelper.coalesceSuppliedValues( NullnessHelper.coalesceSuppliedValues(
@ -1024,7 +1023,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
// any other conditions to account for? // any other conditions to account for?
} }
@SuppressWarnings("unchecked")
private void applyDataSource( private void applyDataSource(
Object dataSourceRef, Object dataSourceRef,
Boolean useJtaDataSource, Boolean useJtaDataSource,
@ -1108,7 +1106,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
} }
@SuppressWarnings("unchecked")
private void applyJdbcSettings( private void applyJdbcSettings(
Object url, Object url,
String driver, String driver,
@ -1256,9 +1253,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
List<ConverterDescriptor> converterDescriptors = null; List<ConverterDescriptor> converterDescriptors = null;
// add any explicit Class references passed in // add any explicit Class references passed in
final List<Class> loadedAnnotatedClasses = (List<Class>) configurationValues.remove( org.hibernate.cfg.AvailableSettings.LOADED_CLASSES ); final List<Class<? extends AttributeConverter>> loadedAnnotatedClasses = (List<Class<? extends AttributeConverter>>)
configurationValues.remove( AvailableSettings.LOADED_CLASSES );
if ( loadedAnnotatedClasses != null ) { if ( loadedAnnotatedClasses != null ) {
for ( Class cls : loadedAnnotatedClasses ) { for ( Class<? extends AttributeConverter> cls : loadedAnnotatedClasses ) {
if ( AttributeConverter.class.isAssignableFrom( cls ) ) { if ( AttributeConverter.class.isAssignableFrom( cls ) ) {
if ( converterDescriptors == null ) { if ( converterDescriptors == null ) {
converterDescriptors = new ArrayList<>(); converterDescriptors = new ArrayList<>();
@ -1517,7 +1515,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
public static class MergedSettings { public static class MergedSettings {
private final Map configurationValues = new ConcurrentHashMap( 16, 0.75f, 1 ); private final Map<Object,Object> configurationValues = new ConcurrentHashMap<>( 16, 0.75f, 1 );
private List<CacheRegionDefinition> cacheRegionDefinitions; private List<CacheRegionDefinition> cacheRegionDefinitions;
@ -1546,14 +1544,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
configurationValues.put( SESSION_FACTORY_NAME, sfName ); configurationValues.put( SESSION_FACTORY_NAME, sfName );
} }
} }
else { // else {
// make sure they match? // make sure they match?
} // }
configurationValues.putAll( loadedConfig.getConfigurationValues() ); configurationValues.putAll( loadedConfig.getConfigurationValues() );
} }
public Map getConfigurationValues() { public Map<Object,Object> getConfigurationValues() {
return configurationValues; return configurationValues;
} }
@ -1565,6 +1563,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil
} }
} }
@SuppressWarnings("unchecked")
private <T> T loadSettingInstance(String settingName, Object settingValue, Class<T> clazz) { private <T> T loadSettingInstance(String settingName, Object settingValue, Class<T> clazz) {
T instance = null; T instance = null;
Class<? extends T> instanceClass = null; Class<? extends T> instanceClass = null;

View File

@ -39,11 +39,11 @@ public class ParsedPersistenceXmlDescriptor implements org.hibernate.jpa.boot.sp
private ValidationMode validationMode; private ValidationMode validationMode;
private SharedCacheMode sharedCacheMode; private SharedCacheMode sharedCacheMode;
private Properties properties = new Properties(); private final Properties properties = new Properties();
private List<String> classes = new ArrayList<>(); private final List<String> classes = new ArrayList<>();
private List<String> mappingFiles = new ArrayList<>(); private final List<String> mappingFiles = new ArrayList<>();
private List<URL> jarFileUrls = new ArrayList<>(); private final List<URL> jarFileUrls = new ArrayList<>();
public ParsedPersistenceXmlDescriptor(URL persistenceUnitRootUrl) { public ParsedPersistenceXmlDescriptor(URL persistenceUnitRootUrl) {
this.persistenceUnitRootUrl = persistenceUnitRootUrl; this.persistenceUnitRootUrl = persistenceUnitRootUrl;