Skip to content

Commit b52e18f

Browse files
committed
typesafe logging in AbstractEntityPersister
1 parent d7dc334 commit b52e18f

File tree

2 files changed

+54
-20
lines changed

2 files changed

+54
-20
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,4 +540,46 @@ void unableToLocateStaticMetamodelField(
540540
@LogMessage(level = WARN)
541541
@Message( id = 6064, value = "Unable to close temp session" )
542542
void unableToCLoseTempSession();
543+
544+
// AbstractEntityPersister
545+
546+
@LogMessage(level = TRACE)
547+
@Message( id = 6565, value = "Initializing lazy properties from datastore (triggered for '%s')" )
548+
void initializingLazyPropertiesFromDatastore(String fieldName);
549+
550+
@LogMessage(level = TRACE)
551+
@Message( id = 6566, value = "Initializing lazy properties from second-level cache" )
552+
void initializingLazyPropertiesFromSecondLevelCache();
553+
554+
@LogMessage(level = TRACE)
555+
@Message( id = 6567, value = "Done initializing lazy properties" )
556+
void doneInitializingLazyProperties();
557+
558+
@LogMessage(level = TRACE)
559+
@Message( id = 6568, value = "Resolving unique key [%s] to identifier for entity [%s]" )
560+
void resolvingUniqueKeyToIdentifier(Object key, String entityName);
561+
562+
@LogMessage(level = TRACE)
563+
@Message( id = 6569, value = "Reading entity version: %s" )
564+
void readingEntityVersion(String info);
565+
566+
@LogMessage(level = TRACE)
567+
@Message( id = 6570, value = "Fetching entity: %s" )
568+
void fetchingEntity(String info);
569+
570+
@LogMessage(level = TRACE)
571+
@Message( id = 6571, value = "%s is dirty" )
572+
void propertyIsDirty(String qualifiedProperty);
573+
574+
@LogMessage(level = TRACE)
575+
@Message( id = 6572, value = "Forcing version increment [%s]" )
576+
void forcingVersionIncrement(String info);
577+
578+
@LogMessage(level = TRACE)
579+
@Message( id = 6573, value = "Getting current natural-id snapshot state for `%s#%s" )
580+
void gettingCurrentNaturalIdSnapshot(String entityName, Object id);
581+
582+
@LogMessage(level = TRACE)
583+
@Message( id = 6574, value = "Initializing lazy properties of: %s, field access: %s" )
584+
void initializingLazyPropertiesOf(String info, String fieldName);
543585
}

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,6 @@
201201
import org.hibernate.sql.ast.tree.select.SelectStatement;
202202
import org.hibernate.sql.exec.spi.JdbcOperation;
203203
import org.hibernate.sql.exec.spi.JdbcParametersList;
204-
import org.hibernate.sql.model.ast.ColumnValueBinding;
205-
import org.hibernate.sql.model.ast.MutatingTableReference;
206204
import org.hibernate.sql.model.ast.builder.MutationGroupBuilder;
207205
import org.hibernate.sql.model.ast.builder.TableInsertBuilder;
208206
import org.hibernate.sql.results.graph.DomainResult;
@@ -1457,8 +1455,7 @@ private Object initializedLazyField(
14571455
}
14581456

14591457
if ( CORE_LOGGER.isTraceEnabled() ) {
1460-
CORE_LOGGER.tracev(
1461-
"Initializing lazy properties of: {0}, field access: {1}",
1458+
CORE_LOGGER.initializingLazyPropertiesOf(
14621459
infoString( this, id, getFactory() ),
14631460
fieldName
14641461
);
@@ -1601,7 +1598,7 @@ private Object initLazyProperties(
16011598
SharedSessionContractImplementor session) {
16021599

16031600
assert hasLazyProperties();
1604-
CORE_LOGGER.tracef( "Initializing lazy properties from datastore (triggered for '%s')", fieldName );
1601+
CORE_LOGGER.initializingLazyPropertiesFromDatastore( fieldName );
16051602

16061603
final var interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
16071604
assert interceptor != null : "Expecting bytecode interceptor to be non-null";
@@ -1639,7 +1636,7 @@ private Object initLazyProperties(
16391636
}
16401637
}
16411638
}
1642-
CORE_LOGGER.trace( "Done initializing lazy properties" );
1639+
CORE_LOGGER.doneInitializingLazyProperties();
16431640
return finalResult;
16441641
}
16451642
catch (JDBCException ex) {
@@ -1700,7 +1697,7 @@ protected Object initializeLazyPropertiesFromCache(
17001697
final SharedSessionContractImplementor session,
17011698
final EntityEntry entry,
17021699
final CacheEntry cacheEntry) {
1703-
CORE_LOGGER.trace( "Initializing lazy properties from second-level cache" );
1700+
CORE_LOGGER.initializingLazyPropertiesFromSecondLevelCache();
17041701
Object result = null;
17051702
final var disassembledValues = cacheEntry.getDisassembledState();
17061703
for ( int j = 0; j < lazyPropertyNames.length; j++ ) {
@@ -1718,7 +1715,7 @@ protected Object initializeLazyPropertiesFromCache(
17181715
}
17191716
}
17201717
}
1721-
CORE_LOGGER.trace( "Done initializing lazy properties" );
1718+
CORE_LOGGER.doneInitializingLazyProperties();
17221719
return result;
17231720
}
17241721

