Skip to content

Commit 273959c

Browse files
committed
minor optimizations to logging and comments in event handlers
1 parent 14ff439 commit 273959c

File tree

7 files changed

+74
-85
lines changed

7 files changed

+74
-85
lines changed

hibernate-core/src/main/java/org/hibernate/event/internal/AbstractFlushingEventListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ protected void logFlushResults(FlushEvent event) {
121121
}
122122

123123
/**
124-
* process cascade save/update at the start of a flush to discover
124+
* Process cascade save/update at the start of a flush to discover
125125
* any newly referenced entity that must be passed to saveOrUpdate(),
126126
* and also apply orphan delete
127127
*/
128128
private void prepareEntityFlushes(EventSource session, PersistenceContext persistenceContext)
129129
throws HibernateException {
130-
LOG.debug( "Processing flush-time cascades" );
130+
LOG.trace( "Processing flush-time cascades" );
131131
final PersistContext context = PersistContext.create();
132132
// safe from concurrent modification because of how concurrentEntries() is implemented on IdentityMap
133133
for ( var me : persistenceContext.reentrantSafeEntityEntries() ) {

hibernate-core/src/main/java/org/hibernate/event/internal/AbstractSaveEventListener.java

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
import static org.hibernate.pretty.MessageHelper.infoString;
4444

4545
/**
46-
* A convenience base class for listeners responding to save events.
46+
* A convenience base class for listeners responding to persist or merge events.
47+
* <p>
48+
* This class contains common functionality for persisting new transient instances.
4749
*
4850
* @author Steve Ebersole.
4951
*/
@@ -58,13 +60,13 @@ public void injectCallbackRegistry(CallbackRegistry callbackRegistry) {
5860
}
5961

6062
/**
61-
* Prepares the save call using the given requested id.
63+
* Prepares the persist call using the given requested id.
6264
*
63-
* @param entity The entity to be saved.
64-
* @param requestedId The id to which to associate the entity.
65-
* @param entityName The name of the entity being saved.
66-
* @param context Generally cascade-specific information.
67-
* @param source The session which is the source of this save event.
65+
* @param entity The entity to be persisted
66+
* @param requestedId The id with which to associate the entity
67+
* @param entityName The name of the entity being persisted
68+
* @param context Generally cascade-specific information
69+
* @param source The session which is the source of this event
6870
*
6971
* @return The id used to save the entity.
7072
*/
@@ -79,18 +81,18 @@ protected Object saveWithRequestedId(
7981
}
8082

8183
/**
82-
* Prepares the save call using a newly generated id.
84+
* Prepares the persist call using a newly generated id.
8385
*
84-
* @param entity The entity to be saved
85-
* @param entityName The entity-name for the entity to be saved
86-
* @param context Generally cascade-specific information.
87-
* @param source The session which is the source of this save event.
86+
* @param entity The entity to be persisted
87+
* @param entityName The entity-name for the entity to be persisted
88+
* @param context Generally cascade-specific information
89+
* @param source The session which is the source of this persist event
8890
* @param requiresImmediateIdAccess does the event context require
8991
* access to the identifier immediately after execution of this method
9092
* (if not, post-insert style id generators may be postponed if we are
9193
* outside a transaction).
9294
*
93-
* @return The id used to save the entity; may be null depending on the
95+
* @return The id used to persist the entity; may be null depending on the
9496
* type of id generator used and the requiresImmediateIdAccess value
9597
*/
9698
protected Object saveWithGeneratedId(
@@ -140,10 +142,10 @@ else if ( generatedBeforeExecution ) {
140142
* Generate an id before execution of the insert statements,
141143
* using the given {@link BeforeExecutionGenerator}.
142144
*
143-
* @param entity The entity instance to be saved
144-
* @param source The session which is the source of this save event.
145-
* @param generator The entity's generator
146-
* @param persister The entity's persister instance.
145+
* @param entity The entity instance to be persisted
146+
* @param source The session which is the source of this persist event
147+
* @param generator The generator for the entity id
148+
* @param persister The persister for the entity
147149
*
148150
* @return The generated id
149151
*/
@@ -158,7 +160,7 @@ private static Object generateId(
158160
throw new IdentifierGenerationException( "Null id generated for entity '" + persister.getEntityName() + "'" );
159161
}
160162
else {
161-
if ( LOG.isDebugEnabled() ) {
163+
if ( LOG.isTraceEnabled() ) {
162164
// TODO: define toString()s for generators
163165
LOG.tracef(
164166
"Generated identifier [%s] using generator '%s'",
@@ -171,18 +173,18 @@ private static Object generateId(
171173
}
172174

173175
/**
174-
* Prepares the save call by checking the session caches for a pre-existing
176+
* Prepares the persist call by checking the session caches for a pre-existing
175177
* entity and performing any lifecycle callbacks.
176178
*
177-
* @param entity The entity to be saved.
178-
* @param id The id by which to save the entity.
179-
* @param persister The entity's persister instance.
179+
* @param entity The entity to be persisted
180+
* @param id The id by which to persist the entity
181+
* @param persister The entity's persister instance
180182
* @param useIdentityColumn Is an identity column being used?
181-
* @param context Generally cascade-specific information.
182-
* @param source The session from which the event originated.
183+
* @param context Generally cascade-specific information
184+
* @param source The session from which the event originated
183185
* @param delayIdentityInserts Should the identity insert be delayed?
184186
*
185-
* @return The id used to save the entity; may be null depending on the
187+
* @return The id used to persist the entity; may be null depending on the
186188
* type of id generator used and on delayIdentityInserts
187189
*/
188190
protected Object performSave(
@@ -211,7 +213,7 @@ protected Object performSave(
211213
}
212214

213215
if ( LOG.isTraceEnabled() ) {
214-
LOG.trace( "Saving " + infoString( persister, id, source.getFactory() ) );
216+
LOG.trace( "Persisting " + infoString( persister, id, source.getFactory() ) );
215217
}
216218

217219
final EntityKey key = useIdentityColumn ? null : entityKey( id, persister, source );
@@ -237,18 +239,18 @@ else if ( persistenceContext.containsDeletedUnloadedEntityKey( key ) ) {
237239
}
238240

239241
/**
240-
* Performs all the actual work needed to save an entity (well to get the save moved to
241-
* the execution queue).
242+
* Performs all the actual work needed to persist an entity
243+
* (well to get the persist action moved to the execution queue).
242244
*
243-
* @param entity The entity to be saved
245+
* @param entity The entity to be persisted
244246
* @param key The id to be used for saving the entity (or null, in the case of identity columns)
245-
* @param persister The entity's persister instance.
247+
* @param persister The persister for the entity
246248
* @param useIdentityColumn Should an identity column be used for id generation?
247-
* @param context Generally cascade-specific information.
248-
* @param source The session which is the source of the current event.
249+
* @param context Generally cascade-specific information
250+
* @param source The session which is the source of the current event
249251
* @param delayIdentityInserts Should the identity insert be delayed?
250252
*
251-
* @return The id used to save the entity; may be null depending on the
253+
* @return The id used to persist the entity; may be null depending on the
252254
* type of id generator used and the requiresImmediateIdAccess value
253255
*/
254256
protected Object performSaveOrReplicate(
@@ -394,10 +396,10 @@ protected Map<Object,Object> getMergeMap(C anything) {
394396
}
395397

396398
/**
397-
* After the save, will the version number be incremented
399+
* After the persist, will the version number be incremented
398400
* if the instance is modified?
399401
*
400-
* @return True if the version will be incremented on an entity change after save;
402+
* @return True if the version will be incremented on an entity change after persist;
401403
* false otherwise.
402404
*/
403405
protected boolean isVersionIncrementDisabled() {
@@ -451,11 +453,11 @@ protected boolean substituteValuesIfNecessary(
451453
}
452454

453455
/**
454-
* Handles the calls needed to perform pre-save cascades for the given entity.
456+
* Handles the calls needed to perform pre-persist cascades for the given entity.
455457
*
456-
* @param source The session from which the save event originated.
457-
* @param persister The entity's persister instance.
458-
* @param entity The entity to be saved.
458+
* @param source The session from which the persist event originated
459+
* @param persister The persister for the entity
460+
* @param entity The entity to be persisted
459461
* @param context Generally cascade-specific data
460462
*/
461463
protected void cascadeBeforeSave(
@@ -482,11 +484,11 @@ protected void cascadeBeforeSave(
482484
}
483485

484486
/**
485-
* Handles calls needed to perform post-save cascades.
487+
* Handles calls needed to perform post-persist cascades.
486488
*
487-
* @param source The session from which the event originated.
488-
* @param persister The entity's persister instance.
489-
* @param entity The entity being saved.
489+
* @param source The session from which the event originated
490+
* @param persister The persister for the entity
491+
* @param entity The entity being persisted
490492
* @param context Generally cascade-specific data
491493
*/
492494
protected void cascadeAfterSave(

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultMergeEventListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ else if ( isPersistentAttributeInterceptable( original ) ) {
121121
final PersistentAttributeInterceptor interceptor =
122122
asPersistentAttributeInterceptable( original ).$$_hibernate_getInterceptor();
123123
if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor proxyInterceptor ) {
124-
LOG.trace( "Ignoring uninitialized enhanced-proxy" );
124+
LOG.trace( "Ignoring uninitialized enhanced proxy" );
125125
event.setResult( source.byId( proxyInterceptor.getEntityName() )
126126
.getReference( proxyInterceptor.getIdentifier() ) );
127127
}
@@ -314,7 +314,7 @@ protected void entityIsTransient(MergeEvent event, Object id, MergeContext copyC
314314
// copy created before we actually copy
315315
super.cascadeAfterSave( session, persister, entity, copyCache );
316316

317-
// this is the second pass through on a merge op, so here we limit the
317+
// this is the second pass of a merge operation, so here we limit the
318318
// replacement to association types (value types were already replaced
319319
// during the first pass)
320320
// final Object[] newSourceValues = persister.getValues( entity );

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultPersistEventListener.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
import org.hibernate.internal.CoreMessageLogger;
2020
import org.hibernate.jpa.event.spi.CallbackRegistryConsumer;
2121
import org.hibernate.persister.entity.EntityPersister;
22-
import org.hibernate.pretty.MessageHelper;
2322
import org.hibernate.proxy.HibernateProxy;
2423
import org.hibernate.proxy.LazyInitializer;
2524

2625
import static org.hibernate.event.internal.EntityState.getEntityState;
26+
import static org.hibernate.pretty.MessageHelper.infoString;
2727

2828
/**
29-
* Defines the default create event listener used by hibernate for creating
30-
* transient entities in response to generated create events.
29+
* Defines the default event listener used by Hibernate for persisting
30+
* transient entities in response to generated persist events.
3131
*
3232
* @author Gavin King
3333
*/
@@ -53,9 +53,9 @@ public void onPersist(PersistEvent event) throws HibernateException {
5353
}
5454

5555
/**
56-
* Handle the given create event.
56+
* Handle the given persist event.
5757
*
58-
* @param event The create event to be handled.
58+
* @param event The persist event to be handled
5959
*
6060
*/
6161
@Override
@@ -83,7 +83,7 @@ private void persist(PersistEvent event, PersistContext createCache, Object enti
8383
final String entityName = entityName( event, entity, entityEntry );
8484
switch ( getEntityState( entity, entityName, entityEntry, source, true ) ) {
8585
case DETACHED:
86-
throw new PersistentObjectException( "detached entity passed to persist: "
86+
throw new PersistentObjectException( "Detached entity passed to persist: "
8787
+ EventUtil.getLoggableName( event.getEntityName(), entity) );
8888
case PERSISTENT:
8989
entityIsPersistent( event, createCache );
@@ -99,7 +99,7 @@ private void persist(PersistEvent event, PersistContext createCache, Object enti
9999
break;
100100
default:
101101
throw new ObjectDeletedException(
102-
"deleted entity passed to persist",
102+
"Deleted entity passed to persist",
103103
null,
104104
EventUtil.getLoggableName( event.getEntityName(), entity )
105105
);
@@ -135,13 +135,13 @@ private void justCascade(PersistContext createCache, EventSource source, Object
135135
}
136136

137137
/**
138-
* Handle the given create event.
138+
* Handle the given persist event.
139139
*
140-
* @param event The save event to be handled.
141-
* @param createCache The copy cache of entity instance to merge/copy instance.
140+
* @param event The persist event to be handled
141+
* @param createCache The copy cache of entity instance to merge/copy instance
142142
*/
143143
protected void entityIsTransient(PersistEvent event, PersistContext createCache) {
144-
LOG.trace( "Saving transient instance" );
144+
LOG.trace( "Persisting transient instance" );
145145
final EventSource source = event.getSession();
146146
final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() );
147147
if ( createCache.add( entity ) ) {
@@ -154,10 +154,8 @@ private void entityIsDeleted(PersistEvent event, PersistContext createCache) {
154154
final Object entity = source.getPersistenceContextInternal().unproxy( event.getObject() );
155155
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
156156
if ( LOG.isTraceEnabled() ) {
157-
LOG.tracef(
158-
"un-scheduling entity deletion [%s]",
159-
MessageHelper.infoString( persister, persister.getIdentifier( entity, source ), event.getFactory() )
160-
);
157+
final Object id = persister.getIdentifier( entity, source );
158+
LOG.trace( "Unscheduling entity deletion: " + infoString( persister, id, source.getFactory() ) );
161159
}
162160
if ( createCache.add( entity ) ) {
163161
justCascade( createCache, source, entity, persister );

hibernate-core/src/main/java/org/hibernate/event/internal/DefaultReplicateEventListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private void doReplicate(ReplicateEvent event, EventSource source, Object entity
9797
performReplication( entity, id, realOldVersion, persister, replicationMode, source );
9898
}
9999
else if ( LOG.isTraceEnabled() ) {
100-
// do nothing (don't even re-associate object!)
100+
// do nothing (don't even reassociate entity!)
101101
LOG.trace( "No need to replicate" );
102102
}
103103

hibernate-core/src/main/java/org/hibernate/event/internal/EntityCopyAllowedLoggedObserver.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import org.hibernate.internal.CoreLogging;
1616
import org.hibernate.internal.CoreMessageLogger;
1717
import org.hibernate.internal.util.collections.IdentitySet;
18-
import org.hibernate.pretty.MessageHelper;
18+
19+
import static org.hibernate.pretty.MessageHelper.infoString;
1920

2021
/**
2122
* An {@link EntityCopyObserver} implementation that allows multiple representations of
@@ -53,15 +54,10 @@ public void entityCopyDetected(
5354
Object mergeEntity2,
5455
EventSource session) {
5556
final String entityName = session.getEntityName( managedEntity );
56-
LOG.trace(
57-
String.format(
58-
"More than one representation of the same persistent entity being merged for: %s",
59-
MessageHelper.infoString(
60-
entityName,
61-
session.getIdentifier( managedEntity )
62-
)
63-
)
64-
);
57+
if ( LOG.isTraceEnabled() ) {
58+
LOG.trace( "More than one representation of the same persistent entity being merged for: "
59+
+ infoString( entityName, session.getIdentifier( managedEntity ) ) );
60+
}
6561
Set<Object> detachedEntitiesForManaged = null;
6662
if ( managedToMergeEntitiesXref == null ) {
6763
// This is the first time multiple representations have been found;
@@ -125,7 +121,7 @@ public void topLevelMergeComplete(EventSource session) {
125121
}
126122
}
127123
else {
128-
LOG.debug( "No entity copies merged." );
124+
LOG.debug( "No entity copies merged" );
129125
}
130126

131127
if ( managedToMergeEntitiesXref != null ) {
@@ -135,12 +131,8 @@ public void topLevelMergeComplete(EventSource session) {
135131
final StringBuilder sb = new StringBuilder( "Details: merged ")
136132
.append( mergeEntities.size() )
137133
.append( " representations of the same entity " )
138-
.append(
139-
MessageHelper.infoString(
140-
session.getEntityName( managedEntity ),
141-
session.getIdentifier( managedEntity )
142-
)
143-
)
134+
.append( infoString( session.getEntityName( managedEntity ),
135+
session.getIdentifier( managedEntity ) ) )
144136
.append( " being merged: " );
145137
boolean first = true;
146138
for ( Object mergeEntity : mergeEntities ) {

hibernate-core/src/main/java/org/hibernate/event/internal/EvictVisitor.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,8 @@ private void evictCollection(PersistentCollection<?> collection) {
7272
final CollectionPersister persister = ce.getLoadedPersister();
7373
final Object loadedKey = ce.getLoadedKey();
7474

75-
if ( LOG.isDebugEnabled() ) {
76-
LOG.debugf(
77-
"Evicting collection: %s",
78-
collectionInfoString( persister, collection, loadedKey, session )
79-
);
75+
if ( LOG.isTraceEnabled() ) {
76+
LOG.trace( "Evicting collection: " + collectionInfoString( persister, collection, loadedKey, session ) );
8077
}
8178

8279
if ( persister != null ) {

0 commit comments

Comments
 (0)