Skip to content

Commit 5a3af6b

Browse files
committed
move more logging to SessionLogging
1 parent 1223520 commit 5a3af6b

File tree

5 files changed

+33
-32
lines changed

5 files changed

+33
-32
lines changed

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120

121121
import static java.lang.Boolean.TRUE;
122122
import static org.hibernate.boot.model.naming.Identifier.toIdentifier;
123+
import static org.hibernate.internal.SessionLogging.SESSION_LOGGER;
123124
import static org.hibernate.internal.util.StringHelper.isEmpty;
124125
import static org.hibernate.query.sqm.internal.SqmUtil.verifyIsSelectStatement;
125126

@@ -139,7 +140,6 @@
139140
* @author Steve Ebersole
140141
*/
141142
public abstract class AbstractSharedSessionContract implements SharedSessionContractImplementor {
142-
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( SessionImpl.class );
143143

144144
private transient SessionFactoryImpl factory;
145145
private transient SessionFactoryOptions factoryOptions;
@@ -282,13 +282,12 @@ protected final void setUpMultitenancy(SessionFactoryImplementor factory, LoadQu
282282
}
283283

284284
private void logInconsistentOptions(SharedSessionCreationOptions sharedOptions) {
285+
// TODO: these should probable be exceptions!
285286
if ( sharedOptions.shouldAutoJoinTransactions() ) {
286-
LOG.debug( "Session creation specified 'autoJoinTransactions', which is invalid in conjunction " +
287-
"with sharing JDBC connection between sessions; ignoring" );
287+
SESSION_LOGGER.invalidAutoJoinTransactionsWithSharedConnection();
288288
}
289289
if ( sharedOptions.getPhysicalConnectionHandlingMode() != connectionHandlingMode ) {
290-
LOG.debug( "Session creation specified 'PhysicalConnectionHandlingMode' which is invalid in conjunction " +
291-
"with sharing JDBC connection between sessions; ignoring" );
290+
SESSION_LOGGER.invalidPhysicalConnectionHandlingModeWithSharedConnection();
292291
}
293292
}
294293

@@ -357,15 +356,17 @@ void afterTransactionBeginEvents() {
357356
}
358357

359358
void beforeTransactionCompletionEvents() {
359+
SESSION_LOGGER.beforeTransactionCompletion();
360360
try {
361361
getInterceptor().beforeTransactionCompletion( getTransactionIfAccessible() );
362362
}
363363
catch (Throwable t) {
364-
LOG.exceptionInBeforeTransactionCompletionInterceptor( t );
364+
SESSION_LOGGER.exceptionInBeforeTransactionCompletionInterceptor( t );
365365
}
366366
}
367367

368368
void afterTransactionCompletionEvents(boolean successful) {
369+
SESSION_LOGGER.afterTransactionCompletion( successful, false );
369370
getEventListenerManager().transactionCompletion(successful);
370371

371372
final var statistics = getFactory().getStatistics();
@@ -377,7 +378,7 @@ void afterTransactionCompletionEvents(boolean successful) {
377378
getInterceptor().afterTransactionCompletion( getTransactionIfAccessible() );
378379
}
379380
catch (Throwable t) {
380-
LOG.exceptionInAfterTransactionCompletionInterceptor( t );
381+
SESSION_LOGGER.exceptionInAfterTransactionCompletionInterceptor( t );
381382
}
382383
}
383384

@@ -1686,9 +1687,7 @@ public SessionAssociationMarkers getSessionAssociationMarkers() {
16861687

16871688
@Serial
16881689
private void writeObject(ObjectOutputStream oos) throws IOException {
1689-
if ( LOG.isTraceEnabled() ) {
1690-
LOG.trace( "Serializing " + getClass().getSimpleName() + " [" );
1691-
}
1690+
SESSION_LOGGER.serializingSession( getSessionIdentifier() );
16921691

16931692

16941693
if ( !jdbcCoordinator.isReadyForSerialization() ) {
@@ -1721,13 +1720,10 @@ private void writeObject(ObjectOutputStream oos) throws IOException {
17211720

17221721
@Serial
17231722
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException, SQLException {
1724-
if ( LOG.isTraceEnabled() ) {
1725-
LOG.trace( "Deserializing " + getClass().getSimpleName() );
1726-
}
1727-
17281723
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17291724
// Step 1 :: read back non-transient state...
17301725
ois.defaultReadObject();
1726+
SESSION_LOGGER.deserializingSession( getSessionIdentifier() );
17311727

17321728
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17331729
// Step 2 :: read back transient state...

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,6 @@ public interface CoreMessageLogger extends BasicLogger {
9595
id = 84)
9696
void entityMappedAsNonAbstract(String name);
9797

98-
@LogMessage(level = ERROR)
99-
@Message(value = "Exception in interceptor afterTransactionCompletion()", id = 87)
100-
void exceptionInAfterTransactionCompletionInterceptor(@Cause Throwable e);
101-
102-
@LogMessage(level = ERROR)
103-
@Message(value = "Exception in interceptor beforeTransactionCompletion()", id = 88)
104-
void exceptionInBeforeTransactionCompletionInterceptor(@Cause Throwable e);
105-
10698
@LogMessage(level = INFO)
10799
@Message(value = "Sub-resolver threw unexpected exception, continuing to next: %s", id = 89)
108100
void exceptionInSubResolver(String message);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public SessionFactoryImpl(
211211
final MetadataImplementor bootMetamodel,
212212
final SessionFactoryOptions options,
213213
final BootstrapContext bootstrapContext) {
214-
SESSION_FACTORY_LOGGER.buildingSessionFactory();
214+
SESSION_FACTORY_LOGGER.buildingSessionFactory();
215215
typeConfiguration = bootstrapContext.getTypeConfiguration();
216216

217217
sessionFactoryOptions = options;

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

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public void close() {
358358
if ( getSessionFactoryOptions().getJpaCompliance().isJpaClosedComplianceEnabled() ) {
359359
throw new IllegalStateException( "EntityManager was already closed" );
360360
}
361-
SESSION_LOGGER.alreadyClosed();
361+
SESSION_LOGGER.alreadyClosed();
362362
}
363363
else {
364364
closeWithoutOpenChecks();
@@ -483,7 +483,7 @@ else if ( isClosed() ) {
483483
}
484484

485485
private void managedClose() {
486-
SESSION_LOGGER.automaticallyClosingSession();
486+
SESSION_LOGGER.automaticallyClosingSession();
487487
closeWithoutOpenChecks();
488488
}
489489

@@ -841,20 +841,15 @@ public void delete(String entityName, Object object, boolean isCascadeDeleteEnab
841841
public void removeOrphanBeforeUpdates(String entityName, Object child) {
842842
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484.
843843
// This should be removed once action/task ordering is improved.
844-
final boolean traceEnabled = SESSION_LOGGER.isTraceEnabled();
845-
if ( traceEnabled ) {
846-
logRemoveOrphanBeforeUpdates( "begin", entityName, child );
847-
}
844+
logRemoveOrphanBeforeUpdates( "begin", entityName, child );
848845
persistenceContext.beginRemoveOrphanBeforeUpdates();
849846
try {
850847
checkOpenOrWaitingForAutoClose();
851848
fireDelete( new DeleteEvent( entityName, child, false, true, this ) );
852849
}
853850
finally {
854851
persistenceContext.endRemoveOrphanBeforeUpdates();
855-
if ( traceEnabled ) {
856-
logRemoveOrphanBeforeUpdates( "end", entityName, child );
857-
}
852+
logRemoveOrphanBeforeUpdates( "end", entityName, child );
858853
}
859854
}
860855

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ public interface SessionLogging extends BasicLogger {
3838

3939
SessionLogging SESSION_LOGGER = Logger.getMessageLogger( MethodHandles.lookup(), SessionLogging.class, NAME );
4040

41+
@LogMessage(level = DEBUG)
42+
@Message("Session creation specified 'autoJoinTransactions', "
43+
+ "which is invalid in conjunction with sharing JDBC connection between sessions; ignoring")
44+
void invalidAutoJoinTransactionsWithSharedConnection();
45+
46+
@LogMessage(level = DEBUG)
47+
@Message("Session creation specified a 'PhysicalConnectionHandlingMode', "
48+
+ "which is invalid in conjunction with sharing JDBC connection between sessions; ignoring")
49+
void invalidPhysicalConnectionHandlingModeWithSharedConnection();
50+
4151
@LogMessage(level = TRACE)
4252
@Message("Opened Session [%s] at timestamp: %s")
4353
void openedSession(UUID sessionIdentifier, long timestamp);
@@ -118,6 +128,14 @@ public interface SessionLogging extends BasicLogger {
118128
@Message("Deserializing Session [%s]")
119129
void deserializingSession(UUID sessionIdentifier);
120130

131+
@LogMessage(level = ERROR)
132+
@Message(id = 90006106, value = "Exception in interceptor beforeTransactionCompletion()")
133+
void exceptionInBeforeTransactionCompletionInterceptor(@Cause Throwable e);
134+
135+
@LogMessage(level = ERROR)
136+
@Message(id = 90006107, value = "Exception in interceptor afterTransactionCompletion()")
137+
void exceptionInAfterTransactionCompletionInterceptor(@Cause Throwable e);
138+
121139
// StatelessSession-specific
122140

123141
@LogMessage(level = TRACE)

0 commit comments

Comments
 (0)