add some 'final' annotations

This commit is contained in:
Gavin King 2024-11-23 12:58:48 +01:00
parent 6dd5c3f2b7
commit 8a21303789
2 changed files with 36 additions and 36 deletions

View File

@ -18,10 +18,11 @@ import org.hibernate.event.spi.EvictEventListener;
import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer; import org.hibernate.proxy.LazyInitializer;
import static org.hibernate.pretty.MessageHelper.infoString;
/** /**
* Defines the default evict event listener used by hibernate for evicting entities * Defines the default evict event listener used by hibernate for evicting entities
* in response to generated flush events. In particular, this implementation will * in response to generated flush events. In particular, this implementation will
@ -53,23 +54,23 @@ public class DefaultEvictEventListener implements EvictEventListener {
if ( id == null ) { if ( id == null ) {
throw new IllegalArgumentException( "Could not determine identifier of proxy passed to evict()" ); throw new IllegalArgumentException( "Could not determine identifier of proxy passed to evict()" );
} }
final EntityPersister persister = source.getFactory() final EntityPersister persister =
.getMappingMetamodel() source.getFactory().getMappingMetamodel()
.getEntityDescriptor( lazyInitializer.getEntityName() ); .getEntityDescriptor( lazyInitializer.getEntityName() );
final EntityKey key = source.generateEntityKey( id, persister ); final EntityKey key = source.generateEntityKey( id, persister );
final EntityHolder holder = persistenceContext.detachEntity( key ); final EntityHolder holder = persistenceContext.detachEntity( key );
// if the entity has been evicted then its holder is null // if the entity has been evicted then its holder is null
if ( holder != null && !lazyInitializer.isUninitialized() ) { if ( holder != null && !lazyInitializer.isUninitialized() ) {
final Object entity = holder.getEntity(); final Object entity = holder.getEntity();
if ( entity != null ) { if ( entity != null ) {
EntityEntry entry = persistenceContext.removeEntry( entity ); final EntityEntry entry = persistenceContext.removeEntry( entity );
doEvict( entity, key, entry.getPersister(), event.getSession() ); doEvict( entity, key, entry.getPersister(), event.getSession() );
} }
} }
lazyInitializer.unsetSession(); lazyInitializer.unsetSession();
} }
else { else {
EntityEntry entry = persistenceContext.getEntry( object ); final EntityEntry entry = persistenceContext.getEntry( object );
if ( entry != null ) { if ( entry != null ) {
doEvict( object, entry.getEntityKey(), entry.getPersister(), source ); doEvict( object, entry.getEntityKey(), entry.getPersister(), source );
} }
@ -85,11 +86,12 @@ public class DefaultEvictEventListener implements EvictEventListener {
* requires with EntityManager.detach(). * requires with EntityManager.detach().
*/ */
private static void checkEntity(Object object, EventSource source) { private static void checkEntity(Object object, EventSource source) {
String entityName = source.getSession().guessEntityName( object ); final String entityName = source.getSession().guessEntityName( object );
if ( entityName != null ) { if ( entityName != null ) {
try { try {
EntityPersister persister = source.getFactory().getMappingMetamodel() final EntityPersister persister =
.getEntityDescriptor( entityName ); source.getFactory().getMappingMetamodel()
.getEntityDescriptor( entityName );
if ( persister != null ) { if ( persister != null ) {
return; //ALL GOOD return; //ALL GOOD
} }
@ -107,7 +109,7 @@ public class DefaultEvictEventListener implements EvictEventListener {
final EventSource session) final EventSource session)
throws HibernateException { throws HibernateException {
if ( LOG.isTraceEnabled() ) { if ( LOG.isTraceEnabled() ) {
LOG.tracev( "Evicting {0}", MessageHelper.infoString( persister ) ); LOG.tracev( "Evicting {0}", infoString( persister ) );
} }
final PersistenceContext persistenceContext = session.getPersistenceContextInternal(); final PersistenceContext persistenceContext = session.getPersistenceContextInternal();

View File

@ -35,7 +35,6 @@ import org.hibernate.jpa.event.spi.CallbackRegistry;
import org.hibernate.jpa.event.spi.CallbackRegistryConsumer; import org.hibernate.jpa.event.spi.CallbackRegistryConsumer;
import org.hibernate.metamodel.mapping.NaturalIdMapping; import org.hibernate.metamodel.mapping.NaturalIdMapping;
import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.pretty.MessageHelper;
import org.hibernate.stat.spi.StatisticsImplementor; import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.type.Type; import org.hibernate.type.Type;
@ -50,6 +49,7 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.processIfManagedEn
import static org.hibernate.engine.internal.Versioning.getVersion; import static org.hibernate.engine.internal.Versioning.getVersion;
import static org.hibernate.engine.internal.Versioning.incrementVersion; import static org.hibernate.engine.internal.Versioning.incrementVersion;
import static org.hibernate.engine.internal.Versioning.setVersion; import static org.hibernate.engine.internal.Versioning.setVersion;
import static org.hibernate.pretty.MessageHelper.infoString;
/** /**
* An event that occurs for each entity instance at flush time * An event that occurs for each entity instance at flush time
@ -110,7 +110,8 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
private static boolean isUninitializedEnhanced(Object entity) { private static boolean isUninitializedEnhanced(Object entity) {
if ( isPersistentAttributeInterceptable( entity ) ) { if ( isPersistentAttributeInterceptable( entity ) ) {
final PersistentAttributeInterceptor interceptor = asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor(); final PersistentAttributeInterceptor interceptor =
asPersistentAttributeInterceptable( entity ).$$_hibernate_getInterceptor();
// the entity is an un-initialized enhancement-as-proxy reference // the entity is an un-initialized enhancement-as-proxy reference
return interceptor instanceof EnhancementAsProxyLazinessInterceptor; return interceptor instanceof EnhancementAsProxyLazinessInterceptor;
} }
@ -162,7 +163,6 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
private Object[] getValues(Object entity, EntityEntry entry, boolean mightBeDirty, SessionImplementor session) { private Object[] getValues(Object entity, EntityEntry entry, boolean mightBeDirty, SessionImplementor session) {
final Object[] loadedState = entry.getLoadedState(); final Object[] loadedState = entry.getLoadedState();
if ( entry.getStatus() == Status.DELETED ) { if ( entry.getStatus() == Status.DELETED ) {
//grab its state saved at deletion //grab its state saved at deletion
return entry.getDeletedState(); return entry.getDeletedState();
@ -216,8 +216,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
final Object entity = event.getEntity(); final Object entity = event.getEntity();
processIfSelfDirtinessTracker( entity, SelfDirtinessTracker::$$_hibernate_clearDirtyAttributes ); processIfSelfDirtinessTracker( entity, SelfDirtinessTracker::$$_hibernate_clearDirtyAttributes );
processIfManagedEntity( entity, DefaultFlushEntityEventListener::useTracker ); processIfManagedEntity( entity, DefaultFlushEntityEventListener::useTracker );
event.getFactory() event.getFactory().getCustomEntityDirtinessStrategy()
.getCustomEntityDirtinessStrategy()
.resetDirty( entity, entry.getPersister(), event.getSession() ); .resetDirty( entity, entry.getPersister(), event.getSession() );
return false; return false;
} }
@ -246,7 +245,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
// increment the version number (if necessary) // increment the version number (if necessary)
final Object nextVersion = getNextVersion( event ); final Object nextVersion = getNextVersion( event );
int[] dirtyProperties = getDirtyProperties( event, intercepted ); final int[] dirtyProperties = getDirtyProperties( event, intercepted );
// check nullability but do not doAfterTransactionCompletion command execute // check nullability but do not doAfterTransactionCompletion command execute
// we'll use scheduled updates for that. // we'll use scheduled updates for that.
@ -276,7 +275,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
} }
private static int[] getDirtyProperties(FlushEntityEvent event, boolean intercepted) { private static int[] getDirtyProperties(FlushEntityEvent event, boolean intercepted) {
int[] dirtyProperties = event.getDirtyProperties(); final int[] dirtyProperties = event.getDirtyProperties();
if ( event.isDirtyCheckPossible() && dirtyProperties == null ) { if ( event.isDirtyCheckPossible() && dirtyProperties == null ) {
if ( !intercepted && !event.hasDirtyCollection() ) { if ( !intercepted && !event.hasDirtyCollection() ) {
throw new AssertionFailure( "dirty, but no dirty properties" ); throw new AssertionFailure( "dirty, but no dirty properties" );
@ -297,26 +296,26 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
if ( !persister.isMutable() ) { if ( !persister.isMutable() ) {
LOG.tracev( LOG.tracev(
"Updating immutable, deleted entity: {0}", "Updating immutable, deleted entity: {0}",
MessageHelper.infoString(persister, entry.getId(), factory) infoString(persister, entry.getId(), factory)
); );
} }
else if ( !entry.isModifiableEntity() ) { else if ( !entry.isModifiableEntity() ) {
LOG.tracev( LOG.tracev(
"Updating non-modifiable, deleted entity: {0}", "Updating non-modifiable, deleted entity: {0}",
MessageHelper.infoString(persister, entry.getId(), factory) infoString(persister, entry.getId(), factory)
); );
} }
else { else {
LOG.tracev( LOG.tracev(
"Updating deleted entity: {0}", "Updating deleted entity: {0}",
MessageHelper.infoString(persister, entry.getId(), factory) infoString(persister, entry.getId(), factory)
); );
} }
} }
else { else {
LOG.tracev( LOG.tracev(
"Updating entity: {0}", "Updating entity: {0}",
MessageHelper.infoString(persister, entry.getId(), factory) infoString(persister, entry.getId(), factory)
); );
} }
} }
@ -340,12 +339,12 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
final EntityPersister persister = entry.getPersister(); final EntityPersister persister = entry.getPersister();
final EventSource session = event.getSession(); final EventSource session = event.getSession();
boolean isDirty = false; final boolean isDirty;
if ( entry.getStatus() != Status.DELETED && callbackRegistry.preUpdate( entity ) ) {
if ( entry.getStatus() != Status.DELETED ) { isDirty = copyState( entity, persister.getPropertyTypes(), values, event.getFactory() );
if ( callbackRegistry.preUpdate( entity ) ) { }
isDirty = copyState( entity, persister.getPropertyTypes(), values, event.getFactory() ); else {
} isDirty = false;
} }
final boolean stateModified = session.getInterceptor().onFlushDirty( final boolean stateModified = session.getInterceptor().onFlushDirty(
@ -414,7 +413,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
return false; return false;
} }
else { else {
int[] dirtyProperties = event.getDirtyProperties(); final int[] dirtyProperties = event.getDirtyProperties();
return dirtyProperties == null return dirtyProperties == null
|| Versioning.isVersionIncrementRequired( || Versioning.isVersionIncrementRequired(
dirtyProperties, dirtyProperties,
@ -445,7 +444,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
persister.getPropertyVersionability() persister.getPropertyVersionability()
); );
visitor.processEntityPropertyValues( event.getPropertyValues(), persister.getPropertyTypes() ); visitor.processEntityPropertyValues( event.getPropertyValues(), persister.getPropertyTypes() );
boolean hasDirtyCollections = visitor.wasDirtyCollectionFound(); final boolean hasDirtyCollections = visitor.wasDirtyCollectionFound();
event.setHasDirtyCollection( hasDirtyCollections ); event.setHasDirtyCollection( hasDirtyCollections );
return hasDirtyCollections; return hasDirtyCollections;
} }
@ -482,7 +481,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
private static int[] performDirtyCheck(FlushEntityEvent event) { private static int[] performDirtyCheck(FlushEntityEvent event) {
final SessionImplementor session = event.getSession(); final SessionImplementor session = event.getSession();
boolean dirtyCheckPossible; final boolean dirtyCheckPossible;
int[] dirtyProperties = null; int[] dirtyProperties = null;
final EventManager eventManager = session.getEventManager(); final EventManager eventManager = session.getEventManager();
final HibernateMonitoringEvent dirtyCalculationEvent = eventManager.beginDirtyCalculationEvent(); final HibernateMonitoringEvent dirtyCalculationEvent = eventManager.beginDirtyCalculationEvent();
@ -547,16 +546,15 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
* the bytecode enhancement, or a custom dirtiness strategy. * the bytecode enhancement, or a custom dirtiness strategy.
*/ */
private static int[] getDirtyProperties(FlushEntityEvent event) { private static int[] getDirtyProperties(FlushEntityEvent event) {
int[] dirtyProperties = getDirtyPropertiesFromInterceptor( event ); final int[] dirtyProperties = getDirtyPropertiesFromInterceptor( event );
if ( dirtyProperties != null ) { if ( dirtyProperties != null ) {
return dirtyProperties; return dirtyProperties;
} }
else { else {
final Object entity = event.getEntity(); final Object entity = event.getEntity();
if ( isSelfDirtinessTracker( entity ) && asManagedEntity( entity ).$$_hibernate_useTracker() ) { return isSelfDirtinessTracker( entity ) && asManagedEntity( entity ).$$_hibernate_useTracker()
return getDirtyPropertiesFromSelfDirtinessTracker( asSelfDirtinessTracker( entity ), event ); ? getDirtyPropertiesFromSelfDirtinessTracker( asSelfDirtinessTracker( entity ), event )
} : getDirtyPropertiesFromCustomEntityDirtinessStrategy( event );
return getDirtyPropertiesFromCustomEntityDirtinessStrategy( event );
} }
} }
@ -685,7 +683,7 @@ public class DefaultFlushEntityEventListener implements FlushEntityEventListener
} }
LOG.tracev( LOG.tracev(
"Found dirty properties [{0}] : {1}", "Found dirty properties [{0}] : {1}",
MessageHelper.infoString( persister.getEntityName(), entry.getId() ), infoString( persister.getEntityName(), entry.getId() ),
Arrays.toString( dirtyPropertyNames ) Arrays.toString( dirtyPropertyNames )
); );
} }