Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,53 @@
import jakarta.persistence.PreUpdate;

/**
* Enumerates the entity lifecycle callback types defined by JPA.
*
* @author Steve Ebersole
*/
public enum CallbackType {
PRE_UPDATE( PreUpdate.class ),
POST_UPDATE( PostUpdate.class ),
PRE_PERSIST( PrePersist.class ),
POST_PERSIST( PostPersist.class ),
PRE_REMOVE( PreRemove.class ),
POST_REMOVE( PostRemove.class ),
POST_LOAD( PostLoad.class );

private final Class<? extends Annotation> callbackAnnotation;

CallbackType(Class<? extends Annotation> callbackAnnotation) {
this.callbackAnnotation = callbackAnnotation;
}
/**
* @see PreUpdate
*/
PRE_UPDATE,
/**
* @see PostUpdate
*/
POST_UPDATE,
/**
* @see PrePersist
*/
PRE_PERSIST,
/**
* @see PostPersist
*/
POST_PERSIST,
/**
* @see PreRemove
*/
PRE_REMOVE,
/**
* @see PostRemove
*/
POST_REMOVE,
/**
* @see PostLoad
*/
POST_LOAD;

/**
* The JPA-defined callback annotation type corresponding
* to this lifecycle event type.
*/
public Class<? extends Annotation> getCallbackAnnotation() {
return callbackAnnotation;
return switch ( this ) {
case PRE_PERSIST -> PrePersist.class;
case PRE_UPDATE -> PreUpdate.class;
case PRE_REMOVE -> PreRemove.class;
case POST_PERSIST -> PostPersist.class;
case POST_UPDATE -> PostUpdate.class;
case POST_REMOVE -> PostRemove.class;
case POST_LOAD -> PostLoad.class;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
*/

/**
* The SPI contracts for supporting JPA lifecycle callbacks.
* The SPI contracts for supporting JPA lifecycle callbacks and
* {@link jakarta.persistence.EntityListeners entity listeners}.
*
* @see jakarta.persistence.EntityListeners
* @see jakarta.persistence.PrePersist
* @see jakarta.persistence.PreUpdate
* @see jakarta.persistence.PreRemove
* @see jakarta.persistence.PostPersist
* @see jakarta.persistence.PostUpdate
* @see jakarta.persistence.PostRemove
* @see jakarta.persistence.PostLoad
*/
package org.hibernate.jpa.event.spi;