Skip to content

Commit 37644a4

Browse files
dreab8sebersole
authored andcommitted
HHH-18452 Remove deprecated org.hibernate.Interceptor methods
1 parent e3fd3fa commit 37644a4

File tree

18 files changed

+78
-403
lines changed

18 files changed

+78
-403
lines changed

hibernate-core/src/main/java/org/hibernate/Interceptor.java

Lines changed: 0 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
package org.hibernate;
88

9-
import java.io.Serializable;
109
import java.util.Iterator;
1110

1211
import org.hibernate.metamodel.RepresentationMode;
@@ -77,34 +76,6 @@ public interface Interceptor {
7776
*/
7877
default boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
7978
throws CallbackException {
80-
if (id==null || id instanceof Serializable) {
81-
return onLoad(entity, (Serializable) id, state, propertyNames, types);
82-
}
83-
return false;
84-
}
85-
86-
/**
87-
* Called just before an object is initialized. The interceptor may change the {@code state}, which will
88-
* be propagated to the persistent object. Note that when this method is called, {@code entity} will be
89-
* an empty uninitialized instance of the class.
90-
*
91-
* @apiNote The indexes across the {@code state}, {@code propertyNames}, and {@code types} arrays match.
92-
*
93-
* @param entity The entity instance being loaded
94-
* @param id The identifier value being loaded
95-
* @param state The entity state (which will be pushed into the entity instance)
96-
* @param propertyNames The names of the entity properties, corresponding to the {@code state}.
97-
* @param types The types of the entity properties, corresponding to the {@code state}.
98-
*
99-
* @return {@code true} if the user modified the {@code state} in any way.
100-
*
101-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
102-
*
103-
* @deprecated use {@link #onLoad(Object, Object, Object[], String[], Type[])}
104-
*/
105-
@Deprecated(since = "6.0")
106-
default boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
107-
throws CallbackException {
10879
return false;
10980
}
11081

@@ -182,67 +153,6 @@ default boolean onFlushDirty(
182153
Object[] previousState,
183154
String[] propertyNames,
184155
Type[] types) throws CallbackException {
185-
if (id==null || id instanceof Serializable) {
186-
return onFlushDirty(entity, (Serializable) id, currentState, previousState, propertyNames, types);
187-
}
188-
return false;
189-
}
190-
191-
/**
192-
* Called when an object is detected to be dirty, during a flush. The interceptor may modify the detected
193-
* {@code currentState}, which will be propagated to both the database and the persistent object.
194-
* Note that not all flushes end in actual synchronization with the database, in which case the
195-
* new {@code currentState} will be propagated to the object, but not necessarily (immediately) to
196-
* the database. It is strongly recommended that the interceptor <b>not</b> modify the {@code previousState}.
197-
*
198-
* @apiNote The indexes across the {@code currentState}, {@code previousState}, {@code propertyNames}, and
199-
* {@code types} arrays match.
200-
*
201-
* @param entity The entity instance detected as being dirty and being flushed
202-
* @param id The identifier of the entity
203-
* @param currentState The entity's current state
204-
* @param previousState The entity's previous (load time) state.
205-
* @param propertyNames The names of the entity properties
206-
* @param types The types of the entity properties
207-
*
208-
* @return {@code true} if the user modified the {@code currentState} in any way.
209-
*
210-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
211-
*
212-
* @deprecated use {@link #onFlushDirty(Object, Object, Object[], Object[], String[], Type[])}
213-
*/
214-
@Deprecated(since = "6.0")
215-
default boolean onFlushDirty(
216-
Object entity,
217-
Serializable id,
218-
Object[] currentState,
219-
Object[] previousState,
220-
String[] propertyNames,
221-
Type[] types) throws CallbackException {
222-
return false;
223-
}
224-
225-
/**
226-
* Called before an object is made persistent by a stateful session.
227-
* <p>
228-
* The interceptor may modify the {@code state}, which will be used for
229-
* the SQL {@code INSERT} and propagated to the persistent object.
230-
*
231-
* @param entity The entity instance whose state is being inserted
232-
* @param id The identifier of the entity
233-
* @param state The state of the entity which will be inserted
234-
* @param propertyNames The names of the entity properties.
235-
* @param types The types of the entity properties
236-
*
237-
* @return {@code true} if the user modified the {@code state} in any way.
238-
*
239-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
240-
*
241-
* @deprecated use {@link #onSave(Object, Object, Object[], String[], Type[])}
242-
*/
243-
@Deprecated(since = "6.0")
244-
default boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
245-
throws CallbackException {
246156
return false;
247157
}
248158

@@ -270,31 +180,9 @@ default boolean onSave(Object entity, Serializable id, Object[] state, String[]
270180
@Deprecated(since = "6.6")
271181
default boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
272182
throws CallbackException {
273-
if (id==null || id instanceof Serializable) {
274-
return onSave(entity, (Serializable) id, state, propertyNames, types);
275-
}
276183
return false;
277184
}
278185

279-
/**
280-
* Called before an object is removed by a stateful session.
281-
* <p>
282-
* It is not recommended that the interceptor modify the {@code state}.
283-
*
284-
* @param entity The entity instance being deleted
285-
* @param id The identifier of the entity
286-
* @param state The state of the entity
287-
* @param propertyNames The names of the entity properties.
288-
* @param types The types of the entity properties
289-
*
290-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
291-
*
292-
* @deprecated use {@link #onDelete(Object, Object, Object[], String[], Type[])}
293-
*/
294-
@Deprecated(since = "6.0")
295-
default void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
296-
throws CallbackException {}
297-
298186
/**
299187
* Called before an object is removed by a stateful session.
300188
* <p>
@@ -315,24 +203,8 @@ default void onDelete(Object entity, Serializable id, Object[] state, String[] p
315203
@Deprecated(since = "6.6")
316204
default void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types)
317205
throws CallbackException {
318-
if (id==null || id instanceof Serializable) {
319-
onDelete(entity, (Serializable) id, state, propertyNames, types);
320-
}
321206
}
322207

323-
/**
324-
* Called before a collection is (re)created.
325-
*
326-
* @param collection The collection instance.
327-
* @param key The collection key value.
328-
*
329-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
330-
*
331-
* @deprecated use {@link #onCollectionRecreate(Object, Object)}
332-
*/
333-
@Deprecated(since = "6.0")
334-
default void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {}
335-
336208
/**
337209
* Called before a collection is (re)created.
338210
*
@@ -342,24 +214,8 @@ default void onCollectionRecreate(Object collection, Serializable key) throws Ca
342214
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
343215
*/
344216
default void onCollectionRecreate(Object collection, Object key) throws CallbackException {
345-
if (key instanceof Serializable) {
346-
onCollectionRecreate(collection, (Serializable) key);
347-
}
348217
}
349218

350-
/**
351-
* Called before a collection is deleted.
352-
*
353-
* @param collection The collection instance.
354-
* @param key The collection key value.
355-
*
356-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
357-
*
358-
* @deprecated use {@link #onCollectionRemove(Object, Object)}
359-
*/
360-
@Deprecated(since = "6.0")
361-
default void onCollectionRemove(Object collection, Serializable key) throws CallbackException {}
362-
363219
/**
364220
* Called before a collection is deleted.
365221
*
@@ -369,24 +225,8 @@ default void onCollectionRemove(Object collection, Serializable key) throws Call
369225
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
370226
*/
371227
default void onCollectionRemove(Object collection, Object key) throws CallbackException {
372-
if (key instanceof Serializable) {
373-
onCollectionRemove(collection, (Serializable) key);
374-
}
375228
}
376229

377-
/**
378-
* Called before a collection is updated.
379-
*
380-
* @param collection The collection instance.
381-
* @param key The collection key value.
382-
*
383-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
384-
*
385-
* @deprecated use {@link #onCollectionUpdate(Object, Object)}
386-
*/
387-
@Deprecated(since = "6.0")
388-
default void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {}
389-
390230
/**
391231
* Called before a collection is updated.
392232
*
@@ -396,9 +236,6 @@ default void onCollectionUpdate(Object collection, Serializable key) throws Call
396236
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
397237
*/
398238
default void onCollectionUpdate(Object collection, Object key) throws CallbackException {
399-
if (key instanceof Serializable) {
400-
onCollectionUpdate(collection, (Serializable) key);
401-
}
402239
}
403240
/**
404241
* Called before a flush.
@@ -436,38 +273,6 @@ default Boolean isTransient(Object entity) {
436273
return null;
437274
}
438275

439-
/**
440-
* Called from {@code flush()}. The return value determines whether the entity is updated
441-
* <ul>
442-
* <li>an array of property indices - the entity is dirty
443-
* <li>an empty array - the entity is not dirty
444-
* <li>{@code null} - use Hibernate's default dirty-checking algorithm
445-
* </ul>
446-
*
447-
* @param entity The entity for which to find dirty properties.
448-
* @param id The identifier of the entity
449-
* @param currentState The current entity state as taken from the entity instance
450-
* @param previousState The state of the entity when it was last synchronized (generally when it was loaded)
451-
* @param propertyNames The names of the entity properties.
452-
* @param types The types of the entity properties
453-
*
454-
* @return array of dirty property indices or {@code null} to indicate Hibernate should perform default behaviour
455-
*
456-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
457-
*
458-
* @deprecated use {@link #findDirty(Object, Object, Object[], Object[], String[], Type[])}
459-
*/
460-
@Deprecated(since = "6.0")
461-
default int[] findDirty(
462-
Object entity,
463-
Serializable id,
464-
Object[] currentState,
465-
Object[] previousState,
466-
String[] propertyNames,
467-
Type[] types) {
468-
return null;
469-
}
470-
471276
/**
472277
* Called from {@code flush()}. The return value determines whether the entity is updated
473278
* <ul>
@@ -494,9 +299,6 @@ default int[] findDirty(
494299
Object[] previousState,
495300
String[] propertyNames,
496301
Type[] types) {
497-
if (id==null || id instanceof Serializable) {
498-
return findDirty(entity, (Serializable) id, currentState, previousState, propertyNames, types);
499-
}
500302
return null;
501303
}
502304

@@ -539,23 +341,6 @@ default String getEntityName(Object object) throws CallbackException {
539341
return null;
540342
}
541343

542-
/**
543-
* Get a fully loaded entity instance that is cached externally.
544-
*
545-
* @param entityName the name of the entity
546-
* @param id the instance identifier
547-
*
548-
* @return a fully initialized entity
549-
*
550-
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
551-
*
552-
* @deprecated use {@link #getEntity(String, Object)}
553-
*/
554-
@Deprecated(since = "6.0")
555-
default Object getEntity(String entityName, Serializable id) throws CallbackException {
556-
return null;
557-
}
558-
559344
/**
560345
* Get a fully loaded entity instance that is cached externally.
561346
*
@@ -567,9 +352,6 @@ default Object getEntity(String entityName, Serializable id) throws CallbackExce
567352
* @throws CallbackException Thrown if the interceptor encounters any problems handling the callback.
568353
*/
569354
default Object getEntity(String entityName, Object id) throws CallbackException {
570-
if (id==null || id instanceof Serializable) {
571-
return getEntity(entityName, (Serializable) id);
572-
}
573355
return null;
574356
}
575357

hibernate-core/src/test/java/org/hibernate/orm/test/caching/mocked/ReadWriteCacheTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import jakarta.persistence.Entity;
1414
import jakarta.persistence.Id;
1515

16-
import org.hibernate.EmptyInterceptor;
16+
import org.hibernate.Interceptor;
1717
import org.hibernate.Session;
1818
import org.hibernate.Transaction;
1919
import org.hibernate.annotations.CacheConcurrencyStrategy;
@@ -296,7 +296,7 @@ public String toString() {
296296
}
297297
}
298298

299-
private final class TransactionInterceptor extends EmptyInterceptor {
299+
private final class TransactionInterceptor implements Interceptor {
300300
@Override
301301
public void beforeTransactionCompletion(Transaction tx) {
302302
if ( interceptTransaction.get() ) {

hibernate-core/src/test/java/org/hibernate/orm/test/dirtiness/CustomDirtinessStrategyTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
*/
77
package org.hibernate.orm.test.dirtiness;
88

9-
import java.io.Serializable;
10-
119
import org.hibernate.CustomEntityDirtinessStrategy;
1210
import org.hibernate.Interceptor;
1311
import org.hibernate.Session;
@@ -203,7 +201,7 @@ public static class OnFlushDirtyInterceptor implements Interceptor {
203201
@Override
204202
public boolean onFlushDirty(
205203
Object entity,
206-
Serializable id,
204+
Object id,
207205
Object[] currentState,
208206
Object[] previousState,
209207
String[] propertyNames,

hibernate-core/src/test/java/org/hibernate/orm/test/interceptor/CollectionInterceptor.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
//$Id: CollectionInterceptor.java 7700 2005-07-30 05:02:47Z oneovthafew $
99
package org.hibernate.orm.test.interceptor;
10-
import java.io.Serializable;
1110

12-
import org.hibernate.EmptyInterceptor;
11+
import org.hibernate.Interceptor;
1312
import org.hibernate.type.Type;
1413

15-
public class CollectionInterceptor extends EmptyInterceptor {
14+
public class CollectionInterceptor implements Interceptor {
1615

17-
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
16+
public boolean onFlushDirty(Object entity, Object id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
1817
( (User) entity ).getActions().add("updated");
1918
return false;
2019
}

hibernate-core/src/test/java/org/hibernate/orm/test/interceptor/InstantiateInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
package org.hibernate.orm.test.interceptor;
1212

1313
import org.hibernate.CallbackException;
14-
import org.hibernate.EmptyInterceptor;
14+
import org.hibernate.Interceptor;
1515
import org.hibernate.metamodel.RepresentationMode;
1616

17-
public class InstantiateInterceptor extends EmptyInterceptor {
17+
public class InstantiateInterceptor implements Interceptor {
1818
private String injectedString;
1919

2020
public InstantiateInterceptor(String injectedString) {

hibernate-core/src/test/java/org/hibernate/orm/test/interceptor/InterceptorNonNullTransactionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import jakarta.persistence.GeneratedValue;
1919
import jakarta.persistence.Id;
2020

21-
import org.hibernate.EmptyInterceptor;
21+
import org.hibernate.Interceptor;
2222
import org.hibernate.Session;
2323
import org.hibernate.cfg.AvailableSettings;
2424
import org.hibernate.resource.transaction.spi.TransactionStatus;
@@ -205,7 +205,7 @@ public void setName(String name) {
205205
}
206206
}
207207

208-
private class TransactionInterceptor extends EmptyInterceptor {
208+
private class TransactionInterceptor implements Interceptor {
209209
private boolean afterTransactionBeginMethodCalled;
210210
private Boolean afterTransactionBeginAssertionPassed;
211211

0 commit comments

Comments
 (0)