107
107
import static org .hibernate .event .spi .LoadEventListener .INTERNAL_LOAD_LAZY ;
108
108
import static org .hibernate .event .spi .LoadEventListener .INTERNAL_LOAD_NULLABLE ;
109
109
import static org .hibernate .internal .LockOptionsHelper .applyPropertiesToLockOptions ;
110
+ import static org .hibernate .internal .SessionLogging .SESSION_LOGGER ;
110
111
import static org .hibernate .jpa .HibernateHints .HINT_BATCH_FETCH_SIZE ;
111
112
import static org .hibernate .jpa .HibernateHints .HINT_ENABLE_SUBSELECT_FETCH ;
112
113
import static org .hibernate .jpa .HibernateHints .HINT_FETCH_PROFILE ;
@@ -154,7 +155,6 @@ public class SessionImpl
154
155
extends AbstractSharedSessionContract
155
156
implements Serializable , SharedSessionContractImplementor , JdbcSessionOwner , SessionImplementor , EventSource ,
156
157
TransactionCoordinatorBuilder .Options , WrapperOptions , LoadAccessContext {
157
- private static final CoreMessageLogger LOG = CoreLogging .messageLogger ( SessionImpl .class );
158
158
159
159
// Defaults to null which means the properties are the default
160
160
// as defined in FastSessionServices#defaultSessionProperties
@@ -220,9 +220,8 @@ public SessionImpl(SessionFactoryImpl factory, SessionCreationOptions options) {
220
220
statistics .openSession ();
221
221
}
222
222
223
- if ( LOG .isTraceEnabled () ) {
224
- LOG .tracef ( "Opened Session [%s] at timestamp: %s" ,
225
- getSessionIdentifier (), currentTimeMillis () );
223
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
224
+ SESSION_LOGGER .openedSession ( getSessionIdentifier (), currentTimeMillis () );
226
225
}
227
226
}
228
227
finally {
@@ -359,16 +358,16 @@ public void close() {
359
358
if ( getSessionFactoryOptions ().getJpaCompliance ().isJpaClosedComplianceEnabled () ) {
360
359
throw new IllegalStateException ( "EntityManager was already closed" );
361
360
}
362
- LOG . trace ( "Already closed" );
361
+ SESSION_LOGGER . alreadyClosed ( );
363
362
}
364
363
else {
365
364
closeWithoutOpenChecks ();
366
365
}
367
366
}
368
367
369
368
public void closeWithoutOpenChecks () {
370
- if ( LOG .isTraceEnabled () ) {
371
- LOG . tracef ( "Closing session [%s]" , getSessionIdentifier () );
369
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
370
+ SESSION_LOGGER . closingSession ( getSessionIdentifier () );
372
371
}
373
372
374
373
final var eventMonitor = getEventMonitor ();
@@ -425,7 +424,7 @@ private boolean isTransactionActiveAndNotMarkedForRollback() {
425
424
protected void checkBeforeClosingJdbcCoordinator () {
426
425
final var actionQueue = getActionQueue ();
427
426
if ( actionQueue .hasBeforeTransactionActions () || actionQueue .hasAfterTransactionActions () ) {
428
- LOG . warn ( "Closing shared session with unprocessed transaction completion actions" );
427
+ SESSION_LOGGER . closingSharedSessionWithUnprocessedTxCompletions ( );
429
428
}
430
429
}
431
430
@@ -453,17 +452,17 @@ public boolean isOpen() {
453
452
454
453
protected void checkSessionFactoryOpen () {
455
454
if ( !getFactory ().isOpen () ) {
456
- LOG . trace ( "Forcing-closing session since factory is already closed" );
455
+ SESSION_LOGGER . forcingCloseBecauseFactoryClosed ( );
457
456
setClosed ();
458
457
}
459
458
}
460
459
461
460
private void managedFlush () {
462
461
if ( !isOpenOrWaitingForAutoClose () ) {
463
- LOG . trace ( "Skipping auto-flush since the session is closed" );
462
+ SESSION_LOGGER . skippingAutoFlushSessionClosed ( );
464
463
}
465
464
else {
466
- LOG . trace ( "Automatically flushing session" );
465
+ SESSION_LOGGER . automaticallyFlushingSession ( );
467
466
fireFlush ();
468
467
}
469
468
}
@@ -484,7 +483,7 @@ else if ( isClosed() ) {
484
483
}
485
484
486
485
private void managedClose () {
487
- LOG . trace ( "Automatically closing session" );
486
+ SESSION_LOGGER . automaticallyClosingSession ( );
488
487
closeWithoutOpenChecks ();
489
488
}
490
489
@@ -825,7 +824,7 @@ private void fireMerge(final MergeContext mergeContext, final MergeEvent mergeEv
825
824
public void delete (String entityName , Object object , boolean isCascadeDeleteEnabled , DeleteContext transientEntities ) {
826
825
checkOpenOrWaitingForAutoClose ();
827
826
final boolean removingOrphanBeforeUpdates = persistenceContext .isRemovingOrphanBeforeUpdates ();
828
- final boolean traceEnabled = LOG .isTraceEnabled ();
827
+ final boolean traceEnabled = SESSION_LOGGER .isTraceEnabled ();
829
828
if ( traceEnabled && removingOrphanBeforeUpdates ) {
830
829
logRemoveOrphanBeforeUpdates ( "before continuing" , entityName , object );
831
830
}
@@ -842,7 +841,7 @@ public void delete(String entityName, Object object, boolean isCascadeDeleteEnab
842
841
public void removeOrphanBeforeUpdates (String entityName , Object child ) {
843
842
// TODO: The removeOrphan concept is a temporary "hack" for HHH-6484.
844
843
// This should be removed once action/task ordering is improved.
845
- final boolean traceEnabled = LOG .isTraceEnabled ();
844
+ final boolean traceEnabled = SESSION_LOGGER .isTraceEnabled ();
846
845
if ( traceEnabled ) {
847
846
logRemoveOrphanBeforeUpdates ( "begin" , entityName , child );
848
847
}
@@ -860,13 +859,10 @@ public void removeOrphanBeforeUpdates(String entityName, Object child) {
860
859
}
861
860
862
861
private void logRemoveOrphanBeforeUpdates (String timing , String entityName , Object entity ) {
863
- if ( LOG .isTraceEnabled () ) {
862
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
864
863
final var entityEntry = persistenceContext .getEntry ( entity );
865
- LOG .tracef (
866
- "%s remove orphan before updates: [%s]" ,
867
- timing ,
868
- entityEntry == null ? entityName : infoString ( entityName , entityEntry .getId () )
869
- );
864
+ final String entityInfo = entityEntry == null ? entityName : infoString ( entityName , entityEntry .getId () );
865
+ SESSION_LOGGER .removeOrphanBeforeUpdates ( timing , entityInfo );
870
866
}
871
867
}
872
868
@@ -1002,9 +998,9 @@ public Object get(String entityName, Object id) {
1002
998
*/
1003
999
@ Override
1004
1000
public Object immediateLoad (String entityName , Object id ) {
1005
- if ( LOG .isDebugEnabled () ) {
1001
+ if ( SESSION_LOGGER .isDebugEnabled () ) {
1006
1002
final var persister = requireEntityPersister ( entityName );
1007
- LOG . tracef ( "Initializing proxy: %s" , infoString ( persister , id , getFactory () ) );
1003
+ SESSION_LOGGER . initializingProxy ( infoString ( persister , id , getFactory () ) );
1008
1004
}
1009
1005
final var event = makeLoadEvent ( entityName , id , getReadOnlyFromLoadQueryInfluencers (), true );
1010
1006
fireLoadNoChecks ( event , IMMEDIATE_LOAD );
@@ -1026,7 +1022,7 @@ public Object internalLoad(String entityName, Object id, boolean eager, boolean
1026
1022
clearedEffectiveGraph = false ;
1027
1023
}
1028
1024
else {
1029
- LOG . trace ( "Clearing effective entity graph for subsequent select" );
1025
+ SESSION_LOGGER . clearingEffectiveEntityGraph ( );
1030
1026
clearedEffectiveGraph = true ;
1031
1027
effectiveEntityGraph .clear ();
1032
1028
}
@@ -1467,9 +1463,8 @@ public void forceFlush(EntityEntry entityEntry) {
1467
1463
1468
1464
@ Override
1469
1465
public void forceFlush (EntityKey key ) {
1470
- if ( LOG .isTraceEnabled () ) {
1471
- LOG .tracef ("Flushing to force deletion of re-saved object: "
1472
- + infoString ( key .getPersister (), key .getIdentifier (), getFactory () ) );
1466
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
1467
+ SESSION_LOGGER .flushingToForceDeletion ( infoString ( key .getPersister (), key .getIdentifier (), getFactory () ) );
1473
1468
}
1474
1469
1475
1470
if ( persistenceContext .getCascadeLevel () > 0 ) {
@@ -1839,7 +1834,7 @@ public String toString() {
1839
1834
.append ( "SessionImpl(" )
1840
1835
.append ( System .identityHashCode ( this ) );
1841
1836
if ( !isClosed () ) {
1842
- if ( LOG .isTraceEnabled () ) {
1837
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
1843
1838
string .append ( persistenceContext )
1844
1839
.append ( ";" )
1845
1840
.append ( actionQueue );
@@ -1991,7 +1986,7 @@ public LobHelper getLobHelper() {
1991
1986
1992
1987
@ Override
1993
1988
public void beforeTransactionCompletion () {
1994
- LOG . trace ( "SessionImpl# beforeTransactionCompletion()" );
1989
+ SESSION_LOGGER . beforeTransactionCompletion ();
1995
1990
flushBeforeTransactionCompletion ();
1996
1991
actionQueue .beforeTransactionCompletion ();
1997
1992
beforeTransactionCompletionEvents ();
@@ -2000,8 +1995,8 @@ public void beforeTransactionCompletion() {
2000
1995
2001
1996
@ Override
2002
1997
public void afterTransactionCompletion (boolean successful , boolean delayed ) {
2003
- if ( LOG .isTraceEnabled () ) {
2004
- LOG . tracef ( "SessionImpl# afterTransactionCompletion(successful=%s, delayed=%s)" , successful , delayed );
1998
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
1999
+ SESSION_LOGGER . afterTransactionCompletion ( successful , delayed );
2005
2000
}
2006
2001
2007
2002
final boolean notClosed = isOpenOrWaitingForAutoClose ();
@@ -2193,7 +2188,7 @@ private <T> T find(Class<T> entityClass, Object primaryKey, LockOptions lockOpti
2193
2188
if ( accessTransaction ().isActive () && accessTransaction ().getRollbackOnly () ) {
2194
2189
// Assume situation HHH-12472 running on WildFly
2195
2190
// Just log the exception and return null
2196
- LOG .jdbcExceptionThrownWithTransactionRolledBack ( e );
2191
+ SESSION_LOGGER .jdbcExceptionThrownWithTransactionRolledBack ( e );
2197
2192
return null ;
2198
2193
}
2199
2194
else {
@@ -2211,8 +2206,8 @@ private <T> T find(Class<T> entityClass, Object primaryKey, LockOptions lockOpti
2211
2206
2212
2207
// Hibernate Reactive calls this
2213
2208
protected static <T > void logIgnoringEntityNotFound (Class <T > entityClass , Object primaryKey ) {
2214
- if ( LOG .isDebugEnabled () ) {
2215
- LOG .ignoringEntityNotFound (
2209
+ if ( SESSION_LOGGER .isDebugEnabled () ) {
2210
+ SESSION_LOGGER .ignoringEntityNotFound (
2216
2211
entityClass != null ? entityClass .getName (): null ,
2217
2212
primaryKey != null ? primaryKey .toString () : null
2218
2213
);
@@ -2544,12 +2539,12 @@ public void setProperty(String propertyName, Object value) {
2544
2539
checkOpen ();
2545
2540
2546
2541
if ( !( value instanceof Serializable ) ) {
2547
- LOG . warnf ( "Property '%s' is not serializable, value won't be set" , propertyName );
2542
+ SESSION_LOGGER . nonSerializableProperty ( propertyName );
2548
2543
return ;
2549
2544
}
2550
2545
2551
2546
if ( propertyName == null ) {
2552
- LOG . warn ( "Property having key null is illegal, value won't be set" );
2547
+ SESSION_LOGGER . nullPropertyKey ( );
2553
2548
return ;
2554
2549
}
2555
2550
@@ -2767,8 +2762,8 @@ public <E> Collection<E> getManagedEntities(EntityType<E> entityType) {
2767
2762
*/
2768
2763
@ Serial
2769
2764
private void writeObject (ObjectOutputStream oos ) throws IOException {
2770
- if ( LOG .isTraceEnabled () ) {
2771
- LOG . tracef ( "Serializing Session [%s]" , getSessionIdentifier () );
2765
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
2766
+ SESSION_LOGGER . serializingSession ( getSessionIdentifier () );
2772
2767
}
2773
2768
2774
2769
oos .defaultWriteObject ();
@@ -2789,8 +2784,8 @@ private void writeObject(ObjectOutputStream oos) throws IOException {
2789
2784
*/
2790
2785
@ Serial
2791
2786
private void readObject (ObjectInputStream ois ) throws IOException , ClassNotFoundException , SQLException {
2792
- if ( LOG .isTraceEnabled () ) {
2793
- LOG . tracef ( "Deserializing Session [%s]" , getSessionIdentifier () );
2787
+ if ( SESSION_LOGGER .isTraceEnabled () ) {
2788
+ SESSION_LOGGER . deserializingSession ( getSessionIdentifier () );
2794
2789
}
2795
2790
2796
2791
ois .defaultReadObject ();
0 commit comments