2727import org .hibernate .event .spi .FlushEntityEventListener ;
2828import org .hibernate .event .spi .FlushEvent ;
2929import org .hibernate .event .spi .PersistContext ;
30- import org .hibernate .internal .CoreLogging ;
31- import org .hibernate .internal .CoreMessageLogger ;
3230import org .hibernate .internal .util .EntityPrinter ;
3331import org .hibernate .internal .util .collections .InstanceIdentityMap ;
3432import org .hibernate .persister .entity .EntityPersister ;
3533
3634
3735import static org .hibernate .engine .internal .Collections .processUnreachableCollection ;
3836import static org .hibernate .engine .internal .Collections .skipRemoval ;
37+ import static org .hibernate .event .internal .EventListenerLogging .EVENT_LISTENER_LOGGER ;
3938
4039/**
4140 * A convenience base class for listeners whose functionality results in flushing.
4443 */
4544public abstract class AbstractFlushingEventListener {
4645
47- private static final CoreMessageLogger LOG = CoreLogging .messageLogger ( AbstractFlushingEventListener .class );
48-
4946 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5047 // Pre-flushing section
5148 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -59,7 +56,7 @@ public abstract class AbstractFlushingEventListener {
5956 * @throws HibernateException Error flushing caches to execution queues.
6057 */
6158 protected void flushEverythingToExecutions (FlushEvent event ) throws HibernateException {
62- LOG . trace ( "Flushing session" );
59+ EVENT_LISTENER_LOGGER . flushingSession ( );
6360 final var session = event .getSession ();
6461 final var persistenceContext = session .getPersistenceContextInternal ();
6562 preFlush ( session , persistenceContext );
@@ -94,19 +91,17 @@ protected void preFlush(EventSource session, PersistenceContext persistenceConte
9491 }
9592
9693 protected void logFlushResults (FlushEvent event ) {
97- if ( LOG .isDebugEnabled () ) {
94+ if ( EVENT_LISTENER_LOGGER .isDebugEnabled () ) {
9895 final var session = event .getSession ();
9996 final var persistenceContext = session .getPersistenceContextInternal ();
10097 final var actionQueue = session .getActionQueue ();
101- LOG .debugf (
102- "Flushed: %s insertions, %s updates, %s deletions to %s objects" ,
98+ EVENT_LISTENER_LOGGER .flushedEntitiesSummary (
10399 actionQueue .numberOfInsertions (),
104100 actionQueue .numberOfUpdates (),
105101 actionQueue .numberOfDeletions (),
106102 persistenceContext .getNumberOfManagedEntities ()
107103 );
108- LOG .debugf (
109- "Flushed: %s (re)creations, %s updates, %s removals to %s collections" ,
104+ EVENT_LISTENER_LOGGER .flushedCollectionsSummary (
110105 actionQueue .numberOfCollectionCreations (),
111106 actionQueue .numberOfCollectionUpdates (),
112107 actionQueue .numberOfCollectionRemovals (),
@@ -124,7 +119,7 @@ protected void logFlushResults(FlushEvent event) {
124119 */
125120 private void prepareEntityFlushes (EventSource session , PersistenceContext persistenceContext )
126121 throws HibernateException {
127- LOG . trace ( "Processing flush-time cascades" );
122+ EVENT_LISTENER_LOGGER . processingFlushTimeCascades ( );
128123 final var context = PersistContext .create ();
129124 // safe from concurrent modification because of how concurrentEntries() is implemented on IdentityMap
130125 for ( var entry : persistenceContext .reentrantSafeEntityEntries () ) {
@@ -188,7 +183,7 @@ private void cascadeOnFlush(EventSource session, EntityPersister persister, Obje
188183 private void prepareCollectionFlushes (PersistenceContext persistenceContext ) throws HibernateException {
189184 // Initialize dirty flags for arrays + collections with composite elements
190185 // and reset reached, doupdate, etc.
191- LOG . trace ( "Dirty checking collections" );
186+ EVENT_LISTENER_LOGGER . dirtyCheckingCollections ( );
192187 final var collectionEntries = persistenceContext .getCollectionEntries ();
193188 if ( collectionEntries != null ) {
194189 final var identityMap =
@@ -209,7 +204,7 @@ private void prepareCollectionFlushes(PersistenceContext persistenceContext) thr
209204 */
210205 private int flushEntities (final FlushEvent event , final PersistenceContext persistenceContext )
211206 throws HibernateException {
212- LOG . trace ( "Flushing entities and processing referenced collections" );
207+ EVENT_LISTENER_LOGGER . flushingEntitiesAndProcessingReferencedCollections ( );
213208
214209 final var source = event .getSession ();
215210 final var flushListeners =
@@ -267,13 +262,13 @@ private FlushEntityEvent createOrReuseEventInstance(
267262 */
268263 private int flushCollections (final EventSource session , final PersistenceContext persistenceContext )
269264 throws HibernateException {
270- LOG . trace ( "Processing unreferenced collections" );
265+ EVENT_LISTENER_LOGGER . processingUnreferencedCollections ( );
271266 final var collectionEntries = persistenceContext .getCollectionEntries ();
272267 final int count = processUnreachableCollections ( session , collectionEntries );
273268
274269 // Schedule updates to collections:
275270
276- LOG . trace ( "Scheduling collection removes/(re)creates/updates" );
271+ EVENT_LISTENER_LOGGER . schedulingCollectionOperations ( );
277272 final var actionQueue = session .getActionQueue ();
278273 final var interceptor = session .getInterceptor ();
279274 persistenceContext .forEachCollectionEntry (
@@ -370,11 +365,9 @@ private static int processUnreachableCollections(
370365 * @param session The session being flushed
371366 */
372367 protected void performExecutions (EventSource session ) {
373- LOG .trace ( "Executing flush" );
374-
375- // IMPL NOTE : here we alter the flushing flag of the persistence context to allow
376- // during-flush callbacks more leniency in regards to initializing proxies and
377- // lazy collections during their processing.
368+ // IMPL NOTE: here we alter the flushing flag of the persistence context to allow
369+ // callbacks occurring during flush more leniency regarding initializing
370+ // proxies and lazy collections
378371 // For more information, see HHH-2763
379372 final var persistenceContext = session .getPersistenceContextInternal ();
380373 final var jdbcCoordinator = session .getJdbcCoordinator ();
@@ -406,7 +399,7 @@ protected void performExecutions(EventSource session) {
406399 * </ol>
407400 */
408401 protected void postFlush (SessionImplementor session ) throws HibernateException {
409- LOG . trace ( "Post flush" );
402+ EVENT_LISTENER_LOGGER . postFlush ( );
410403
411404 final var persistenceContext = session .getPersistenceContextInternal ();
412405 persistenceContext .clearCollectionsByKey ();
0 commit comments