HHH-15803 Have the default EmptyInterceptor avoid triggering type pollution

This commit is contained in:
Sanne Grinovero 2022-12-02 21:17:16 +00:00 committed by Sanne Grinovero
parent 721b66c6d3
commit c114d08ac2
7 changed files with 76 additions and 9 deletions

View File

@ -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() {}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
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;
}
}

View File

@ -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;