From 37644a42a8b8ea338b5fc1ea1b5f39214e89ac91 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Wed, 31 Jul 2024 14:25:19 +0200 Subject: [PATCH] HHH-18452 Remove deprecated org.hibernate.Interceptor methods --- .../main/java/org/hibernate/Interceptor.java | 218 ------------------ .../caching/mocked/ReadWriteCacheTest.java | 4 +- .../CustomDirtinessStrategyTest.java | 4 +- .../interceptor/CollectionInterceptor.java | 7 +- .../interceptor/InstantiateInterceptor.java | 4 +- .../InterceptorNonNullTransactionTest.java | 4 +- .../orm/test/interceptor/InterceptorTest.java | 8 +- .../InterceptorTransactionEventTest.java | 3 +- .../test/interceptor/PropertyInterceptor.java | 8 +- .../test/interceptor/StatefulInterceptor.java | 8 +- .../interfaceproxy/DocumentInterceptor.java | 75 ++---- ...PreUpdateDirtyCheckingInterceptorTest.java | 8 +- .../ExceptionInterceptor.java | 8 +- .../orm/test/mixed/DocumentInterceptor.java | 89 ++----- .../orm/test/querycache/QueryCacheTest.java | 14 +- .../test/tm/InterceptorTransactionTest.java | 4 +- .../test/integration/tm/TestInterceptor.java | 5 +- migration-guide.adoc | 10 +- 18 files changed, 78 insertions(+), 403 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/Interceptor.java b/hibernate-core/src/main/java/org/hibernate/Interceptor.java index 2c4d1ba77a..08808c6e45 100644 --- a/hibernate-core/src/main/java/org/hibernate/Interceptor.java +++ b/hibernate-core/src/main/java/org/hibernate/Interceptor.java @@ -6,7 +6,6 @@ */ package org.hibernate; -import java.io.Serializable; import java.util.Iterator; import org.hibernate.metamodel.RepresentationMode; @@ -77,34 +76,6 @@ public interface Interceptor { */ default boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException { - if (id==null || id instanceof Serializable) { - return onLoad(entity, (Serializable) id, state, propertyNames, types); - } - return false; - } - - /** - * Called just before an object is initialized. The interceptor may change the {@code state}, which will - * be propagated to the persistent object. Note that when this method is called, {@code entity} will be - * an empty uninitialized instance of the class. - * - * @apiNote The indexes across the {@code state}, {@code propertyNames}, and {@code types} arrays match. - * - * @param entity The entity instance being loaded - * @param id The identifier value being loaded - * @param state The entity state (which will be pushed into the entity instance) - * @param propertyNames The names of the entity properties, corresponding to the {@code state}. - * @param types The types of the entity properties, corresponding to the {@code state}. - * - * @return {@code true} if the user modified the {@code state} in any way. - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onLoad(Object, Object, Object[], String[], Type[])} - */ - @Deprecated(since = "6.0") - default boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) - throws CallbackException { return false; } @@ -182,67 +153,6 @@ public interface Interceptor { Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException { - if (id==null || id instanceof Serializable) { - return onFlushDirty(entity, (Serializable) id, currentState, previousState, propertyNames, types); - } - return false; - } - - /** - * Called when an object is detected to be dirty, during a flush. The interceptor may modify the detected - * {@code currentState}, which will be propagated to both the database and the persistent object. - * Note that not all flushes end in actual synchronization with the database, in which case the - * new {@code currentState} will be propagated to the object, but not necessarily (immediately) to - * the database. It is strongly recommended that the interceptor not modify the {@code previousState}. - * - * @apiNote The indexes across the {@code currentState}, {@code previousState}, {@code propertyNames}, and - * {@code types} arrays match. - * - * @param entity The entity instance detected as being dirty and being flushed - * @param id The identifier of the entity - * @param currentState The entity's current state - * @param previousState The entity's previous (load time) state. - * @param propertyNames The names of the entity properties - * @param types The types of the entity properties - * - * @return {@code true} if the user modified the {@code currentState} in any way. - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onFlushDirty(Object, Object, Object[], Object[], String[], Type[])} - */ - @Deprecated(since = "6.0") - default boolean onFlushDirty( - Object entity, - Serializable id, - Object[] currentState, - Object[] previousState, - String[] propertyNames, - Type[] types) throws CallbackException { - return false; - } - - /** - * Called before an object is made persistent by a stateful session. - *

- * The interceptor may modify the {@code state}, which will be used for - * the SQL {@code INSERT} and propagated to the persistent object. - * - * @param entity The entity instance whose state is being inserted - * @param id The identifier of the entity - * @param state The state of the entity which will be inserted - * @param propertyNames The names of the entity properties. - * @param types The types of the entity properties - * - * @return {@code true} if the user modified the {@code state} in any way. - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onSave(Object, Object, Object[], String[], Type[])} - */ - @Deprecated(since = "6.0") - default boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) - throws CallbackException { return false; } @@ -270,31 +180,9 @@ public interface Interceptor { @Deprecated(since = "6.6") default boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException { - if (id==null || id instanceof Serializable) { - return onSave(entity, (Serializable) id, state, propertyNames, types); - } return false; } - /** - * Called before an object is removed by a stateful session. - *

- * It is not recommended that the interceptor modify the {@code state}. - * - * @param entity The entity instance being deleted - * @param id The identifier of the entity - * @param state The state of the entity - * @param propertyNames The names of the entity properties. - * @param types The types of the entity properties - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onDelete(Object, Object, Object[], String[], Type[])} - */ - @Deprecated(since = "6.0") - default void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) - throws CallbackException {} - /** * Called before an object is removed by a stateful session. *

@@ -315,24 +203,8 @@ public interface Interceptor { @Deprecated(since = "6.6") default void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException { - if (id==null || id instanceof Serializable) { - onDelete(entity, (Serializable) id, state, propertyNames, types); - } } - /** - * Called before a collection is (re)created. - * - * @param collection The collection instance. - * @param key The collection key value. - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onCollectionRecreate(Object, Object)} - */ - @Deprecated(since = "6.0") - default void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {} - /** * Called before a collection is (re)created. * @@ -342,24 +214,8 @@ public interface Interceptor { * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. */ default void onCollectionRecreate(Object collection, Object key) throws CallbackException { - if (key instanceof Serializable) { - onCollectionRecreate(collection, (Serializable) key); - } } - /** - * Called before a collection is deleted. - * - * @param collection The collection instance. - * @param key The collection key value. - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onCollectionRemove(Object, Object)} - */ - @Deprecated(since = "6.0") - default void onCollectionRemove(Object collection, Serializable key) throws CallbackException {} - /** * Called before a collection is deleted. * @@ -369,24 +225,8 @@ public interface Interceptor { * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. */ default void onCollectionRemove(Object collection, Object key) throws CallbackException { - if (key instanceof Serializable) { - onCollectionRemove(collection, (Serializable) key); - } } - /** - * Called before a collection is updated. - * - * @param collection The collection instance. - * @param key The collection key value. - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #onCollectionUpdate(Object, Object)} - */ - @Deprecated(since = "6.0") - default void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {} - /** * Called before a collection is updated. * @@ -396,9 +236,6 @@ public interface Interceptor { * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. */ default void onCollectionUpdate(Object collection, Object key) throws CallbackException { - if (key instanceof Serializable) { - onCollectionUpdate(collection, (Serializable) key); - } } /** * Called before a flush. @@ -436,38 +273,6 @@ public interface Interceptor { return null; } - /** - * Called from {@code flush()}. The return value determines whether the entity is updated - *

- * - * @param entity The entity for which to find dirty properties. - * @param id The identifier of the entity - * @param currentState The current entity state as taken from the entity instance - * @param previousState The state of the entity when it was last synchronized (generally when it was loaded) - * @param propertyNames The names of the entity properties. - * @param types The types of the entity properties - * - * @return array of dirty property indices or {@code null} to indicate Hibernate should perform default behaviour - * - * @throws CallbackException Thrown if the interceptor encounters any problems handling the callback. - * - * @deprecated use {@link #findDirty(Object, Object, Object[], Object[], String[], Type[])} - */ - @Deprecated(since = "6.0") - default int[] findDirty( - Object entity, - Serializable id, - Object[] currentState, - Object[] previousState, - String[] propertyNames, - Type[] types) { - return null; - } - /** * Called from {@code flush()}. The return value determines whether the entity is updated *