diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 2769fa8ab2..337a3f7891 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -143,7 +143,7 @@ import static org.hibernate.jpa.internal.util.FlushModeTypeHelper.getFlushModeTy * @author Steve Ebersole */ public abstract class AbstractSharedSessionContract implements SharedSessionContractImplementor { - private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( SessionImpl.class ); private transient SessionFactoryImpl factory; protected transient FastSessionServices fastSessionServices; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java index 271239f38a..9874316dff 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java @@ -48,7 +48,7 @@ import static org.jboss.logging.Logger.Level.WARN; * New messages must be added after the last message defined to ensure message codes are unique. */ @MessageLogger(projectCode = "HHH") -@ValidIdRange(min=2,max = 10000) +@ValidIdRange(min=2,max = 20000) public interface CoreMessageLogger extends BasicLogger { @LogMessage(level = WARN) @@ -937,4 +937,37 @@ public interface CoreMessageLogger extends BasicLogger { @Message(value = "Flushing and evicting managed instance of type [%s] before removing detached instance with same id", id = 530) void flushAndEvictOnRemove(String entityName); + + @LogMessage(level = ERROR) + @Message(value = "Illegal argument on static metamodel field injection : %s#%s; expected type : %s; encountered type : %s", id = 15007) + void illegalArgumentOnStaticMetamodelFieldInjection( + String name, + String name2, + String name3, + String name4); + + @LogMessage(level = WARN) + @Message(value = "Unable to locate static metamodel field : %s#%s; this may or may not indicate a problem with the static metamodel", id = 15011) + void unableToLocateStaticMetamodelField( + String name, + String name2); + + @LogMessage(level = DEBUG) + @Message(value = "Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, " + + "as the entity (type=%s, id=%s) does not exist", id = 15013) + void ignoringEntityNotFound(String entityName, String identifier); + + @LogMessage(level = DEBUG) + @Message( + id = 15015, + value = "Encountered a MappedSuperclass [%s] not used in any entity hierarchy" + ) + void unusedMappedSuperclass(String name); + + @LogMessage(level = WARN) + @Message( + id = 15018, + value = "Encountered multiple persistence-unit stanzas defining same name [%s]; persistence-unit names must be unique" + ) + void duplicatedPersistenceUnitName(String name); } diff --git a/hibernate-core/src/main/java/org/hibernate/internal/EntityManagerMessageLogger.java b/hibernate-core/src/main/java/org/hibernate/internal/EntityManagerMessageLogger.java deleted file mode 100644 index 47be4ed057..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/EntityManagerMessageLogger.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal; - -import org.jboss.logging.annotations.LogMessage; -import org.jboss.logging.annotations.Message; -import org.jboss.logging.annotations.MessageLogger; -import org.jboss.logging.annotations.ValidIdRange; - -import static org.jboss.logging.Logger.Level.DEBUG; -import static org.jboss.logging.Logger.Level.ERROR; -import static org.jboss.logging.Logger.Level.WARN; - -/** - * {@link MessageLogger} originally for the no-longer existing hibernate-entitymanager module. - */ -@MessageLogger(projectCode = "HHH") -@ValidIdRange( min = 15001, max = 20000 ) -public interface EntityManagerMessageLogger extends CoreMessageLogger { - - @LogMessage(level = ERROR) - @Message(value = "Illegal argument on static metamodel field injection : %s#%s; expected type : %s; encountered type : %s", id = 15007) - void illegalArgumentOnStaticMetamodelFieldInjection( - String name, - String name2, - String name3, - String name4); - - @LogMessage(level = WARN) - @Message(value = "Unable to locate static metamodel field : %s#%s; this may or may not indicate a problem with the static metamodel", id = 15011) - void unableToLocateStaticMetamodelField( - String name, - String name2); - - @LogMessage(level = DEBUG) - @Message(value = "Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, " + - "as the entity (type=%s, id=%s) does not exist", id = 15013) - void ignoringEntityNotFound(String entityName, String identifier); - - @LogMessage(level = DEBUG) - @Message( - id = 15015, - value = "Encountered a MappedSuperclass [%s] not used in any entity hierarchy" - ) - void unusedMappedSuperclass(String name); - - @LogMessage(level = WARN) - @Message( - id = 15016, - value = "Encountered a deprecated jakarta.persistence.spi.PersistenceProvider [%s]; [%s] will be used instead." - ) - void deprecatedPersistenceProvider(String deprecated, String replacement); - - @LogMessage(level = WARN) - @Message( - id = 15017, - value = "'hibernate.ejb.use_class_enhancer' property is deprecated. " + - "Use 'hibernate.enhance.enable[...]' properties instead to enable each individual feature." - ) - void deprecatedInstrumentationProperty(); - - @LogMessage(level = WARN) - @Message( - id = 15018, - value = "Encountered multiple persistence-unit stanzas defining same name [%s]; persistence-unit names must be unique" - ) - void duplicatedPersistenceUnitName(String name); - -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/ExceptionConverterImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/ExceptionConverterImpl.java index 64fc30fb8c..279784259d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/ExceptionConverterImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/ExceptionConverterImpl.java @@ -44,7 +44,7 @@ import jakarta.persistence.RollbackException; * @author Andrea Boriero */ public class ExceptionConverterImpl implements ExceptionConverter { - private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( ExceptionConverterImpl.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( ExceptionConverterImpl.class ); private final SharedSessionContractImplementor session; private final boolean isJpaBootstrap; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/HEMLogging.java b/hibernate-core/src/main/java/org/hibernate/internal/HEMLogging.java deleted file mode 100644 index 887ec4acbe..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/internal/HEMLogging.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Hibernate, Relational Persistence for Idiomatic Java - * - * License: GNU Lesser General Public License (LGPL), version 2.1 or later. - * See the lgpl.txt file in the root directory or . - */ -package org.hibernate.internal; - -import org.jboss.logging.Logger; - -import java.lang.invoke.MethodHandles; - -/** - * @author Steve Ebersole - */ -public class HEMLogging { - /** - * Disallow instantiation - */ - private HEMLogging() { - } - - public static EntityManagerMessageLogger messageLogger(Class classNeedingLogging) { - return messageLogger( classNeedingLogging.getName() ); - } - - public static EntityManagerMessageLogger messageLogger(String loggerName) { - return Logger.getMessageLogger( MethodHandles.lookup(), EntityManagerMessageLogger .class, loggerName ); - } - - public static Logger logger(Class classNeedingLogging) { - return Logger.getLogger( classNeedingLogging ); - } - - public static Logger logger(String loggerName) { - return Logger.getLogger( loggerName ); - } -} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 0d144e659b..f8d57ed0e0 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -218,7 +218,7 @@ public class SessionImpl extends AbstractSharedSessionContract implements Serializable, SharedSessionContractImplementor, JdbcSessionOwner, SessionImplementor, EventSource, TransactionCoordinatorBuilder.Options, WrapperOptions, LoadAccessContext { - private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( SessionImpl.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( SessionImpl.class ); // Defaults to null which means the properties are the default // as defined in FastSessionServices#defaultSessionProperties diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java b/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java index 8a1b3bcffa..c7775a9d29 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java @@ -6,8 +6,6 @@ */ package org.hibernate.jpa; -import static org.hibernate.internal.HEMLogging.messageLogger; - import java.net.URL; import java.util.Collection; import java.util.Collections; @@ -22,7 +20,8 @@ import jakarta.persistence.spi.PersistenceUnitInfo; import jakarta.persistence.spi.ProviderUtil; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.internal.EntityManagerMessageLogger; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.jpa.boot.spi.PersistenceConfigurationDescriptor; import org.hibernate.jpa.boot.spi.PersistenceXmlParser; import org.hibernate.jpa.boot.spi.Bootstrap; @@ -39,7 +38,7 @@ import org.hibernate.jpa.internal.util.PersistenceUtilHelper; * @author Brett Meyer */ public class HibernatePersistenceProvider implements PersistenceProvider { - private static final EntityManagerMessageLogger log = messageLogger( HibernatePersistenceProvider.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( HibernatePersistenceProvider.class ); private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache(); diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java index 14d834d51a..a1281fee0b 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java @@ -9,7 +9,6 @@ package org.hibernate.jpa.boot.internal; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -32,6 +31,7 @@ import org.hibernate.boot.beanvalidation.BeanValidationIntegrator; import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService; import org.hibernate.boot.cfgxml.spi.LoadedConfig; import org.hibernate.boot.cfgxml.spi.MappingReference; +import org.hibernate.boot.internal.ClassmateContext; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping; import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType; import org.hibernate.boot.jaxb.spi.Binding; @@ -63,7 +63,8 @@ import org.hibernate.cfg.Environment; import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.integrator.spi.Integrator; -import org.hibernate.internal.EntityManagerMessageLogger; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.NullnessHelper; import org.hibernate.internal.util.PropertiesHelper; import org.hibernate.internal.util.StringHelper; @@ -80,21 +81,20 @@ import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorBuilderImpl; import org.hibernate.resource.transaction.spi.TransactionCoordinatorBuilder; -import org.hibernate.service.ServiceRegistry; import org.hibernate.service.spi.ServiceBinding; import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.Stoppable; import org.hibernate.tool.schema.spi.DelayedDropRegistryNotAvailableImpl; import org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator; -import org.jboss.jandex.Index; - import jakarta.persistence.AttributeConverter; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityNotFoundException; import jakarta.persistence.PersistenceException; import jakarta.persistence.spi.PersistenceUnitTransactionType; +import static java.lang.Boolean.parseBoolean; +import static java.util.Collections.unmodifiableMap; import static org.hibernate.cfg.AvailableSettings.CFG_XML_FILE; import static org.hibernate.cfg.AvailableSettings.CLASSLOADERS; import static org.hibernate.cfg.AvailableSettings.CLASS_CACHE_PREFIX; @@ -131,15 +131,16 @@ import static org.hibernate.cfg.AvailableSettings.USER; import static org.hibernate.cfg.BytecodeSettings.ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT; import static org.hibernate.cfg.BytecodeSettings.ENHANCER_ENABLE_DIRTY_TRACKING; import static org.hibernate.cfg.BytecodeSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION; -import static org.hibernate.internal.HEMLogging.messageLogger; +import static org.hibernate.cfg.TransactionSettings.FLUSH_BEFORE_COMPLETION; import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER; +import static org.hibernate.internal.util.StringHelper.isNotEmpty; /** * @author Steve Ebersole */ -@SuppressWarnings("deprecation") +@SuppressWarnings({"deprecation", "removal"}) public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuilder { - private static final EntityManagerMessageLogger LOG = messageLogger( EntityManagerFactoryBuilderImpl.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( EntityManagerFactoryBuilderImpl.class ); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -165,11 +166,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil */ public static final String METADATA_BUILDER_CONTRIBUTOR = JpaSettings.METADATA_BUILDER_CONTRIBUTOR; - /** - * Names a Jandex {@link Index} instance to use. - */ - public static final String JANDEX_INDEX = "hibernate.jandex_index"; - private final PersistenceUnitDescriptor persistenceUnit; @@ -239,7 +235,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } Map mergedIntegrationSettings = null; - Properties properties = persistenceUnit.getProperties(); + final Properties properties = persistenceUnit.getProperties(); if ( properties != null ) { // original integration setting entries take precedence mergedIntegrationSettings = new HashMap<>( properties ); @@ -255,48 +251,49 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil try { // merge configuration sources and build the "standard" service registry - final StandardServiceRegistryBuilder ssrBuilder = getStandardServiceRegistryBuilder( bsr ); + final StandardServiceRegistryBuilder registryBuilder = getStandardServiceRegistryBuilder( bsr ); - final MergedSettings mergedSettings = mergeSettings( persistenceUnit, integrationSettings, ssrBuilder, mergedSettingsBaseline ); + final MergedSettings mergedSettings = + mergeSettings( persistenceUnit, integrationSettings, registryBuilder, mergedSettingsBaseline ); // flush before completion validation - if ( "true".equals( mergedSettings.configurationValues.get( Environment.FLUSH_BEFORE_COMPLETION ) ) ) { - LOG.definingFlushBeforeCompletionIgnoredInHem( Environment.FLUSH_BEFORE_COMPLETION ); - mergedSettings.configurationValues.put( Environment.FLUSH_BEFORE_COMPLETION, "false" ); + if ( "true".equals( mergedSettings.configurationValues.get( FLUSH_BEFORE_COMPLETION ) ) ) { + log.definingFlushBeforeCompletionIgnoredInHem( FLUSH_BEFORE_COMPLETION ); + mergedSettings.configurationValues.put( FLUSH_BEFORE_COMPLETION, "false" ); } // keep the merged config values for phase-2 - this.configurationValues = mergedSettings.getConfigurationValues(); + configurationValues = mergedSettings.getConfigurationValues(); // Build the "standard" service registry - ssrBuilder.applySettings( configurationValues ); + registryBuilder.applySettings( configurationValues ); - this.standardServiceRegistry = ssrBuilder.build(); + standardServiceRegistry = registryBuilder.build(); final MetadataSources metadataSources = new MetadataSources( standardServiceRegistry ); - this.metamodelBuilder = (MetadataBuilderImplementor) metadataSources.getMetadataBuilder( standardServiceRegistry ); - List attributeConverterDefinitions = applyMappingResources( metadataSources ); + metamodelBuilder = + (MetadataBuilderImplementor) + metadataSources.getMetadataBuilder( standardServiceRegistry ); - applyMetamodelBuilderSettings( mergedSettings, attributeConverterDefinitions ); + applyMetamodelBuilderSettings( mergedSettings, applyMappingResources( metadataSources ) ); applyMetadataBuilderContributor(); // todo : would be nice to have MetadataBuilder still do the handling of CfgXmlAccessService here // another option is to immediately handle them here (probably in mergeSettings?) as we encounter them... - final CfgXmlAccessService cfgXmlAccessService = standardServiceRegistry.requireService( CfgXmlAccessService.class ); - if ( cfgXmlAccessService.getAggregatedConfig() != null ) { - if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) { - for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig() - .getMappingReferences() ) { + final LoadedConfig aggregatedConfig = + standardServiceRegistry.requireService( CfgXmlAccessService.class ) + .getAggregatedConfig(); + if ( aggregatedConfig != null ) { + final List mappingReferences = aggregatedConfig.getMappingReferences(); + if ( mappingReferences != null ) { + for ( MappingReference mappingReference : mappingReferences ) { mappingReference.apply( metadataSources ); } } } - this.managedResources = MetadataBuildingProcess.prepare( - metadataSources, - metamodelBuilder.getBootstrapContext() - ); + managedResources = MetadataBuildingProcess.prepare( metadataSources, metamodelBuilder.getBootstrapContext() ); final Object validatorFactory = configurationValues.get( JAKARTA_VALIDATION_FACTORY ); if ( validatorFactory == null ) { @@ -312,23 +309,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - final boolean dirtyTrackingEnabled; - Object propertyValue = configurationValues.remove( ENHANCER_ENABLE_DIRTY_TRACKING ); - if ( propertyValue != null ) { - dirtyTrackingEnabled = Boolean.parseBoolean( propertyValue.toString() ); - } - else { - dirtyTrackingEnabled = true; - } - final boolean lazyInitializationEnabled; - propertyValue = configurationValues.remove( ENHANCER_ENABLE_LAZY_INITIALIZATION ); - if ( propertyValue != null ) { - lazyInitializationEnabled = Boolean.parseBoolean( propertyValue.toString() ); - } - else { - lazyInitializationEnabled = true; - } - final boolean associationManagementEnabled = readBooleanConfigurationValue( ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT ); + final boolean dirtyTrackingEnabled = + readBooleanConfigurationValueDefaultTrue( ENHANCER_ENABLE_DIRTY_TRACKING ); + final boolean lazyInitializationEnabled = + readBooleanConfigurationValueDefaultTrue( ENHANCER_ENABLE_LAZY_INITIALIZATION ); + final boolean associationManagementEnabled = + readBooleanConfigurationValue( ENHANCER_ENABLE_ASSOCIATION_MANAGEMENT ); + if ( !lazyInitializationEnabled ) { DEPRECATION_LOGGER.deprecatedSettingForRemoval( ENHANCER_ENABLE_LAZY_INITIALIZATION, "true" ); } @@ -337,11 +324,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } if ( dirtyTrackingEnabled || lazyInitializationEnabled || associationManagementEnabled ) { - EnhancementContext enhancementContext = getEnhancementContext( - dirtyTrackingEnabled, - lazyInitializationEnabled, - associationManagementEnabled - ); + final EnhancementContext enhancementContext = + getEnhancementContext( dirtyTrackingEnabled, + lazyInitializationEnabled, + associationManagementEnabled ); // push back class transformation to the environment; for the time being this only has any effect in EE // container situations, calling back into PersistenceUnitInfo#addClassTransformer @@ -357,18 +343,15 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil final JaxbHbmHibernateMapping hibernateMapping = binding.getRoot(); final String packageName = hibernateMapping.getPackage(); for ( JaxbHbmRootEntityType clazz : hibernateMapping.getClazz() ) { - final String className; - if ( packageName == null || packageName.isEmpty() ) { - className = clazz.getName(); - } - else { - className = packageName + '.' + clazz.getName(); - } + final String className = + packageName == null || packageName.isEmpty() + ? clazz.getName() + : packageName + '.' + clazz.getName(); try { classTransformer.discoverTypes( classLoader, className ); } catch (EnhancementException ex) { - LOG.enhancementDiscoveryFailed( className, ex ); + log.enhancementDiscoveryFailed( className, ex ); } } } @@ -391,6 +374,11 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } } + private boolean readBooleanConfigurationValueDefaultTrue(String propertyName) { + final Object propertyValue = configurationValues.remove( propertyName ); + return propertyValue == null || parseBoolean( propertyValue.toString() ); + } + /** * Extension point for subclasses. Used by Hibernate Reactive */ @@ -415,19 +403,19 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil metamodelBuilder.getBootstrapContext().getServiceRegistry() .requireService( ClassLoaderService.class ) .loadJavaServices( MetadataBuilderContributor.class ) - .forEach( (contributor) -> contributor.contribute( metamodelBuilder ) ); + .forEach( contributor -> contributor.contribute( metamodelBuilder ) ); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // temporary! public Map getConfigurationValues() { - return Collections.unmodifiableMap( configurationValues ); + return unmodifiableMap( configurationValues ); } // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ private boolean readBooleanConfigurationValue(String propertyName) { - Object propertyValue = configurationValues.remove( propertyName ); - return propertyValue != null && Boolean.parseBoolean( propertyValue.toString() ); + final Object propertyValue = configurationValues.remove( propertyName ); + return propertyValue != null && parseBoolean( propertyValue.toString() ); } /** @@ -447,13 +435,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil @Override public boolean isEntityClass(UnloadedClass classDescriptor) { return managedResources.getAnnotatedClassNames().contains( classDescriptor.getName() ) - && super.isEntityClass( classDescriptor ); + && super.isEntityClass( classDescriptor ); } @Override public boolean isCompositeClass(UnloadedClass classDescriptor) { return managedResources.getAnnotatedClassNames().contains( classDescriptor.getName() ) - && super.isCompositeClass( classDescriptor ); + && super.isCompositeClass( classDescriptor ); } @Override @@ -481,7 +469,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // doesn't make any sense to have extended enhancement enabled at runtime. we only enhance entities anyway. return false; } - }; } @@ -497,21 +484,18 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil Map integrationSettings, ClassLoader providedClassLoader, ClassLoaderService providedClassLoaderService) { - final BootstrapServiceRegistryBuilder bsrBuilder = new BootstrapServiceRegistryBuilder(); - - applyIntegrationProvider( integrationSettings, bsrBuilder ); - + final BootstrapServiceRegistryBuilder builder = new BootstrapServiceRegistryBuilder(); + applyIntegrationProvider( integrationSettings, builder ); final StrategyRegistrationProviderList strategyRegistrationProviderList = (StrategyRegistrationProviderList) integrationSettings.get( STRATEGY_REGISTRATION_PROVIDERS ); if ( strategyRegistrationProviderList != null ) { - for ( StrategyRegistrationProvider strategyRegistrationProvider : strategyRegistrationProviderList.getStrategyRegistrationProviders() ) { - bsrBuilder.applyStrategySelectors( strategyRegistrationProvider ); + for ( StrategyRegistrationProvider strategyRegistrationProvider : + strategyRegistrationProviderList.getStrategyRegistrationProviders() ) { + builder.applyStrategySelectors( strategyRegistrationProvider ); } } - - configureClassLoading( integrationSettings, providedClassLoader, providedClassLoaderService, bsrBuilder ); - - return bsrBuilder.build(); + configureClassLoading( integrationSettings, providedClassLoader, providedClassLoaderService, builder ); + return builder.build(); } /** @@ -542,7 +526,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( classLoadersSetting != null ) { if ( classLoadersSetting instanceof Collection) { @SuppressWarnings("unchecked") - Collection classLoaders = (Collection) classLoadersSetting; + final Collection classLoaders = + (Collection) classLoadersSetting; for ( ClassLoader classLoader : classLoaders ) { bsrBuilder.applyClassLoader( classLoader ); } @@ -568,7 +553,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } private void applyIntegrationProvider(Map integrationSettings, BootstrapServiceRegistryBuilder bsrBuilder) { - Object integrationSetting = integrationSettings.get( INTEGRATOR_PROVIDER ); + final Object integrationSetting = integrationSettings.get( INTEGRATOR_PROVIDER ); if ( integrationSetting == null ) { return; } @@ -603,7 +588,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil cfgXmlResourceName = (String) integrationSettings.get( CFG_XML_FILE ); } - if ( StringHelper.isNotEmpty( cfgXmlResourceName ) ) { + if ( isNotEmpty( cfgXmlResourceName ) ) { processHibernateConfigXmlResources( ssrBuilder, mergedSettings, cfgXmlResourceName ); } @@ -614,19 +599,18 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // 2) additional cache region declarations // // we will also clean up any references with null entries - Iterator> itr = mergedSettings.configurationValues.entrySet().iterator(); - while ( itr.hasNext() ) { - final Map.Entry entry = itr.next(); + final Iterator> iterator = + mergedSettings.configurationValues.entrySet().iterator(); + while ( iterator.hasNext() ) { + final Map.Entry entry = iterator.next(); if ( entry.getValue() == null ) { // remove entries with null values - itr.remove(); + iterator.remove(); break; } - if ( entry.getValue() instanceof String) { + if ( entry.getValue() instanceof String valueString ) { final String keyString = entry.getKey(); - final String valueString = (String) entry.getValue(); - if ( keyString.startsWith( CLASS_CACHE_PREFIX ) ) { mergedSettings.addCacheRegionDefinition( parseCacheRegionDefinitionEntry( @@ -702,15 +686,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // NOTE that this occurs after the specialized normalize calls above which remove // any specially-handled settings. for ( Map.Entry entry : integrationSettingsCopy.entrySet() ) { - if ( entry.getKey() == null ) { - continue; - } - - if ( entry.getValue() == null ) { - mergedSettings.configurationValues.remove( entry.getKey() ); - } - else { - mergedSettings.configurationValues.put( entry.getKey(), entry.getValue() ); + if ( entry.getKey() != null ) { + if ( entry.getValue() == null ) { + mergedSettings.configurationValues.remove( entry.getKey() ); + } + else { + mergedSettings.configurationValues.put( entry.getKey(), entry.getValue() ); + } } } } @@ -772,21 +754,22 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } private T extractPuProperty(PersistenceUnitDescriptor persistenceUnit, String propertyName) { + final Properties properties = persistenceUnit.getProperties(); //noinspection unchecked - return persistenceUnit.getProperties() == null ? null : (T) persistenceUnit.getProperties().get( propertyName ); + return properties == null ? null : (T) properties.get( propertyName ); } private void applyUserAndPass(Object effectiveUser, Object effectivePass, MergedSettings mergedSettings) { + final Map configuration = mergedSettings.configurationValues; if ( effectiveUser != null ) { - mergedSettings.configurationValues.put( USER, effectiveUser ); - mergedSettings.configurationValues.put( JAKARTA_JDBC_USER, effectiveUser ); - mergedSettings.configurationValues.put( JPA_JDBC_USER, effectiveUser ); + configuration.put( USER, effectiveUser ); + configuration.put( JAKARTA_JDBC_USER, effectiveUser ); + configuration.put( JPA_JDBC_USER, effectiveUser ); } - if ( effectivePass != null ) { - mergedSettings.configurationValues.put( PASS, effectivePass ); - mergedSettings.configurationValues.put( JAKARTA_JDBC_PASSWORD, effectivePass ); - mergedSettings.configurationValues.put( JPA_JDBC_PASSWORD, effectivePass ); + configuration.put( PASS, effectivePass ); + configuration.put( JAKARTA_JDBC_PASSWORD, effectivePass ); + configuration.put( JPA_JDBC_PASSWORD, effectivePass ); } } @@ -820,7 +803,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil DEPRECATION_LOGGER.deprecatedSetting( JPA_TRANSACTION_TYPE, JAKARTA_TRANSACTION_TYPE ); } } - if ( puPropTxnType != null ) { txnType = PersistenceUnitTransactionTypeHelper.interpretTransactionType( puPropTxnType ); } @@ -828,32 +810,31 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( txnType == null ) { // is it more appropriate to have this be based on bootstrap entry point (EE vs SE)? - LOG.debug( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" ); + log.debug( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" ); txnType = PersistenceUnitTransactionType.RESOURCE_LOCAL; } - boolean hasTxStrategy = mergedSettings.configurationValues.containsKey( TRANSACTION_COORDINATOR_STRATEGY ); + final boolean hasTxStrategy = + mergedSettings.configurationValues.containsKey( TRANSACTION_COORDINATOR_STRATEGY ); final boolean definiteJtaCoordinator; - if ( hasTxStrategy ) { - LOG.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY ); - + log.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY ); // see if we can tell whether it is a JTA coordinator - final Object strategy = mergedSettings.configurationValues.get( TRANSACTION_COORDINATOR_STRATEGY ); - if ( strategy instanceof TransactionCoordinatorBuilder ) { - definiteJtaCoordinator = ( (TransactionCoordinatorBuilder) strategy ).isJta(); - } - else { - definiteJtaCoordinator = false; - } + final Object strategy = + mergedSettings.configurationValues.get( TRANSACTION_COORDINATOR_STRATEGY ); + definiteJtaCoordinator = + strategy instanceof TransactionCoordinatorBuilder transactionCoordinatorBuilder + && transactionCoordinatorBuilder.isJta(); } else { if ( txnType == PersistenceUnitTransactionType.JTA ) { - mergedSettings.configurationValues.put( TRANSACTION_COORDINATOR_STRATEGY, JtaTransactionCoordinatorBuilderImpl.class ); + mergedSettings.configurationValues.put( TRANSACTION_COORDINATOR_STRATEGY, + JtaTransactionCoordinatorBuilderImpl.class ); definiteJtaCoordinator = true; } else if ( txnType == PersistenceUnitTransactionType.RESOURCE_LOCAL ) { - mergedSettings.configurationValues.put( TRANSACTION_COORDINATOR_STRATEGY, JdbcResourceLocalTransactionCoordinatorBuilderImpl.class ); + mergedSettings.configurationValues.put( TRANSACTION_COORDINATOR_STRATEGY, + JdbcResourceLocalTransactionCoordinatorBuilderImpl.class ); definiteJtaCoordinator = false; } else { @@ -869,14 +850,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil MergedSettings mergedSettings, PersistenceUnitDescriptor persistenceUnit) { if ( dataSource != null ) { - applyDataSource( - dataSource, - // we don't explicitly know - null, - integrationSettingsCopy, - mergedSettings - ); - + // we don't explicitly know if it's JTA + applyDataSource( dataSource, null, integrationSettingsCopy, mergedSettings ); // EARLY EXIT!! return; } @@ -884,13 +859,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( integrationSettingsCopy.containsKey( DATASOURCE ) ) { final Object dataSourceRef = integrationSettingsCopy.remove( DATASOURCE ); if ( dataSourceRef != null ) { - applyDataSource( - dataSourceRef, - null, - integrationSettingsCopy, - mergedSettings - ); - + applyDataSource( dataSourceRef, null, integrationSettingsCopy, mergedSettings ); // EARLY EXIT!! return; } @@ -899,13 +868,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( integrationSettingsCopy.containsKey( JAKARTA_JTA_DATASOURCE ) ) { final Object dataSourceRef = integrationSettingsCopy.remove( JAKARTA_JTA_DATASOURCE ); if ( dataSourceRef != null ) { - applyDataSource( - dataSourceRef, - true, - integrationSettingsCopy, - mergedSettings - ); - + applyDataSource( dataSourceRef, true, integrationSettingsCopy, mergedSettings ); // EARLY EXIT!! return; } @@ -916,7 +879,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil final Object dataSourceRef = integrationSettingsCopy.remove( JPA_JTA_DATASOURCE ); if ( dataSourceRef != null ) { applyDataSource( dataSourceRef, true,integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } @@ -925,17 +887,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( integrationSettingsCopy.containsKey( JAKARTA_NON_JTA_DATASOURCE ) ) { final Object dataSourceRef = integrationSettingsCopy.remove( JAKARTA_NON_JTA_DATASOURCE ); applyDataSource( dataSourceRef, false, integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } if ( integrationSettingsCopy.containsKey( JPA_NON_JTA_DATASOURCE ) ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_NON_JTA_DATASOURCE, JAKARTA_NON_JTA_DATASOURCE ); - final Object dataSourceRef = integrationSettingsCopy.remove( JPA_NON_JTA_DATASOURCE ); applyDataSource( dataSourceRef, false, integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } @@ -950,7 +909,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil () -> ConfigurationHelper.getString( DRIVER, integrationSettingsCopy ), () -> ConfigurationHelper.getString( JAKARTA_JDBC_DRIVER, integrationSettingsCopy ), () -> { - final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy ); + final String driver = + ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy ); if ( driver != null ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JDBC_DRIVER ); } @@ -959,7 +919,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil () -> ConfigurationHelper.getString( DRIVER, mergedSettings.configurationValues ), () -> ConfigurationHelper.getString( JAKARTA_JDBC_DRIVER, mergedSettings.configurationValues ), () -> { - final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ); + final String driver = + ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ); if ( driver != null ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JDBC_DRIVER ); } @@ -969,7 +930,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } @@ -977,7 +937,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( integrationSettingsCopy.containsKey( JAKARTA_JDBC_URL ) ) { final Object integrationJdbcUrl = integrationSettingsCopy.get( JAKARTA_JDBC_URL ); - if ( integrationJdbcUrl != null ) { applyJdbcSettings( integrationJdbcUrl, @@ -988,7 +947,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } @@ -996,22 +954,22 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( integrationSettingsCopy.containsKey( JPA_JDBC_URL ) ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_URL, JAKARTA_JDBC_URL ); - final Object integrationJdbcUrl = integrationSettingsCopy.get( JPA_JDBC_URL ); - if ( integrationJdbcUrl != null ) { applyJdbcSettings( integrationJdbcUrl, NullnessHelper.coalesceSuppliedValues( () -> { - final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy ); + final String driver = + ConfigurationHelper.getString( JPA_JDBC_DRIVER, integrationSettingsCopy ); if ( driver != null ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JDBC_DRIVER ); } return driver; }, () -> { - final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ); + final String driver = + ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ); if ( driver != null ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JDBC_DRIVER ); } @@ -1021,37 +979,34 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } } if ( persistenceUnit.getJtaDataSource() != null ) { - applyDataSource( persistenceUnit.getJtaDataSource(), true, integrationSettingsCopy, mergedSettings ); - + applyDataSource( persistenceUnit.getJtaDataSource(), + true, integrationSettingsCopy, mergedSettings ); // EARLY EXIT!! return; } if ( persistenceUnit.getNonJtaDataSource() != null ) { - applyDataSource( persistenceUnit.getNonJtaDataSource(), false, integrationSettingsCopy, mergedSettings ); - + applyDataSource( persistenceUnit.getNonJtaDataSource(), + false, integrationSettingsCopy, mergedSettings ); // EARLY EXIT!! return; } if ( mergedSettings.configurationValues.containsKey( URL ) ) { final Object url = mergedSettings.configurationValues.get( URL ); - - if ( url != null && ( ! ( url instanceof String ) || StringHelper.isNotEmpty( (String) url ) ) ) { + if ( url != null && ( ! ( url instanceof String stringUrl ) || isNotEmpty( stringUrl ) ) ) { applyJdbcSettings( url, ConfigurationHelper.getString( DRIVER, mergedSettings.configurationValues ), integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } @@ -1059,15 +1014,13 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( mergedSettings.configurationValues.containsKey( JAKARTA_JDBC_URL ) ) { final Object url = mergedSettings.configurationValues.get( JAKARTA_JDBC_URL ); - - if ( url != null && ( ! ( url instanceof String ) || StringHelper.isNotEmpty( (String) url ) ) ) { + if ( url != null && ( ! ( url instanceof String stringUrl ) || isNotEmpty( stringUrl ) ) ) { applyJdbcSettings( url, ConfigurationHelper.getString( JAKARTA_JDBC_DRIVER, mergedSettings.configurationValues ), integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! return; } @@ -1075,16 +1028,14 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( mergedSettings.configurationValues.containsKey( JPA_JDBC_URL ) ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_URL, JAKARTA_JDBC_URL ); - final Object url = mergedSettings.configurationValues.get( JPA_JDBC_URL ); - - if ( url != null && ( ! ( url instanceof String ) || StringHelper.isNotEmpty( (String) url ) ) ) { - final String driver = ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ); + if ( url != null && ( !( url instanceof String stringUrl ) || isNotEmpty( stringUrl ) ) ) { + final String driver = + ConfigurationHelper.getString( JPA_JDBC_DRIVER, mergedSettings.configurationValues ); if ( driver != null ) { DEPRECATION_LOGGER.deprecatedSetting( JPA_JDBC_DRIVER, JAKARTA_JDBC_DRIVER ); } applyJdbcSettings( url, driver, integrationSettingsCopy, mergedSettings ); - // EARLY EXIT!! //noinspection UnnecessaryReturnStatement return; @@ -1104,7 +1055,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // the execution environment "is JTA" as best as it can tell.. // // we use this value when JTA was not explicitly specified in regards to the DataSource - final boolean isJtaTransactionCoordinator = (boolean) mergedSettings.configurationValues.remove( IS_JTA_TXN_COORD ); + final boolean isJtaTransactionCoordinator = + (Boolean) mergedSettings.configurationValues.remove( IS_JTA_TXN_COORD ); final boolean isJta = useJtaDataSource == null ? isJtaTransactionCoordinator : useJtaDataSource; // add to EMF properties (questionable - see HHH-13432) @@ -1161,12 +1113,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil for ( String key : keys ) { final Object removedIntgSetting = integrationSettingsCopy.remove( key ); if ( removedIntgSetting != null ) { - LOG.debugf( "Removed integration override setting [%s] due to normalization", key ); + log.debugf( "Removed integration override setting [%s] due to normalization", key ); } final Object removedMergedSetting = mergedSettings.configurationValues.remove( key ); if ( removedMergedSetting != null ) { - LOG.debugf( "Removed merged setting [%s] due to normalization", key ); + log.debugf( "Removed merged setting [%s] due to normalization", key ); } } } @@ -1226,54 +1178,50 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } private void processHibernateConfigXmlResources( - StandardServiceRegistryBuilder ssrBuilder, + StandardServiceRegistryBuilder serviceRegistryBuilder, MergedSettings mergedSettings, String cfgXmlResourceName) { - final LoadedConfig loadedConfig = ssrBuilder.getConfigLoader().loadConfigXmlResource( cfgXmlResourceName ); - + final LoadedConfig loadedConfig = + serviceRegistryBuilder.getConfigLoader().loadConfigXmlResource( cfgXmlResourceName ); mergedSettings.processHibernateConfigXmlResources( loadedConfig ); - - ssrBuilder.getAggregatedCfgXml().merge( loadedConfig ); + serviceRegistryBuilder.getAggregatedCfgXml().merge( loadedConfig ); } - private CacheRegionDefinition parseCacheRegionDefinitionEntry(String role, String value, CacheRegionDefinition.CacheRegionType cacheType) { + private CacheRegionDefinition parseCacheRegionDefinitionEntry( + String role, String value, CacheRegionDefinition.CacheRegionType cacheType) { final StringTokenizer params = new StringTokenizer( value, ";, " ); if ( !params.hasMoreTokens() ) { - StringBuilder error = new StringBuilder( "Illegal usage of " ); - if ( cacheType == CacheRegionDefinition.CacheRegionType.ENTITY ) { - error.append( CLASS_CACHE_PREFIX ) - .append( ": " ) - .append( CLASS_CACHE_PREFIX ); - } - else { - error.append( COLLECTION_CACHE_PREFIX ) - .append( ": " ) - .append( COLLECTION_CACHE_PREFIX ); - } - error.append( '.' ) - .append( role ) - .append( ' ' ) - .append( value ) - .append( ". Was expecting configuration (usage[,region[,lazy]]), but found none" ); - throw persistenceException( error.toString() ); - } - - String usage = params.nextToken(); - String region = null; - if ( params.hasMoreTokens() ) { - region = params.nextToken(); - } - boolean lazyProperty = true; - if ( cacheType == CacheRegionDefinition.CacheRegionType.ENTITY ) { - if ( params.hasMoreTokens() ) { - lazyProperty = "all".equalsIgnoreCase( params.nextToken() ); - } + throw illegalUsageException( role, value, cacheType ); } else { - lazyProperty = false; + final String usage = params.nextToken(); + final String region = params.hasMoreTokens() ? params.nextToken() : null; + final boolean lazyProperty = + cacheType == CacheRegionDefinition.CacheRegionType.ENTITY + && ( !params.hasMoreTokens() || "all".equalsIgnoreCase( params.nextToken() ) ); + return new CacheRegionDefinition( cacheType, role, usage, region, lazyProperty ); } + } - return new CacheRegionDefinition( cacheType, role, usage, region, lazyProperty ); + private PersistenceException illegalUsageException( + String role, String value, CacheRegionDefinition.CacheRegionType cacheType) { + final StringBuilder error = new StringBuilder( "Illegal usage of " ); + if ( cacheType == CacheRegionDefinition.CacheRegionType.ENTITY ) { + error.append( CLASS_CACHE_PREFIX ) + .append( ": " ) + .append( CLASS_CACHE_PREFIX ); + } + else { + error.append( COLLECTION_CACHE_PREFIX ) + .append( ": " ) + .append( COLLECTION_CACHE_PREFIX ); + } + error.append( '.' ) + .append(role) + .append( ' ' ) + .append(value) + .append( ". Was expecting configuration (usage[,region[,lazy]]), but found none" ); + return persistenceException( error.toString() ); } @SuppressWarnings("unchecked") @@ -1324,17 +1272,18 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil List converterDescriptors = null; // add any explicit Class references passed in - final List>> loadedAnnotatedClasses = (List>>) - configurationValues.remove( AvailableSettings.LOADED_CLASSES ); + final List>> loadedAnnotatedClasses = + (List>>) + configurationValues.remove( AvailableSettings.LOADED_CLASSES ); if ( loadedAnnotatedClasses != null ) { for ( Class> cls : loadedAnnotatedClasses ) { if ( AttributeConverter.class.isAssignableFrom( cls ) ) { if ( converterDescriptors == null ) { converterDescriptors = new ArrayList<>(); } - converterDescriptors.add( - new ClassBasedConverterDescriptor( cls, metamodelBuilder.getBootstrapContext().getClassmateContext() ) - ); + final ClassmateContext classmateContext = + metamodelBuilder.getBootstrapContext().getClassmateContext(); + converterDescriptors.add( new ClassBasedConverterDescriptor( cls, classmateContext ) ); } else { metadataSources.addAnnotatedClass( cls ); @@ -1343,7 +1292,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } // add any explicit hbm.xml references passed in - final String explicitHbmXmls = (String) configurationValues.remove( org.hibernate.cfg.AvailableSettings.HBM_XML_FILES ); + final String explicitHbmXmls = + (String) configurationValues.remove( AvailableSettings.HBM_XML_FILES ); if ( explicitHbmXmls != null ) { for ( String hbmXml : StringHelper.split( ", ", explicitHbmXmls ) ) { metadataSources.addResource( hbmXml ); @@ -1351,7 +1301,8 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } // add any explicit orm.xml references passed in - final List explicitOrmXmlList = (List) configurationValues.remove( org.hibernate.cfg.AvailableSettings.ORM_XML_FILES ); + final List explicitOrmXmlList = + (List) configurationValues.remove( AvailableSettings.ORM_XML_FILES ); if ( explicitOrmXmlList != null ) { explicitOrmXmlList.forEach( metadataSources::addResource ); } @@ -1388,14 +1339,11 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } private void applyTypeContributors() { - final TypeContributorList typeContributorList = (TypeContributorList) configurationValues.remove( - TYPE_CONTRIBUTORS - ); - + final TypeContributorList typeContributorList = + (TypeContributorList) configurationValues.remove( TYPE_CONTRIBUTORS ); if ( typeContributorList != null ) { typeContributorList.getTypeContributors().forEach( metamodelBuilder::applyTypes ); } - metamodelBuilder.getBootstrapContext().getServiceRegistry() .requireService( ClassLoaderService.class ) .loadJavaServices( TypeContributor.class ) @@ -1426,12 +1374,11 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil */ @Override public MetadataImplementor metadata() { - if ( this.metadata == null ) { - this.metadata = MetadataBuildingProcess.complete( - managedResources, - metamodelBuilder.getBootstrapContext(), - metamodelBuilder.getMetadataBuildingOptions() - ); + if ( metadata == null ) { + metadata = + MetadataBuildingProcess.complete( managedResources, + metamodelBuilder.getBootstrapContext(), + metamodelBuilder.getMetadataBuildingOptions() ); } return metadata; } @@ -1439,7 +1386,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil @Override public EntityManagerFactoryBuilder withValidatorFactory(Object validatorFactory) { this.validatorFactory = validatorFactory; - if ( validatorFactory != null ) { BeanValidationIntegrator.validateFactory( validatorFactory ); } @@ -1449,7 +1395,6 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil @Override public EntityManagerFactoryBuilder withDataSource(DataSource dataSource) { this.dataSource = dataSource; - return this; } @@ -1461,11 +1406,10 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil private void cleanup() { // Stop and de-register the ConnectionProvider to prevent connections lying around - if ( standardServiceRegistry instanceof ServiceRegistryImplementor && - standardServiceRegistry instanceof ServiceBinding.ServiceLifecycleOwner ) { - final ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) standardServiceRegistry; - final ServiceBinding.ServiceLifecycleOwner lifecycleOwner = (ServiceBinding.ServiceLifecycleOwner) serviceRegistry; - final ServiceBinding binding = serviceRegistry.locateServiceBinding( ConnectionProvider.class ); + if ( standardServiceRegistry instanceof ServiceRegistryImplementor serviceRegistry + && standardServiceRegistry instanceof ServiceBinding.ServiceLifecycleOwner lifecycleOwner ) { + final ServiceBinding binding = + serviceRegistry.locateServiceBinding( ConnectionProvider.class ); if ( binding != null && binding.getService() instanceof Stoppable ) { lifecycleOwner.stopService( binding ); binding.setService( null ); @@ -1478,12 +1422,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // This seems overkill, but building the SF is necessary to get the Integrators to kick in. // Metamodel will clean this up... try { - SessionFactoryBuilder sfBuilder = metadata().getSessionFactoryBuilder(); - populateSfBuilder( sfBuilder, standardServiceRegistry ); - - SchemaManagementToolCoordinator.process( - metadata, standardServiceRegistry, configurationValues, DelayedDropRegistryNotAvailableImpl.INSTANCE - ); + populateSessionFactoryBuilder( metadata().getSessionFactoryBuilder(), standardServiceRegistry ); + SchemaManagementToolCoordinator.process( metadata, standardServiceRegistry, configurationValues, + DelayedDropRegistryNotAvailableImpl.INSTANCE ); } catch (Exception e) { throw persistenceException( "Error performing schema management", e ); @@ -1498,13 +1439,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil public EntityManagerFactory build() { boolean success = false; try { - final SessionFactoryBuilder sfBuilder = metadata().getSessionFactoryBuilder(); - populateSfBuilder( sfBuilder, standardServiceRegistry ); - + final SessionFactoryBuilder sessionFactoryBuilder = metadata().getSessionFactoryBuilder(); + populateSessionFactoryBuilder( sessionFactoryBuilder, standardServiceRegistry ); try { - final EntityManagerFactory emf = sfBuilder.build(); + final EntityManagerFactory entityManagerFactory = sessionFactoryBuilder.build(); success = true; - return emf; + return entityManagerFactory; } catch (Exception e) { throw persistenceException( "Unable to build Hibernate SessionFactory", e ); @@ -1517,9 +1457,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } } - protected void populateSfBuilder(SessionFactoryBuilder sfBuilder, StandardServiceRegistry ssr) { - - final StrategySelector strategySelector = ssr.requireService( StrategySelector.class ); + protected void populateSessionFactoryBuilder(SessionFactoryBuilder builder, StandardServiceRegistry registry) { // // Locate and apply the requested SessionFactory-level interceptor (if one) // final Object sessionFactoryInterceptorSetting = configurationValues.remove( org.hibernate.cfg.AvailableSettings.INTERCEPTOR ); @@ -1530,32 +1468,34 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil // } // will use user override value or default to false if not supplied to follow JPA spec. - final boolean jtaTransactionAccessEnabled = readBooleanConfigurationValue( AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS ); + final boolean jtaTransactionAccessEnabled = + readBooleanConfigurationValue( AvailableSettings.ALLOW_JTA_TRANSACTION_ACCESS ); if ( !jtaTransactionAccessEnabled ) { - ( ( SessionFactoryBuilderImplementor ) sfBuilder ).disableJtaTransactionAccess(); + ( ( SessionFactoryBuilderImplementor ) builder ).disableJtaTransactionAccess(); } - final boolean allowRefreshDetachedEntity = readBooleanConfigurationValue( AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY ); + final boolean allowRefreshDetachedEntity = + readBooleanConfigurationValue( AvailableSettings.ALLOW_REFRESH_DETACHED_ENTITY ); if ( !allowRefreshDetachedEntity ) { - ( (SessionFactoryBuilderImplementor) sfBuilder ).disableRefreshDetachedEntity(); + ( (SessionFactoryBuilderImplementor) builder ).disableRefreshDetachedEntity(); } // Locate and apply any requested SessionFactoryObserver - final Object sessionFactoryObserverSetting = configurationValues.remove( AvailableSettings.SESSION_FACTORY_OBSERVER ); + final Object sessionFactoryObserverSetting = + configurationValues.remove( AvailableSettings.SESSION_FACTORY_OBSERVER ); if ( sessionFactoryObserverSetting != null ) { - final SessionFactoryObserver suppliedSessionFactoryObserver = strategySelector.resolveStrategy( - SessionFactoryObserver.class, - sessionFactoryObserverSetting - ); - sfBuilder.addSessionFactoryObservers( suppliedSessionFactoryObserver ); + final SessionFactoryObserver suppliedSessionFactoryObserver = + registry.requireService( StrategySelector.class ) + .resolveStrategy( SessionFactoryObserver.class, sessionFactoryObserverSetting ); + builder.addSessionFactoryObservers( suppliedSessionFactoryObserver ); } - sfBuilder.addSessionFactoryObservers( ServiceRegistryCloser.INSTANCE ); + builder.addSessionFactoryObservers( ServiceRegistryCloser.INSTANCE ); - sfBuilder.applyEntityNotFoundDelegate( JpaEntityNotFoundDelegate.INSTANCE ); + builder.applyEntityNotFoundDelegate( JpaEntityNotFoundDelegate.INSTANCE ); - if ( this.validatorFactory != null ) { - sfBuilder.applyValidatorFactory( validatorFactory ); + if ( validatorFactory != null ) { + builder.applyValidatorFactory( validatorFactory ); } } @@ -1573,10 +1513,12 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil @Override public void sessionFactoryClosed(SessionFactory sessionFactory) { - SessionFactoryImplementor sfi = ( (SessionFactoryImplementor) sessionFactory ); - sfi.getServiceRegistry().destroy(); - ServiceRegistry basicRegistry = sfi.getServiceRegistry().getParentServiceRegistry(); - ( (ServiceRegistryImplementor) basicRegistry ).destroy(); + final SessionFactoryImplementor factoryImplementor = (SessionFactoryImplementor) sessionFactory; + final ServiceRegistryImplementor serviceRegistry = factoryImplementor.getServiceRegistry(); + serviceRegistry.destroy(); + final ServiceRegistryImplementor basicRegistry = + (ServiceRegistryImplementor) serviceRegistry.getParentServiceRegistry(); + basicRegistry.destroy(); } } @@ -1585,10 +1527,7 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } protected PersistenceException persistenceException(String message, Exception cause) { - return new PersistenceException( - getExceptionHeader() + message, - cause - ); + return new PersistenceException( getExceptionHeader() + message, cause ); } private String getExceptionHeader() { @@ -1611,24 +1550,21 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil if ( persistenceUnit.getProperties() != null ) { configurationValues.putAll( PropertiesHelper.map( persistenceUnit.getProperties() ) ); } - configurationValues.put( PERSISTENCE_UNIT_NAME, persistenceUnit.getName() ); - } public void processHibernateConfigXmlResources(LoadedConfig loadedConfig){ - if ( ! configurationValues.containsKey( SESSION_FACTORY_NAME ) ) { + if ( !configurationValues.containsKey( SESSION_FACTORY_NAME ) ) { // there is not already a SF-name in the merged settings - final String sfName = loadedConfig.getSessionFactoryName(); - if ( sfName != null ) { + final String sessionFactoryName = loadedConfig.getSessionFactoryName(); + if ( sessionFactoryName != null ) { // but the cfg.xml file we are processing named one.. - configurationValues.put( SESSION_FACTORY_NAME, sfName ); + configurationValues.put( SESSION_FACTORY_NAME, sessionFactoryName ); } } // else { // make sure they match? // } - configurationValues.putAll( loadedConfig.getConfigurationValues() ); } @@ -1637,48 +1573,45 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil } private void addCacheRegionDefinition(CacheRegionDefinition cacheRegionDefinition) { - if ( this.cacheRegionDefinitions == null ) { - this.cacheRegionDefinitions = new ArrayList<>(); + if ( cacheRegionDefinitions == null ) { + cacheRegionDefinitions = new ArrayList<>(); } - this.cacheRegionDefinitions.add( cacheRegionDefinition ); + cacheRegionDefinitions.add( cacheRegionDefinition ); } } @SuppressWarnings("unchecked") private T loadSettingInstance(String settingName, Object settingValue, Class clazz) { - T instance = null; - Class instanceClass = null; - + final Class instanceClass; if ( clazz.isAssignableFrom( settingValue.getClass() ) ) { - instance = (T) settingValue; + return (T) settingValue; } else if ( settingValue instanceof Class ) { instanceClass = (Class) settingValue; } - else if ( settingValue instanceof String ) { - String settingStringValue = (String) settingValue; + else if ( settingValue instanceof String className ) { if ( standardServiceRegistry != null ) { - instanceClass = standardServiceRegistry.requireService( ClassLoaderService.class ) - .classForName( settingStringValue ); + instanceClass = + standardServiceRegistry.requireService( ClassLoaderService.class ) + .classForName( className ); } else { try { - instanceClass = (Class) Class.forName( settingStringValue ); + instanceClass = (Class) Class.forName( className ); } catch (ClassNotFoundException e) { - throw new IllegalArgumentException( "Can't load class: " + settingStringValue, e ); + throw new IllegalArgumentException( "Can't load class: " + className, e ); } } } else { - throw new IllegalArgumentException( - "The provided " + settingName + " setting value [" + settingValue + "] is not supported" - ); + throw new IllegalArgumentException( "The provided " + settingName + + " setting value [" + settingValue + "] is not supported" ); } if ( instanceClass != null ) { try { - instance = instanceClass.newInstance(); + return instanceClass.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException( @@ -1687,8 +1620,9 @@ public class EntityManagerFactoryBuilderImpl implements EntityManagerFactoryBuil ); } } - - return instance; + else { + return null; + } } /** diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java b/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java index 405701ea65..7fc7837464 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/boot/spi/PersistenceXmlParser.java @@ -30,7 +30,8 @@ import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl; import org.hibernate.boot.registry.classloading.internal.TcclLookupPrecedence; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.cfg.AvailableSettings; -import org.hibernate.internal.EntityManagerMessageLogger; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.jpa.boot.internal.ParsedPersistenceXmlDescriptor; @@ -39,8 +40,6 @@ import org.hibernate.jpa.internal.util.ConfigurationHelper; import jakarta.persistence.PersistenceException; import jakarta.persistence.spi.PersistenceUnitTransactionType; -import static org.hibernate.internal.HEMLogging.messageLogger; - /** * Used by Hibernate to parse {@code persistence.xml} files in SE environments. * @@ -48,7 +47,7 @@ import static org.hibernate.internal.HEMLogging.messageLogger; */ public final class PersistenceXmlParser { - private static final EntityManagerMessageLogger LOG = messageLogger( PersistenceXmlParser.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( PersistenceXmlParser.class ); /** * @return A {@link PersistenceXmlParser} using no settings at all. @@ -160,10 +159,10 @@ public final class PersistenceXmlParser { } @SuppressWarnings("removal") - protected void parsePersistenceXml(Map persistenceUnits, + private void parsePersistenceXml(Map persistenceUnits, URL xmlUrl, PersistenceUnitTransactionType defaultTransactionType) { - if ( LOG.isTraceEnabled() ) { - LOG.tracef( "Attempting to parse persistence.xml file : %s", xmlUrl.toExternalForm() ); + if ( log.isTraceEnabled() ) { + log.tracef( "Attempting to parse persistence.xml file : %s", xmlUrl.toExternalForm() ); } final URL persistenceUnitRootUrl = ArchiveHelper.getJarURLFromURLEntry( xmlUrl, "/META-INF/persistence.xml" ); @@ -175,12 +174,12 @@ public final class PersistenceXmlParser { final JaxbPersistenceImpl.JaxbPersistenceUnitImpl jaxbPersistenceUnit = jaxbPersistenceUnits.get( i ); if ( persistenceUnits.containsKey( jaxbPersistenceUnit.getName() ) ) { - LOG.duplicatedPersistenceUnitName( jaxbPersistenceUnit.getName() ); + log.duplicatedPersistenceUnitName( jaxbPersistenceUnit.getName() ); continue; } - final ParsedPersistenceXmlDescriptor persistenceUnitDescriptor = new ParsedPersistenceXmlDescriptor( - persistenceUnitRootUrl ); + final ParsedPersistenceXmlDescriptor persistenceUnitDescriptor = + new ParsedPersistenceXmlDescriptor( persistenceUnitRootUrl ); bindPersistenceUnit( jaxbPersistenceUnit, persistenceUnitDescriptor ); // per JPA spec, any settings passed in to PersistenceProvider bootstrap methods should override @@ -196,7 +195,7 @@ public final class PersistenceXmlParser { ParsedPersistenceXmlDescriptor persistenceUnitDescriptor) { final String name = jaxbPersistenceUnit.getName(); if ( StringHelper.isNotEmpty( name ) ) { - LOG.tracef( "Persistence unit name from persistence.xml : %s", name ); + log.tracef( "Persistence unit name from persistence.xml : %s", name ); persistenceUnitDescriptor.setName( name ); } diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/internal/util/LogHelper.java b/hibernate-core/src/main/java/org/hibernate/jpa/internal/util/LogHelper.java index beef18f56c..318b7d8e0c 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/internal/util/LogHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/internal/util/LogHelper.java @@ -12,8 +12,8 @@ import java.util.Enumeration; import java.util.List; import java.util.Properties; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor; -import org.hibernate.internal.EntityManagerMessageLogger; import org.jboss.logging.Logger; @@ -22,7 +22,7 @@ import org.jboss.logging.Logger; * @author Steve Ebersole */ public final class LogHelper { - private static final EntityManagerMessageLogger log = Logger.getMessageLogger( MethodHandles.lookup(), EntityManagerMessageLogger.class, LogHelper.class.getName() ); + private static final CoreMessageLogger log = Logger.getMessageLogger( MethodHandles.lookup(), CoreMessageLogger.class, LogHelper.class.getName() ); private LogHelper() { } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 890384a453..f8f22a78cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -16,8 +16,8 @@ import org.hibernate.AssertionFailure; import org.hibernate.PropertyNotFoundException; import org.hibernate.boot.model.convert.spi.ConverterDescriptor; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.internal.HEMLogging; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.AggregateColumn; import org.hibernate.mapping.Any; import org.hibernate.mapping.Collection; @@ -86,7 +86,7 @@ import jakarta.persistence.metamodel.Type; * @author Emmanuel Bernard */ public class AttributeFactory { - private static final EntityManagerMessageLogger LOG = HEMLogging.messageLogger( AttributeFactory.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( AttributeFactory.class ); private final MetadataContext context; @@ -114,10 +114,10 @@ public class AttributeFactory { MetadataContext metadataContext) { if ( property.isSynthetic() ) { // hide synthetic/virtual properties (fabricated by Hibernate) from the JPA metamodel. - LOG.tracef( "Skipping synthetic property %s(%s)", ownerType.getTypeName(), property.getName() ); + log.tracef( "Skipping synthetic property %s(%s)", ownerType.getTypeName(), property.getName() ); return null; } - LOG.tracef( "Building attribute [%s.%s]", ownerType.getTypeName(), property.getName() ); + log.tracef( "Building attribute [%s.%s]", ownerType.getTypeName(), property.getName() ); final AttributeContext attributeContext = wrap( ownerType, property ); final AttributeMetadata attributeMetadata = determineAttributeMetadata( attributeContext, @@ -180,7 +180,7 @@ public class AttributeFactory { public SingularPersistentAttribute buildIdAttribute( IdentifiableDomainType ownerType, Property property) { - LOG.tracef( "Building identifier attribute [%s.%s]", ownerType.getTypeName(), property.getName() ); + log.tracef( "Building identifier attribute [%s.%s]", ownerType.getTypeName(), property.getName() ); final AttributeMetadata attributeMetadata = determineAttributeMetadata( wrap( ownerType, property ), identifierMemberResolver ); @@ -211,7 +211,7 @@ public class AttributeFactory { public SingularAttributeImpl buildVersionAttribute( IdentifiableDomainType ownerType, Property property) { - LOG.tracef( "Building version attribute [%s.%s]", ownerType.getTypeName(), property.getName() ); + log.tracef( "Building version attribute [%s.%s]", ownerType.getTypeName(), property.getName() ); final AttributeMetadata attributeMetadata = determineAttributeMetadata( wrap( ownerType, property ), versionMemberResolver ); @@ -455,14 +455,14 @@ public class AttributeFactory { final Property propertyMapping = attributeContext.getPropertyMapping(); final String propertyName = propertyMapping.getName(); - LOG.tracef( "Starting attribute metadata determination [%s]", propertyName ); + log.tracef( "Starting attribute metadata determination [%s]", propertyName ); final Member member = memberResolver.resolveMember( attributeContext, context ); - LOG.tracef( " Determined member [%s]", member ); + log.tracef( " Determined member [%s]", member ); final Value value = propertyMapping.getValue(); final org.hibernate.type.Type type = value.getType(); - LOG.tracef( " Determined type [name=%s, class=%s]", type.getName(), type.getClass().getName() ); + log.tracef( " Determined type [name=%s, class=%s]", type.getName(), type.getClass().getName() ); if ( type instanceof AnyType ) { return new SingularAttributeMetadataImpl<>( diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 864af9d455..0634947f3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -22,8 +22,8 @@ import org.hibernate.MappingException; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.spi.MetadataImplementor; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.internal.HEMLogging; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.Component; @@ -75,7 +75,7 @@ import jakarta.persistence.metamodel.Type; */ @Internal public class MetadataContext { - private static final EntityManagerMessageLogger LOG = HEMLogging.messageLogger( MetadataContext.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( MetadataContext.class ); private final JpaMetamodelImplementor jpaMetamodel; private final RuntimeModelCreationContext runtimeModelCreationContext; @@ -288,8 +288,8 @@ public class MetadataContext { @SuppressWarnings("unchecked") public void wrapUp() { - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Wrapping up metadata context..." ); + if ( log.isTraceEnabled() ) { + log.trace( "Wrapping up metadata context..." ); } final boolean staticMetamodelScanEnabled = @@ -300,8 +300,8 @@ public class MetadataContext { for ( Object mapping : orderedMappings ) { if ( PersistentClass.class.isAssignableFrom( mapping.getClass() ) ) { final PersistentClass safeMapping = (PersistentClass) mapping; - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Starting entity [" + safeMapping.getEntityName() + ']' ); + if ( log.isTraceEnabled() ) { + log.trace( "Starting entity [" + safeMapping.getEntityName() + ']' ); } try { final EntityDomainType jpaMapping = (EntityDomainType) @@ -343,15 +343,15 @@ public class MetadataContext { } } finally { - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Completed entity [" + safeMapping.getEntityName() + ']' ); + if ( log.isTraceEnabled() ) { + log.trace( "Completed entity [" + safeMapping.getEntityName() + ']' ); } } } else if ( MappedSuperclass.class.isAssignableFrom( mapping.getClass() ) ) { final MappedSuperclass safeMapping = (MappedSuperclass) mapping; - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']' ); + if ( log.isTraceEnabled() ) { + log.trace( "Starting mapped superclass [" + safeMapping.getMappedClass().getName() + ']' ); } try { final MappedSuperclassDomainType jpaType = (MappedSuperclassDomainType) @@ -387,8 +387,8 @@ public class MetadataContext { } } finally { - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']' ); + if ( log.isTraceEnabled() ) { + log.trace( "Completed mapped superclass [" + safeMapping.getMappedClass().getName() + ']' ); } } } @@ -646,8 +646,8 @@ public class MetadataContext { private Set> buildIdClassAttributes( IdentifiableDomainType ownerType, List properties) { - if ( LOG.isTraceEnabled() ) { - LOG.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + ']' ); + if ( log.isTraceEnabled() ) { + log.trace( "Building old-school composite identifier [" + ownerType.getJavaType().getName() + ']' ); } Set> attributes = new HashSet<>(); for ( Property property : properties ) { @@ -732,14 +732,14 @@ public class MetadataContext { injectField( metamodelClass, name, attribute, allowNonDeclaredFieldReference ); } catch (NoSuchFieldException e) { - LOG.unableToLocateStaticMetamodelField( metamodelClass.getName(), name ); + log.unableToLocateStaticMetamodelField( metamodelClass.getName(), name ); // throw new AssertionFailure( // "Unable to locate static metamodel field : " + metamodelClass.getName() + '#' + name // ); } } - private static void injectField( + private static void injectField( Class metamodelClass, String name, Object model, boolean allowNonDeclaredFieldReference) throws NoSuchFieldException { @@ -770,7 +770,7 @@ public class MetadataContext { // + "; expected type : " + attribute.getClass().getName() // + "; encountered type : " + field.getType().getName() // ); - LOG.illegalArgumentOnStaticMetamodelFieldInjection( + log.illegalArgumentOnStaticMetamodelFieldInjection( metamodelClass.getName(), name, model.getClass().getName(), diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java index 6961b85a55..c41fca0c00 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java @@ -33,8 +33,8 @@ import org.hibernate.graph.spi.AttributeNodeImplementor; import org.hibernate.graph.spi.GraphImplementor; import org.hibernate.graph.spi.RootGraphImplementor; import org.hibernate.graph.spi.SubGraphImplementor; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.internal.HEMLogging; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.jpa.spi.JpaCompliance; import org.hibernate.mapping.MappedSuperclass; @@ -43,7 +43,6 @@ import org.hibernate.metamodel.MappingMetamodel; import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting; import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting; import org.hibernate.metamodel.internal.MetadataContext; -import org.hibernate.metamodel.mapping.EntityMappingType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.IdentifiableDomainType; @@ -76,7 +75,7 @@ import jakarta.persistence.metamodel.Type; * @author Steve Ebersole */ public class JpaMetamodelImpl implements JpaMetamodelImplementor, Serializable { - private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( JpaMetamodel.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( JpaMetamodel.class ); private static class ImportInfo { final String importedName; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java index 7ab8499658..5ecd47d1c7 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/MappingMetamodelImpl.java @@ -32,8 +32,8 @@ import org.hibernate.cache.spi.access.EntityDataAccess; import org.hibernate.cache.spi.access.NaturalIdDataAccess; import org.hibernate.graph.RootGraph; import org.hibernate.graph.spi.RootGraphImplementor; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.internal.HEMLogging; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.QueryParameterBindingTypeResolverImpl; import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.jpa.spi.JpaCompliance; @@ -99,7 +99,7 @@ import static org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetti public class MappingMetamodelImpl extends QueryParameterBindingTypeResolverImpl implements MappingMetamodelImplementor, MetamodelImplementor, Serializable { // todo : Integrate EntityManagerLogger into CoreMessageLogger - private static final EntityManagerMessageLogger log = HEMLogging.messageLogger( MappingMetamodelImpl.class ); + private static final CoreMessageLogger log = CoreLogging.messageLogger( MappingMetamodelImpl.class ); //NOTE: we suppress deprecation warnings because at the moment we //implement a deprecated API so have to override deprecated things diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java index 7011442a30..9076e11be5 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/AbstractQuery.java @@ -32,8 +32,8 @@ import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.graph.GraphSemantic; -import org.hibernate.internal.EntityManagerMessageLogger; -import org.hibernate.internal.HEMLogging; +import org.hibernate.internal.CoreLogging; +import org.hibernate.internal.CoreMessageLogger; import org.hibernate.jpa.AvailableHints; import org.hibernate.jpa.internal.util.FlushModeTypeHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; @@ -75,7 +75,7 @@ import static org.hibernate.jpa.SpecHints.HINT_SPEC_QUERY_TIMEOUT; public abstract class AbstractQuery extends AbstractSelectionQuery implements QueryImplementor { - protected static final EntityManagerMessageLogger log = HEMLogging.messageLogger( AbstractQuery.class ); + protected static final CoreMessageLogger log = CoreLogging.messageLogger( AbstractQuery.class ); public AbstractQuery(SharedSessionContractImplementor session) { super( session ); diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/AbstractJtaBatchTest.java b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/AbstractJtaBatchTest.java index 79a6e2de87..457f641177 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/AbstractJtaBatchTest.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/jpa/transaction/batch/AbstractJtaBatchTest.java @@ -8,7 +8,7 @@ package org.hibernate.orm.test.jpa.transaction.batch; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.Parameter; -import org.hibernate.internal.HEMLogging; +import org.hibernate.internal.CoreLogging; import org.hibernate.jpa.boot.spi.ProviderChecker; import org.hibernate.testing.jta.JtaAwareConnectionProviderImpl; @@ -34,7 +34,7 @@ public abstract class AbstractJtaBatchTest extends AbstractBatchingTest { @RegisterExtension public LoggerInspectionExtension logger = LoggerInspectionExtension.builder() - .setLogger( HEMLogging.messageLogger( ProviderChecker.class.getName() ) ) + .setLogger( CoreLogging.messageLogger( ProviderChecker.class.getName() ) ) .build(); @BeforeEach