Skip to content

Commit

Permalink
finally kill of Lifecycle after all these years
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinking committed Dec 12, 2024
1 parent 98f06d4 commit d311440
Show file tree
Hide file tree
Showing 20 changed files with 32 additions and 448 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
package org.hibernate;

/**
* Intended to be thrown from {@link org.hibernate.classic.Lifecycle}
* and {@link Interceptor} callbacks.
* Intended to be thrown from {@link Interceptor} callbacks.
*
* @implNote This is a legacy exception type from back in the day before
* Hibernate moved to an unchecked exception strategy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
*
* @author Gavin King
*/
@SuppressWarnings("unused")
public interface Interceptor {
/**
* Called just before an object is initialized. The interceptor may change the {@code state}, which will
Expand Down
125 changes: 0 additions & 125 deletions hibernate-core/src/main/java/org/hibernate/classic/Lifecycle.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.hibernate.action.internal.AbstractEntityInsertAction;
import org.hibernate.action.internal.EntityIdentityInsertAction;
import org.hibernate.action.internal.EntityInsertAction;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.spi.CascadingAction;
Expand Down Expand Up @@ -215,12 +214,7 @@ protected Object performSave(
}

final EntityKey key = useIdentityColumn ? null : entityKey( id, persister, source );
if ( invokeSaveLifecycle( entity, persister, source ) ) {
return id;
}
else {
return performSaveOrReplicate( entity, key, persister, useIdentityColumn, context, source, delayIdentityInserts );
}
return performSaveOrReplicate( entity, key, persister, useIdentityColumn, context, source, delayIdentityInserts );
}

private static EntityKey entityKey(Object id, EntityPersister persister, EventSource source) {
Expand All @@ -241,19 +235,6 @@ else if ( persistenceContext.containsDeletedUnloadedEntityKey( key ) ) {
return key;
}

protected boolean invokeSaveLifecycle(Object entity, EntityPersister persister, EventSource source) {
// Sub-insertions should occur before containing insertion so
// Try to do the callback now
if ( persister.implementsLifecycle() ) {
LOG.debug( "Calling onSave()" );
if ( ((Lifecycle) entity).onSave( source ) ) {
LOG.debug( "Insertion vetoed by onSave()" );
return true;
}
}
return false;
}

/**
* Performs all the actual work needed to save an entity (well to get the save moved to
* the execution queue).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import org.hibernate.action.internal.OrphanRemovalAction;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.bytecode.spi.BytecodeEnhancementMetadata;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.internal.Cascade;
import org.hibernate.engine.internal.CascadePoint;
import org.hibernate.engine.internal.ForeignKeys;
Expand Down Expand Up @@ -271,20 +270,18 @@ private void delete(
Object id,
Object version,
EntityEntry entityEntry) {
callbackRegistry.preRemove(entity);
if ( !invokeDeleteLifecycle( source, entity, persister ) ) {
deleteEntity(
source,
entity,
entityEntry,
event.isCascadeDeleteEnabled(),
event.isOrphanRemovalBeforeUpdates(),
persister,
transientEntities
);
if ( source.getFactory().getSessionFactoryOptions().isIdentifierRollbackEnabled() ) {
persister.resetIdentifier( entity, id, version, source );
}
callbackRegistry.preRemove( entity );
deleteEntity(
source,
entity,
entityEntry,
event.isCascadeDeleteEnabled(),
event.isOrphanRemovalBeforeUpdates(),
persister,
transientEntities
);
if ( source.getFactory().getSessionFactoryOptions().isIdentifierRollbackEnabled() ) {
persister.resetIdentifier( entity, id, version, source );
}
}

Expand All @@ -293,7 +290,6 @@ private void delete(
*/
private boolean canBeDeletedWithoutLoading(EventSource source, EntityPersister persister) {
return source.getInterceptor() == EmptyInterceptor.INSTANCE
&& !persister.implementsLifecycle()
&& !persister.hasSubclasses() //TODO: should be unnecessary, using EntityPersister.getSubclassPropertyTypeClosure(), etc
&& !persister.hasCascadeDelete()
&& !persister.hasNaturalIdentifier()
Expand Down Expand Up @@ -488,17 +484,6 @@ else if ( currentState[i] == LazyPropertyInitializer.UNFETCHED_PROPERTY
return deletedState;
}

protected boolean invokeDeleteLifecycle(EventSource session, Object entity, EntityPersister persister) {
if ( persister.implementsLifecycle() ) {
LOG.debug( "Calling onDelete()" );
if ( ( (Lifecycle) entity ).onDelete( session ) ) {
LOG.debug( "Deletion vetoed by onDelete()" );
return true;
}
}
return false;
}

protected void cascadeBeforeDelete(
EventSource session,
EntityPersister persister,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.hibernate.LockMode;
import org.hibernate.action.internal.EntityIncrementVersionProcess;
import org.hibernate.action.internal.EntityVerifyVersionProcess;
import org.hibernate.classic.Lifecycle;
import org.hibernate.engine.spi.EntityEntry;
import org.hibernate.event.spi.EventSource;
import org.hibernate.event.spi.PostLoadEvent;
Expand All @@ -20,11 +19,7 @@
import org.hibernate.persister.entity.EntityPersister;

/**
* We do two things here:
* <ul>
* <li>Call {@link Lifecycle} interface if necessary</li>
* <li>Perform needed {@link EntityEntry#getLockMode()} related processing</li>
* </ul>
* Performs needed {@link EntityEntry#getLockMode()}-related processing.
*
* @author Gavin King
* @author Steve Ebersole
Expand Down Expand Up @@ -72,13 +67,5 @@ public void onPostLoad(PostLoadEvent event) {
+ "] not supported for non-versioned entities [" + persister.getEntityName() + "]");
}
}

invokeLoadLifecycle( event, session );
}

protected void invokeLoadLifecycle(PostLoadEvent event, EventSource session) {
if ( event.getPersister().implementsLifecycle() ) {
( (Lifecycle) event.getEntity() ).onLoad( session, event.getId() );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.bytecode.spi.ReflectionOptimizer;
import org.hibernate.bytecode.spi.ReflectionOptimizer.InstantiationOptimizer;
import org.hibernate.classic.Lifecycle;
import org.hibernate.internal.CoreLogging;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ReflectHelper;
Expand Down Expand Up @@ -59,7 +58,6 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
private final JavaType<?> proxyJtd;

private final boolean isBytecodeEnhanced;
private final boolean lifecycleImplementor;

private final ReflectionOptimizer reflectionOptimizer;
private final ProxyFactory proxyFactory;
Expand Down Expand Up @@ -89,7 +87,6 @@ public EntityRepresentationStrategyPojoStandard(
this.proxyJtd = null;
}

this.lifecycleImplementor = Lifecycle.class.isAssignableFrom( mappedJavaType );
this.isBytecodeEnhanced = isPersistentAttributeInterceptableType( mappedJavaType );

final Property identifierProperty = bootDescriptor.getIdentifierProperty();
Expand Down Expand Up @@ -389,11 +386,6 @@ public ProxyFactory getProxyFactory() {
return proxyFactory;
}

@Override
public boolean isLifecycleImplementor() {
return lifecycleImplementor;
}

@Override
public boolean isBytecodeEnhanced() {
return isBytecodeEnhanced;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ public interface EntityRepresentationStrategy extends ManagedTypeRepresentationS
*/
ProxyFactory getProxyFactory();

default boolean isLifecycleImplementor() {
return false;
}

default boolean isBytecodeEnhanced() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.hibernate.cache.spi.entry.StandardCacheEntryImpl;
import org.hibernate.cache.spi.entry.StructuredCacheEntry;
import org.hibernate.cache.spi.entry.UnstructuredCacheEntry;
import org.hibernate.classic.Lifecycle;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.lock.LockingStrategy;
Expand Down Expand Up @@ -464,8 +463,6 @@ public abstract class AbstractEntityPersister
*/
private final EntityPropertyMapping propertyMapping;

private final boolean implementsLifecycle;

private List<UniqueKeyEntry> uniqueKeyEntries = null; //lazily initialized
private ConcurrentHashMap<String,SingleIdArrayLoadPlan> nonLazyPropertyLoadPlansByName;

Expand Down Expand Up @@ -523,7 +520,6 @@ public AbstractEntityPersister(

javaType = representationStrategy.getLoadJavaType();
assert javaType != null;
this.implementsLifecycle = Lifecycle.class.isAssignableFrom( javaType.getJavaTypeClass() );

concreteProxy = entityMetamodel.isPolymorphic()
&& ( getBytecodeEnhancementMetadata().isEnhancedForLazyLoading() || hasProxy() )
Expand Down Expand Up @@ -4181,11 +4177,6 @@ public final Class<?> getMappedClass() {
return this.getMappedJavaType().getJavaTypeClass();
}

@Override
public boolean implementsLifecycle() {
return this.implementsLifecycle;
}

@Override
public Class<?> getConcreteProxyClass() {
final JavaType<?> proxyJavaType = getRepresentationStrategy().getProxyJavaType();
Expand Down
Loading

0 comments on commit d311440

Please sign in to comment.