@@ -2034,8 +2031,7 @@ public Object[] getDatabaseSnapshot(Object id, SharedSessionContractImplementor
20342031
@Override
20352032
public Object getIdByUniqueKey(Object key, String uniquePropertyName, SharedSessionContractImplementor session) {
20362033
if ( CORE_LOGGER.isTraceEnabled() ) {
2037-
CORE_LOGGER.tracef( "resolving unique key [%s] to identifier for entity [%s]",
2038-
key, getEntityName() );
2034+
CORE_LOGGER.resolvingUniqueKeyToIdentifier( key, getEntityName() );
20392035
}
20402036

20412037
return getUniqueKeyLoader( uniquePropertyName, session ).resolveId( key, session );
@@ -2094,8 +2090,8 @@ private Object calculateNextVersion(Object id, Object currentVersion, SharedSess
20942090
.generate( session, null, currentVersion, FORCE_INCREMENT );
20952091
if ( CORE_LOGGER.isTraceEnabled() ) {
20962092
final var versionType = getVersionType();
2097-
CORE_LOGGER.trace(
2098-
"Forcing version increment [" + infoString( this, id, factory ) + "; "
2093+
CORE_LOGGER.forcingVersionIncrement(
2094+
"[" + infoString( this, id, factory ) + "; "
20992095
+ versionType.toLoggableString( currentVersion, factory ) + " -> "
21002096
+ versionType.toLoggableString( nextVersion, factory ) + "]"
21012097
);
@@ -2137,7 +2133,7 @@ else if ( isVersionGeneratedOnExecution() ) {
21372133
public Object getCurrentVersion(Object id, SharedSessionContractImplementor session) throws HibernateException {
21382134

21392135
if ( CORE_LOGGER.isTraceEnabled() ) {
2140-
CORE_LOGGER.tracev( "Getting version: {0}", infoString( this, id, getFactory() ) );
2136+
CORE_LOGGER.readingEntityVersion( infoString( this, id, getFactory() ) );
21412137
}
21422138
final String versionSelectString = getVersionSelectString();
21432139
try {
@@ -3513,7 +3509,7 @@ public Object load(Object id, Object optionalObject, LockOptions lockOptions, Sh
35133509
private Object doLoad(Object id, Object optionalObject, LockOptions lockOptions, Boolean readOnly, SharedSessionContractImplementor session)
35143510
throws HibernateException {
35153511
if ( CORE_LOGGER.isTraceEnabled() ) {
3516-
CORE_LOGGER.tracev( "Fetching entity: {0}", infoString( this, id, getFactory() ) );
3512+
CORE_LOGGER.fetchingEntity( infoString( this, id, getFactory() ) );
35173513
}
35183514

35193515
final SingleIdEntityLoader<?> loader = determineLoaderToUse( session, lockOptions );
@@ -3731,7 +3727,7 @@ private void logDirtyProperties(int[] props) {
37313727
if ( CORE_LOGGER.isTraceEnabled() ) {
37323728
for ( int prop : props ) {
37333729
final String propertyName = getAttributeMapping( prop ).getAttributeName();
3734-
CORE_LOGGER.trace( qualify( getEntityName(), propertyName ) + " is dirty" );
3730+
CORE_LOGGER.propertyIsDirty( qualify( getEntityName(), propertyName ) );
37353731
}
37363732
}
37373733
}
@@ -4431,11 +4427,7 @@ protected void verifyHasNaturalId() {
44314427
public Object getNaturalIdentifierSnapshot(Object id, SharedSessionContractImplementor session) {
44324428
verifyHasNaturalId();
44334429
if ( CORE_LOGGER.isTraceEnabled() ) {
4434-
CORE_LOGGER.tracef(
4435-
"Getting current natural-id snapshot state for `%s#%s",
4436-
getEntityName(),
4437-
id
4438-
);
4430+
CORE_LOGGER.gettingCurrentNaturalIdSnapshot( getEntityName(), id );
44394431
}
44404432
return getNaturalIdLoader().resolveIdToNaturalId( id, session );
44414433
}

0 commit comments

Comments
 (0)