From c114d08ac23e095452b2d47a1473aec8c1935b7f Mon Sep 17 00:00:00 2001 From: Sanne Grinovero Date: Fri, 2 Dec 2022 21:17:16 +0000 Subject: [PATCH] HHH-15803 Have the default EmptyInterceptor avoid triggering type pollution --- .../java/org/hibernate/EmptyInterceptor.java | 5 +- .../SessionFactoryOptionsBuilder.java | 2 +- .../java/org/hibernate/cfg/Configuration.java | 2 +- .../internal/DefaultDeleteEventListener.java | 2 +- .../AbstractSharedSessionContract.java | 1 - .../hibernate/internal/EmptyInterceptor.java | 72 +++++++++++++++++++ .../internal/SessionFactoryImpl.java | 1 - 7 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/internal/EmptyInterceptor.java diff --git a/hibernate-core/src/main/java/org/hibernate/EmptyInterceptor.java b/hibernate-core/src/main/java/org/hibernate/EmptyInterceptor.java index c9caf19b6e..170437123b 100644 --- a/hibernate-core/src/main/java/org/hibernate/EmptyInterceptor.java +++ b/hibernate-core/src/main/java/org/hibernate/EmptyInterceptor.java @@ -20,10 +20,7 @@ import org.hibernate.type.Type; */ @Deprecated(since = "6.0") public class EmptyInterceptor implements Interceptor, Serializable { - /** - * The singleton reference. - */ - public static final Interceptor INSTANCE = new EmptyInterceptor(); protected EmptyInterceptor() {} + } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java index 602fc672fd..155f64a14c 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java @@ -18,7 +18,6 @@ import java.util.concurrent.Callable; import java.util.function.Supplier; import org.hibernate.CustomEntityDirtinessStrategy; -import org.hibernate.EmptyInterceptor; import org.hibernate.EntityNameResolver; import org.hibernate.HibernateException; import org.hibernate.Interceptor; @@ -48,6 +47,7 @@ import org.hibernate.engine.jdbc.env.spi.ExtractedDatabaseMetaData; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.id.uuid.LocalObjectUuidHelper; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.EmptyInterceptor; import org.hibernate.internal.util.NullnessHelper; import org.hibernate.internal.util.PropertiesHelper; import org.hibernate.internal.util.StringHelper; diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index e6a08dedce..efbcd343f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -16,7 +16,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.hibernate.EmptyInterceptor; import org.hibernate.EntityNameResolver; import org.hibernate.HibernateException; import org.hibernate.Interceptor; @@ -51,6 +50,7 @@ import org.hibernate.cfg.annotations.NamedEntityGraphDefinition; import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.EmptyInterceptor; import org.hibernate.proxy.EntityNotFoundDelegate; import org.hibernate.query.sqm.function.SqmFunctionDescriptor; import org.hibernate.service.ServiceRegistry; diff --git a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java index b652875a92..4ce54a133b 100644 --- a/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/event/internal/DefaultDeleteEventListener.java @@ -7,7 +7,6 @@ package org.hibernate.event.internal; import org.hibernate.CacheMode; -import org.hibernate.EmptyInterceptor; import org.hibernate.HibernateException; import org.hibernate.LockMode; import org.hibernate.TransientObjectException; @@ -35,6 +34,7 @@ import org.hibernate.event.spi.DeleteEventListener; import org.hibernate.event.spi.EventSource; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.internal.EmptyInterceptor; import org.hibernate.internal.FastSessionServices; import org.hibernate.jpa.event.spi.CallbackRegistry; import org.hibernate.jpa.event.spi.CallbackRegistryConsumer; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 0555691d1d..a7b966bb5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -17,7 +17,6 @@ import java.util.UUID; import java.util.function.Function; import org.hibernate.CacheMode; -import org.hibernate.EmptyInterceptor; import org.hibernate.EntityNameResolver; import org.hibernate.FlushMode; import org.hibernate.HibernateException; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/EmptyInterceptor.java b/hibernate-core/src/main/java/org/hibernate/internal/EmptyInterceptor.java new file mode 100644 index 0000000000..b1cfebd17a --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/internal/EmptyInterceptor.java @@ -0,0 +1,72 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * License: GNU Lesser General Public License (LGPL), version 2.1 or later. + * See the lgpl.txt file in the root directory or . + */ +package org.hibernate.internal; + +import java.io.Serializable; + +import org.hibernate.Interceptor; +import org.hibernate.type.Type; + +/** + * An interceptor that does nothing. + * This is an internal class and should not be used as a base to implement a custom Interceptor; + * it is similar to the public, deprecated {@link org.hibernate.EmptyInterceptor} but overrides + * the default methods for sake of efficiency: this wasn't possible on the original deprecated + * copy as that wouldn't have been backwards compatible. For this reason this copy is internal. + * + * Implementors of Interceptor don't need a base class anymore since we now have default + * implementations of the contract defined in the interface. + */ +public final class EmptyInterceptor implements Interceptor, Serializable { + + public static final Interceptor INSTANCE = new EmptyInterceptor(); + + private EmptyInterceptor() { + } + + @Override + public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) { + return false; + } + + @Override + public boolean onFlushDirty( + Object entity, + Object id, + Object[] currentState, + Object[] previousState, + String[] propertyNames, + Type[] types) { + return false; + } + + @Override + public boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) { + return false; + } + + @Override + public void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) { + } + + @Override + public int[] findDirty( + Object entity, + Object id, + Object[] currentState, + Object[] previousState, + String[] propertyNames, + Type[] types) { + return null; + } + + @Override + public Object getEntity(String entityName, Object id) { + return null; + } + +} diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java index c13e485587..95dc6efdc3 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java @@ -34,7 +34,6 @@ import jakarta.persistence.Query; import jakarta.persistence.SynchronizationType; import org.hibernate.CustomEntityDirtinessStrategy; -import org.hibernate.EmptyInterceptor; import org.hibernate.EntityNameResolver; import org.hibernate.FlushMode; import org.hibernate.HibernateException;