Skip to content

Commit 005e0a6

Browse files
committed
introduce SynchronizationLogging
1 parent 7dda59a commit 005e0a6

File tree

3 files changed

+86
-47
lines changed

3 files changed

+86
-47
lines changed

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.hibernate.HibernateException;
1818
import org.hibernate.Internal;
1919
import org.hibernate.JDBCException;
20-
import org.hibernate.LockMode;
2120
import org.hibernate.cache.CacheException;
2221
import org.hibernate.id.IntegralDataTypeHolder;
2322
import org.hibernate.type.SerializationException;
@@ -29,7 +28,6 @@
2928
import org.jboss.logging.annotations.MessageLogger;
3029
import org.jboss.logging.annotations.ValidIdRange;
3130

32-
import jakarta.transaction.Synchronization;
3331
import org.checkerframework.checker.nullness.qual.Nullable;
3432

3533
import static org.jboss.logging.Logger.Level.DEBUG;
@@ -110,14 +108,6 @@ public interface CoreMessageLogger extends BasicLogger {
110108
@Message(value = "Duplicate generator name %s", id = 69)
111109
void duplicateGeneratorName(String name);
112110

113-
@LogMessage(level = INFO)
114-
@Message(value = "entity listener duplication, first event definition will be used: %s", id = 73)
115-
void duplicateListener(String className);
116-
117-
@LogMessage(level = WARN)
118-
@Message(value = "Found more than one <persistence-unit-metadata>, subsequent ignored", id = 74)
119-
void duplicateMetadata();
120-
121111
@LogMessage(level = WARN)
122112
@Message(value = "Entity [%s] is abstract-class/interface explicitly mapped as non-abstract; be sure to supply entity-names",
123113
id = 84)
@@ -273,14 +263,6 @@ void missingArguments(
273263
@Message(value = "Start time: %s", id = 251)
274264
void startTime(long startTime);
275265

276-
@LogMessage(level = INFO)
277-
@Message(value = "Synchronization [%s] was already registered", id = 259)
278-
void synchronizationAlreadyRegistered(Synchronization synchronization);
279-
280-
@LogMessage(level = ERROR)
281-
@Message(value = "Exception calling user Synchronization [%s]: %s", id = 260)
282-
void synchronizationFailed(Synchronization synchronization, Throwable t);
283-
284266
@LogMessage(level = INFO)
285267
@Message(value = "Table not found: %s", id = 262)
286268
void tableNotFound(String name);
@@ -301,10 +283,6 @@ void missingArguments(
301283
@Message(value = "Error accessing type info result set: %s", id = 273)
302284
void unableToAccessTypeInfoResultSet(String string);
303285

304-
@LogMessage(level = WARN)
305-
@Message(value = "Unable to apply constraints on DDL for %s", id = 274)
306-
void unableToApplyConstraints(String className, @Cause Exception e);
307-
308286
@LogMessage(level = WARN)
309287
@Message(value = "Unable to cleanup temporary id table after use [%s]", id = 283)
310288
void unableToCleanupTemporaryIdTable(Throwable t);
@@ -483,14 +461,6 @@ void cannotResolveNonNullableTransientDependencies(
483461
)
484462
void usingFollowOnLocking();
485463

486-
@LogMessage(level = WARN)
487-
@Message(
488-
value = "Alias-specific lock modes requested, which is not currently supported with follow-on locking; " +
489-
"all acquired locks will be [%s]",
490-
id = 445
491-
)
492-
void aliasSpecificLockingWithFollowOnLocking(LockMode lockMode);
493-
494464
@LogMessage(level = WARN)
495465
@Message(
496466
value = "Explicit use of UPGRADE_SKIPLOCKED in lock() calls is not recommended; use normal UPGRADE locking instead",
@@ -670,14 +640,6 @@ void unableToLocateStaticMetamodelField(
670640
)
671641
void invalidJSONColumnType(String actual, String expected);
672642

673-
@LogMessage(level = TRACE)
674-
@Message(value = "Closing logical connection", id = 456)
675-
void closingLogicalConnection();
676-
677-
@LogMessage(level = TRACE)
678-
@Message(value = "Logical connection closed", id = 457)
679-
void logicalConnectionClosed();
680-
681643
@LogMessage(level = TRACE)
682644
@Message(value = "Initializing service: %s", id = 500)
683645
void initializingService(String serviceRole);
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.resource.transaction.internal;
6+
7+
import jakarta.transaction.Synchronization;
8+
import org.hibernate.Internal;
9+
import org.hibernate.internal.log.SubSystemLogging;
10+
11+
import org.jboss.logging.BasicLogger;
12+
import org.jboss.logging.Logger;
13+
import org.jboss.logging.annotations.Cause;
14+
import org.jboss.logging.annotations.LogMessage;
15+
import org.jboss.logging.annotations.Message;
16+
import org.jboss.logging.annotations.MessageLogger;
17+
import org.jboss.logging.annotations.ValidIdRange;
18+
19+
import java.lang.invoke.MethodHandles;
20+
21+
import static org.jboss.logging.Logger.Level.ERROR;
22+
import static org.jboss.logging.Logger.Level.INFO;
23+
import static org.jboss.logging.Logger.Level.TRACE;
24+
25+
/**
26+
* Logging interface for local Synchronization registry operations.
27+
*/
28+
@MessageLogger(projectCode = "HHH")
29+
@ValidIdRange(min = 90008001, max = 90009000)
30+
@SubSystemLogging(
31+
name = SynchronizationLogging.LOGGER_NAME,
32+
description = "Logging related to local Synchronization registry management"
33+
)
34+
@Internal
35+
public interface SynchronizationLogging extends BasicLogger {
36+
String LOGGER_NAME = SubSystemLogging.BASE + ".synchronization";
37+
38+
SynchronizationLogging SYNCHRONIZATION_LOGGER = Logger.getMessageLogger(
39+
MethodHandles.lookup(), SynchronizationLogging.class, LOGGER_NAME
40+
);
41+
42+
int NAMESPACE = 90008000;
43+
44+
@LogMessage(level = TRACE)
45+
@Message(
46+
value = "Notifying Synchronizations (before completion)",
47+
id = NAMESPACE + 1
48+
)
49+
void notifyingSynchronizationsBefore();
50+
51+
@LogMessage(level = TRACE)
52+
@Message(
53+
value = "Notifying Synchronizations (after completion with status %s)",
54+
id = NAMESPACE + 2
55+
)
56+
void notifyingSynchronizationsAfter(int status);
57+
58+
@LogMessage(level = TRACE)
59+
@Message(
60+
value = "Clearing local Synchronizations",
61+
id = NAMESPACE + 3
62+
)
63+
void clearingSynchronizations();
64+
65+
@LogMessage(level = INFO)
66+
@Message(
67+
value = "Synchronization [%s] was already registered",
68+
id = NAMESPACE + 4
69+
)
70+
void synchronizationAlreadyRegistered(Synchronization synchronization);
71+
72+
@LogMessage(level = ERROR)
73+
@Message(
74+
value = "Exception calling user Synchronization [%s]",
75+
id = NAMESPACE + 5
76+
)
77+
void synchronizationFailed(Synchronization synchronization, @Cause Throwable t);
78+
}

hibernate-core/src/main/java/org/hibernate/resource/transaction/internal/SynchronizationRegistryStandardImpl.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,18 @@
77
import java.util.LinkedHashSet;
88
import jakarta.transaction.Synchronization;
99

10-
import org.hibernate.internal.CoreLogging;
11-
import org.hibernate.internal.CoreMessageLogger;
1210
import org.hibernate.resource.transaction.LocalSynchronizationException;
1311
import org.hibernate.resource.transaction.NullSynchronizationException;
1412
import org.hibernate.resource.transaction.spi.SynchronizationRegistryImplementor;
1513

14+
import static org.hibernate.resource.transaction.internal.SynchronizationLogging.SYNCHRONIZATION_LOGGER;
15+
1616
/**
1717
* The standard implementation of the {@link org.hibernate.resource.transaction.spi.SynchronizationRegistry} contract.
1818
*
1919
* @author Steve Ebersole
2020
*/
2121
public class SynchronizationRegistryStandardImpl implements SynchronizationRegistryImplementor {
22-
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SynchronizationRegistryStandardImpl.class );
2322

2423
private LinkedHashSet<Synchronization> synchronizations;
2524

@@ -44,20 +43,20 @@ public void registerSynchronization(Synchronization synchronization) {
4443

4544
final boolean added = synchronizations.add( synchronization );
4645
if ( !added ) {
47-
LOG.synchronizationAlreadyRegistered( synchronization );
46+
SYNCHRONIZATION_LOGGER.synchronizationAlreadyRegistered( synchronization );
4847
}
4948
}
5049

5150
@Override
5251
public void notifySynchronizationsBeforeTransactionCompletion() {
53-
LOG.trace( "Notifying Synchronizations (before completion)" );
52+
SYNCHRONIZATION_LOGGER.notifyingSynchronizationsBefore();
5453
if ( synchronizations != null ) {
5554
for ( var synchronization : synchronizations ) {
5655
try {
5756
synchronization.beforeCompletion();
5857
}
5958
catch (Throwable t) {
60-
LOG.synchronizationFailed( synchronization, t );
59+
SYNCHRONIZATION_LOGGER.synchronizationFailed( synchronization, t );
6160
throw new LocalSynchronizationException(
6261
"Exception calling user Synchronization (beforeCompletion): " + synchronization.getClass().getName(),
6362
t
@@ -69,15 +68,15 @@ public void notifySynchronizationsBeforeTransactionCompletion() {
6968

7069
@Override
7170
public void notifySynchronizationsAfterTransactionCompletion(int status) {
72-
LOG.tracef( "Notifying Synchronizations (after completion with status %s)", status );
71+
SYNCHRONIZATION_LOGGER.notifyingSynchronizationsAfter( status );
7372
if ( synchronizations != null ) {
7473
try {
7574
for ( var synchronization : synchronizations ) {
7675
try {
7776
synchronization.afterCompletion( status );
7877
}
7978
catch (Throwable t) {
80-
LOG.synchronizationFailed( synchronization, t );
79+
SYNCHRONIZATION_LOGGER.synchronizationFailed( synchronization, t );
8180
throw new LocalSynchronizationException(
8281
"Exception calling user Synchronization (afterCompletion): " + synchronization.getClass().getName(),
8382
t
@@ -93,7 +92,7 @@ public void notifySynchronizationsAfterTransactionCompletion(int status) {
9392

9493
@Override
9594
public void clearSynchronizations() {
96-
LOG.trace( "Clearing local Synchronizations" );
95+
SYNCHRONIZATION_LOGGER.clearingSynchronizations();
9796
if ( synchronizations != null ) {
9897
synchronizations.clear();
9998
}

0 commit comments

Comments
 (0)