Skip to content

Commit b1f63ee

Browse files
committed
introduce JpaLogger
1 parent 9099bef commit b1f63ee

File tree

10 files changed

+350
-206
lines changed

10 files changed

+350
-206
lines changed

hibernate-core/src/main/java/org/hibernate/internal/CoreMessageLogger.java

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
*/
3636
@SubSystemLogging(
3737
name = SessionLogging.NAME,
38-
description = "Miscellaneous Logging related to Hibernate ORM Core"
38+
description = "Miscellaneous logging related to Hibernate ORM Core"
3939
)
4040
@MessageLogger(projectCode = "HHH")
41-
@ValidIdRange(min=2,max = 10000)
41+
@ValidIdRange(min=2,max = 8000)
4242
@Internal
4343
public interface CoreMessageLogger extends BasicLogger {
4444

@@ -59,10 +59,6 @@ public interface CoreMessageLogger extends BasicLogger {
5959
@Message(value = "Ignoring bag join fetch [%s] due to prior collection join fetch", id = 51)
6060
void containsJoinFetchedCollection(String role);
6161

62-
@LogMessage(level = WARN)
63-
@Message(value = "Defining %s=true ignored in HEM", id = 59)
64-
void definingFlushBeforeCompletionIgnoredInHem(String flushBeforeCompletion);
65-
6662
@LogMessage(level = WARN)
6763
@Message(value = "Entity [%s] is abstract-class/interface explicitly mapped as non-abstract; be sure to supply entity-names",
6864
id = 84)
@@ -117,14 +113,6 @@ void missingArguments(
117113
id = 182)
118114
void noDefaultConstructor(String name);
119115

120-
@LogMessage(level = WARN)
121-
@Message(value = "Overriding %s is dangerous, this might break the EJB3 specification implementation", id = 193)
122-
void overridingTransactionStrategyDangerous(String transactionStrategy);
123-
124-
@LogMessage(level = INFO)
125-
@Message(value = "Processing PersistenceUnitInfo [name: %s]", id = 204)
126-
void processingPersistenceUnitInfoName(String persistenceUnitName);
127-
128116
@LogMessage(level = INFO)
129117
@Message(value = "Loaded properties from resource hibernate.properties: %s", id = 205)
130118
void propertiesLoaded(Properties maskOut);
@@ -220,10 +208,6 @@ void missingArguments(
220208
@Message(value = "Error creating schema ", id = 306)
221209
void unableToCreateSchema(@Cause Exception e);
222210

223-
@LogMessage(level = INFO)
224-
@Message(value = "Could not find any META-INF/persistence.xml file in the classpath", id = 318)
225-
void unableToFindPersistenceXmlInClasspath();
226-
227211
@LogMessage(level = ERROR)
228212
@Message(value = "Problem loading properties from hibernate.properties", id = 329)
229213
void unableToLoadProperties();
@@ -369,24 +353,13 @@ void missingArguments(
369353
id = 513)
370354
void unableToGenerateReflectionOptimizer(String className, String cause);
371355

372-
@LogMessage(level = WARN)
373-
@Message(value = "Failed to discover types for enhancement from class: %s",
374-
id = 516)
375-
void enhancementDiscoveryFailed(String className, @Cause Throwable cause);
376356
@LogMessage(level = DEBUG)
377357
@Message(
378358
id = 517,
379359
value = "Encountered a MappedSuperclass [%s] not used in any entity hierarchy"
380360
)
381361
void unusedMappedSuperclass(String name);
382362

383-
@LogMessage(level = WARN)
384-
@Message(
385-
id = 518,
386-
value = "Encountered multiple persistence-unit stanzas defining same name [%s]; persistence-unit names must be unique"
387-
)
388-
void duplicatedPersistenceUnitName(String name);
389-
390363
@LogMessage(level = WARN)
391364
@Message(
392365
id = 519,

hibernate-core/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
*/
55
package org.hibernate.jpa;
66

7-
import java.net.URL;
87
import java.util.Collection;
9-
import java.util.Collections;
108
import java.util.List;
119
import java.util.Map;
1210
import jakarta.persistence.EntityManagerFactory;
@@ -23,10 +21,13 @@
2321
import org.hibernate.jpa.boot.spi.Bootstrap;
2422
import org.hibernate.jpa.boot.spi.EntityManagerFactoryBuilder;
2523
import org.hibernate.jpa.boot.spi.PersistenceUnitDescriptor;
26-
import org.hibernate.jpa.boot.spi.ProviderChecker;
2724
import org.hibernate.jpa.internal.util.PersistenceUtilHelper;
25+
import org.hibernate.jpa.internal.util.PersistenceUtilHelper.MetadataCache;
2826

29-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
27+
import static java.util.Collections.emptyMap;
28+
import static java.util.Collections.unmodifiableMap;
29+
import static org.hibernate.jpa.boot.spi.ProviderChecker.isProvider;
30+
import static org.hibernate.jpa.internal.JpaLogger.JPA_LOGGER;
3031

3132
/**
3233
* The best-ever implementation of a JPA {@link PersistenceProvider}.
@@ -37,7 +38,7 @@
3738
*/
3839
public class HibernatePersistenceProvider implements PersistenceProvider {
3940

40-
private final PersistenceUtilHelper.MetadataCache cache = new PersistenceUtilHelper.MetadataCache();
41+
private final MetadataCache cache = new MetadataCache();
4142

4243
/**
4344
* {@inheritDoc}
@@ -46,13 +47,15 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
4647
*/
4748
@Override
4849
public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) {
49-
CORE_LOGGER.tracef( "Starting createEntityManagerFactory for persistenceUnitName %s", persistenceUnitName );
50-
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties );
50+
JPA_LOGGER.startingCreateEntityManagerFactory( persistenceUnitName );
51+
final var builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, properties );
5152
if ( builder == null ) {
52-
CORE_LOGGER.trace( "Could not obtain matching EntityManagerFactoryBuilder, returning null" );
53+
JPA_LOGGER.couldNotObtainEmfBuilder("null");
5354
return null;
5455
}
55-
return builder.build();
56+
else {
57+
return builder.build();
58+
}
5659
}
5760

5861
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map<?,?> properties) {
@@ -71,22 +74,18 @@ protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(Strin
7174

7275
private EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String persistenceUnitName, Map<?,?> properties,
7376
ClassLoader providedClassLoader, ClassLoaderService providedClassLoaderService) {
74-
CORE_LOGGER.tracef( "Attempting to obtain correct EntityManagerFactoryBuilder for persistenceUnitName : %s", persistenceUnitName );
75-
76-
final Map<?,?> integration = wrap( properties );
77-
final Collection<PersistenceUnitDescriptor> units = locatePersistenceUnits( integration, providedClassLoader, providedClassLoaderService );
78-
79-
CORE_LOGGER.tracef( "Located and parsed %s persistence units; checking each", units.size() );
80-
77+
JPA_LOGGER.attemptingToObtainEmfBuilder( persistenceUnitName );
78+
final var integration = wrap( properties );
79+
final var units = locatePersistenceUnits( integration, providedClassLoader, providedClassLoaderService );
80+
JPA_LOGGER.locatedAndParsedPersistenceUnits( units.size() );
8181
if ( persistenceUnitName == null && units.size() > 1 ) {
82-
// no persistence-unit name to look for was given and we found multiple persistence-units
82+
// no persistence-unit name was specified, and we found multiple persistence-units
8383
throw new PersistenceException( "No name provided and multiple persistence units found" );
8484
}
8585

86-
for ( PersistenceUnitDescriptor persistenceUnit : units ) {
87-
if ( CORE_LOGGER.isTraceEnabled() ) {
88-
CORE_LOGGER.tracef(
89-
"Checking persistence-unit [name=%s, explicit-provider=%s] against incoming persistence unit name [%s]",
86+
for ( var persistenceUnit : units ) {
87+
if ( JPA_LOGGER.isTraceEnabled() ) {
88+
JPA_LOGGER.checkingPersistenceUnitName(
9089
persistenceUnit.getName(),
9190
persistenceUnit.getProviderClassName(),
9291
persistenceUnitName
@@ -95,52 +94,47 @@ private EntityManagerFactoryBuilder getEntityManagerFactoryBuilderOrNull(String
9594

9695
final boolean matches = persistenceUnitName == null || persistenceUnit.getName().equals( persistenceUnitName );
9796
if ( !matches ) {
98-
CORE_LOGGER.tracef( "Excluding from consideration due to name mismatch" );
97+
JPA_LOGGER.excludingDueToNameMismatch();
9998
continue;
10099
}
101100

102101
// See if we (Hibernate) are the persistence provider
103-
if ( ! ProviderChecker.isProvider( persistenceUnit, properties ) ) {
104-
CORE_LOGGER.tracef( "Excluding from consideration due to provider mismatch" );
102+
if ( !isProvider( persistenceUnit, properties ) ) {
103+
JPA_LOGGER.excludingDueToProviderMismatch();
105104
continue;
106105
}
107106

108-
if ( providedClassLoaderService != null ) {
109-
return getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoaderService );
110-
}
111-
else {
112-
return getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoader );
113-
}
107+
return providedClassLoaderService == null
108+
? getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoader )
109+
: getEntityManagerFactoryBuilder( persistenceUnit, integration, providedClassLoaderService );
114110
}
115111

116-
CORE_LOGGER.debug( "Found no matching persistence units" );
112+
JPA_LOGGER.foundNoMatchingPersistenceUnits();
117113
return null;
118114
}
119115

120116
protected static Map<?,?> wrap(Map<?,?> properties) {
121-
return properties == null ? Collections.emptyMap() : Collections.unmodifiableMap( properties );
117+
return properties == null ? emptyMap() : unmodifiableMap( properties );
122118
}
123119

124120
// Check before changing: may be overridden in Quarkus
125121
protected Collection<PersistenceUnitDescriptor> locatePersistenceUnits(Map<?, ?> integration, ClassLoader providedClassLoader,
126122
ClassLoaderService providedClassLoaderService) {
127-
final Collection<PersistenceUnitDescriptor> units;
128123
try {
129124
var parser = PersistenceXmlParser.create( integration, providedClassLoader, providedClassLoaderService );
130-
final List<URL> xmlUrls = parser.getClassLoaderService().locateResources( "META-INF/persistence.xml" );
125+
final var xmlUrls = parser.getClassLoaderService().locateResources( "META-INF/persistence.xml" );
131126
if ( xmlUrls.isEmpty() ) {
132-
CORE_LOGGER.unableToFindPersistenceXmlInClasspath();
133-
units = List.of();
127+
JPA_LOGGER.unableToFindPersistenceXmlInClasspath();
128+
return List.of();
134129
}
135130
else {
136-
units = parser.parse( xmlUrls ).values();
131+
return parser.parse( xmlUrls ).values();
137132
}
138133
}
139134
catch (Exception e) {
140-
CORE_LOGGER.debug( "Unable to locate persistence units", e );
135+
JPA_LOGGER.unableToLocatePersistenceUnits( e );
141136
throw new PersistenceException( "Unable to locate persistence units", e );
142137
}
143-
return units;
144138
}
145139

146140
/**
@@ -150,34 +144,28 @@ protected Collection<PersistenceUnitDescriptor> locatePersistenceUnits(Map<?, ?>
150144
*/
151145
@Override
152146
public EntityManagerFactory createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) {
153-
if ( CORE_LOGGER.isTraceEnabled() ) {
154-
CORE_LOGGER.tracef( "Starting createContainerEntityManagerFactory : %s", info.getPersistenceUnitName() );
155-
}
156-
147+
JPA_LOGGER.startingCreateContainerEntityManagerFactory( info.getPersistenceUnitName() );
157148
return getEntityManagerFactoryBuilder( info, properties ).build();
158149
}
159150

160151
@Override
161152
public void generateSchema(PersistenceUnitInfo info, Map map) {
162-
if ( CORE_LOGGER.isTraceEnabled() ) {
163-
CORE_LOGGER.tracef( "Starting generateSchema : PUI.name=%s", info.getPersistenceUnitName() );
164-
}
165-
166-
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilder( info, map );
167-
builder.generateSchema();
153+
JPA_LOGGER.startingGenerateSchemaForPuiName( info.getPersistenceUnitName() );
154+
getEntityManagerFactoryBuilder( info, map ).generateSchema();
168155
}
169156

170157
@Override
171158
public boolean generateSchema(String persistenceUnitName, Map map) {
172-
CORE_LOGGER.tracef( "Starting generateSchema for persistenceUnitName %s", persistenceUnitName );
173-
174-
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, map );
159+
JPA_LOGGER.startingGenerateSchema( persistenceUnitName );
160+
final var builder = getEntityManagerFactoryBuilderOrNull( persistenceUnitName, map );
175161
if ( builder == null ) {
176-
CORE_LOGGER.trace( "Could not obtain matching EntityManagerFactoryBuilder, returning false" );
162+
JPA_LOGGER.couldNotObtainEmfBuilder("false");
177163
return false;
178164
}
179-
builder.generateSchema();
180-
return true;
165+
else {
166+
builder.generateSchema();
167+
return true;
168+
}
181169
}
182170

183171
protected EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceUnitInfo info, Map<?,?> integration) {
@@ -211,12 +199,15 @@ public LoadState isLoaded(Object object) {
211199

212200
@Override
213201
public EntityManagerFactory createEntityManagerFactory(PersistenceConfiguration configuration) {
214-
final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilder(
202+
return getEntityManagerFactoryBuilder( configuration ).build();
203+
}
204+
205+
private EntityManagerFactoryBuilder getEntityManagerFactoryBuilder(PersistenceConfiguration configuration) {
206+
return getEntityManagerFactoryBuilder(
215207
new PersistenceConfigurationDescriptor( configuration ),
216-
Collections.emptyMap(),
208+
emptyMap(),
217209
HibernatePersistenceProvider.class.getClassLoader()
218210
);
219-
return builder.build();
220211
}
221212

222213
@Override

hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/EntityManagerFactoryBuilderImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
import static org.hibernate.cfg.BytecodeSettings.ENHANCER_ENABLE_DIRTY_TRACKING;
108108
import static org.hibernate.cfg.BytecodeSettings.ENHANCER_ENABLE_LAZY_INITIALIZATION;
109109
import static org.hibernate.cfg.TransactionSettings.FLUSH_BEFORE_COMPLETION;
110-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
110+
import static org.hibernate.jpa.internal.JpaLogger.JPA_LOGGER;
111111
import static org.hibernate.internal.log.DeprecationLogger.DEPRECATION_LOGGER;
112112
import static org.hibernate.internal.util.NullnessHelper.coalesceSuppliedValues;
113113
import static org.hibernate.internal.util.StringHelper.isEmpty;
@@ -264,7 +264,7 @@ private static void ignoreFlushBeforeCompletion(MergedSettings mergedSettings) {
264264
// flush before completion validation
265265
final var config = mergedSettings.getConfigurationValues();
266266
if ( getBoolean( FLUSH_BEFORE_COMPLETION, config, false ) ) {
267-
CORE_LOGGER.definingFlushBeforeCompletionIgnoredInHem( FLUSH_BEFORE_COMPLETION );
267+
JPA_LOGGER.definingFlushBeforeCompletionIgnoredInHem( FLUSH_BEFORE_COMPLETION );
268268
config.put( FLUSH_BEFORE_COMPLETION, String.valueOf(false) );
269269
}
270270
}
@@ -348,7 +348,7 @@ private static void discoverTypesToTransform(
348348
classTransformer.discoverTypes(classLoader, className );
349349
}
350350
catch (EnhancementException ex) {
351-
CORE_LOGGER.enhancementDiscoveryFailed( className, ex );
351+
JPA_LOGGER.enhancementDiscoveryFailed( className, ex );
352352
}
353353
}
354354
}
@@ -800,7 +800,7 @@ private void normalizeTransactionCoordinator(
800800
}
801801

802802
private static boolean handeTransactionCoordinatorStrategy(MergedSettings mergedSettings) {
803-
CORE_LOGGER.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY );
803+
JPA_LOGGER.overridingTransactionStrategyDangerous( TRANSACTION_COORDINATOR_STRATEGY );
804804
// see if we can tell whether it is a JTA coordinator
805805
final Object strategy = mergedSettings.getConfigurationValues().get( TRANSACTION_COORDINATOR_STRATEGY );
806806
return strategy instanceof TransactionCoordinatorBuilder transactionCoordinatorBuilder
@@ -821,7 +821,7 @@ private static PersistenceUnitTransactionType determineTransactionType(
821821
final var txnType = configuredTransactionType( persistenceUnit, integrationSettingsCopy, mergedSettings );
822822
if ( txnType == null ) {
823823
// is it more appropriate to have this be based on bootstrap entry point (EE vs SE)?
824-
CORE_LOGGER.debug( "PersistenceUnitTransactionType not specified - falling back to RESOURCE_LOCAL" );
824+
JPA_LOGGER.fallingBackToResourceLocal();
825825
return PersistenceUnitTransactionType.RESOURCE_LOCAL;
826826
}
827827
else {
@@ -1120,12 +1120,12 @@ private void cleanUpConfigKeys(Map<?, ?> integrationSettingsCopy, MergedSettings
11201120
for ( String key : keys ) {
11211121
final Object removedSetting = integrationSettingsCopy.remove( key );
11221122
if ( removedSetting != null ) {
1123-
CORE_LOGGER.debugf( "Removed integration override setting [%s] due to normalization", key );
1123+
JPA_LOGGER.removedIntegrationOverride( key );
11241124
}
11251125

11261126
final Object removedMergedSetting = mergedSettings.getConfigurationValues().remove( key );
11271127
if ( removedMergedSetting != null ) {
1128-
CORE_LOGGER.debugf( "Removed merged setting [%s] due to normalization", key );
1128+
JPA_LOGGER.removedMergedSetting( key );
11291129
}
11301130
}
11311131
}

hibernate-core/src/main/java/org/hibernate/jpa/boot/internal/PersistenceUnitInfoDescriptor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import org.hibernate.jpa.internal.util.PersistenceUnitTransactionTypeHelper;
2323

24-
import static org.hibernate.internal.CoreMessageLogger.CORE_LOGGER;
24+
import static org.hibernate.jpa.internal.JpaLogger.JPA_LOGGER;
2525

2626
/**
2727
* @author Steve Ebersole
@@ -130,9 +130,8 @@ public void pushClassTransformer(EnhancementContext enhancementContext) {
130130
// During testing, we will return a null temp class loader
131131
// in cases where we don't care about enhancement
132132
if ( persistenceUnitInfo.getNewTempClassLoader() != null ) {
133-
if ( CORE_LOGGER.isTraceEnabled() ) {
134-
CORE_LOGGER.trace( "Pushing class transformers for PU named '" + getName()
135-
+ "' on loading classloader " + enhancementContext.getLoadingClassLoader() );
133+
if ( JPA_LOGGER.isTraceEnabled() ) {
134+
JPA_LOGGER.pushingClassTransformers( getName(), String.valueOf( enhancementContext.getLoadingClassLoader() ) );
136135
}
137136
final EnhancingClassTransformerImpl classTransformer =
138137
new EnhancingClassTransformerImpl( enhancementContext );

0 commit comments

Comments
 (0)