Skip to content

Commit d3bc67b

Browse files
committed
modernize the CallbackType enum
1 parent 7215a91 commit d3bc67b

File tree

2 files changed

+54
-15
lines changed

2 files changed

+54
-15
lines changed

hibernate-core/src/main/java/org/hibernate/jpa/event/spi/CallbackType.java

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,53 @@
1414
import jakarta.persistence.PreUpdate;
1515

1616
/**
17+
* Enumerates the entity lifecycle callback types defined by JPA.
18+
*
1719
* @author Steve Ebersole
1820
*/
1921
public enum CallbackType {
20-
PRE_UPDATE( PreUpdate.class ),
21-
POST_UPDATE( PostUpdate.class ),
22-
PRE_PERSIST( PrePersist.class ),
23-
POST_PERSIST( PostPersist.class ),
24-
PRE_REMOVE( PreRemove.class ),
25-
POST_REMOVE( PostRemove.class ),
26-
POST_LOAD( PostLoad.class );
27-
28-
private final Class<? extends Annotation> callbackAnnotation;
29-
30-
CallbackType(Class<? extends Annotation> callbackAnnotation) {
31-
this.callbackAnnotation = callbackAnnotation;
32-
}
22+
/**
23+
* @see PreUpdate
24+
*/
25+
PRE_UPDATE,
26+
/**
27+
* @see PostUpdate
28+
*/
29+
POST_UPDATE,
30+
/**
31+
* @see PrePersist
32+
*/
33+
PRE_PERSIST,
34+
/**
35+
* @see PostPersist
36+
*/
37+
POST_PERSIST,
38+
/**
39+
* @see PreRemove
40+
*/
41+
PRE_REMOVE,
42+
/**
43+
* @see PostRemove
44+
*/
45+
POST_REMOVE,
46+
/**
47+
* @see PostLoad
48+
*/
49+
POST_LOAD;
3350

51+
/**
52+
* The JPA-defined callback annotation type corresponding
53+
* to this lifecycle event type.
54+
*/
3455
public Class<? extends Annotation> getCallbackAnnotation() {
35-
return callbackAnnotation;
56+
return switch ( this ) {
57+
case PRE_PERSIST -> PrePersist.class;
58+
case PRE_UPDATE -> PreUpdate.class;
59+
case PRE_REMOVE -> PreRemove.class;
60+
case POST_PERSIST -> PostPersist.class;
61+
case POST_UPDATE -> PostUpdate.class;
62+
case POST_REMOVE -> PostRemove.class;
63+
case POST_LOAD -> PostLoad.class;
64+
};
3665
}
3766
}

hibernate-core/src/main/java/org/hibernate/jpa/event/spi/package-info.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44
*/
55

66
/**
7-
* The SPI contracts for supporting JPA lifecycle callbacks.
7+
* The SPI contracts for supporting JPA lifecycle callbacks and
8+
* {@link jakarta.persistence.EntityListeners entity listeners}.
9+
*
10+
* @see jakarta.persistence.EntityListeners
11+
* @see jakarta.persistence.PrePersist
12+
* @see jakarta.persistence.PreUpdate
13+
* @see jakarta.persistence.PreRemove
14+
* @see jakarta.persistence.PostPersist
15+
* @see jakarta.persistence.PostUpdate
16+
* @see jakarta.persistence.PostRemove
17+
* @see jakarta.persistence.PostLoad
818
*/
919
package org.hibernate.jpa.event.spi;

0 commit comments

Comments
 (0)