Package io.micronaut.data.event
Interface EntityEventListener<T>
-
- Type Parameters:
T
- the entity type
- All Superinterfaces:
java.util.EventListener
,io.micronaut.core.order.Ordered
- All Known Subinterfaces:
PostPersistEventListener<T>
,PostRemoveEventListener<T>
,PostUpdateEventListener<T>
,PrePersistEventListener<T>
,PreRemoveEventListener<T>
,PreUpdateEventListener<T>
- All Known Implementing Classes:
AnnotatedMethodInvokingEntityEventListener
,AutoPopulatedEntityEventListener
,AutoTimestampEntityEventListener
,EntityEventRegistry
,UUIDGeneratingEntityEventListener
,VersionGeneratingEntityEventListener
@Indexed(EntityEventListener.class) public interface EntityEventListener<T> extends java.util.EventListener, io.micronaut.core.order.Ordered
The interface representing an entity event listener.Event listeners are able to listen for persistence events through the various method hooks provided. The
supports(RuntimePersistentEntity, Class)
method can be used to narrow applicable entities and should be called by implementors prior to invoking one of the event methods.Note that
EntityEventListener
added by the user SHOULD NOT be annotated withPrimary
.- Since:
- 2.3.0
- Author:
- graemerocher, Denis Stepanov
-
-
Field Summary
Fields Modifier and Type Field Description static EntityEventListener<java.lang.Object>
NOOP
A no-op event listener that does nothing.
-
Method Summary
All Methods Instance Methods Default Methods Modifier and Type Method Description default void
postLoad(EntityEventContext<T> context)
A post-load hook.default void
postPersist(EntityEventContext<T> context)
A post-persist hook.default void
postRemove(EntityEventContext<T> context)
A post-remove hook.default void
postUpdate(EntityEventContext<T> context)
A post-update hook.default boolean
prePersist(EntityEventContext<T> context)
A pre-persist hook.default boolean
preQuery(QueryEventContext<T> context)
A pre-update hook.default boolean
preRemove(EntityEventContext<T> context)
A pre-remove hook.default boolean
preUpdate(EntityEventContext<T> context)
A pre-update hook.default boolean
supports(RuntimePersistentEntity<T> entity, java.lang.Class<? extends java.lang.annotation.Annotation> eventType)
Allows including or excluding a listener for a specific entity.
-
-
-
Field Detail
-
NOOP
static final EntityEventListener<java.lang.Object> NOOP
A no-op event listener that does nothing.
-
-
Method Detail
-
supports
default boolean supports(RuntimePersistentEntity<T> entity, java.lang.Class<? extends java.lang.annotation.Annotation> eventType)
Allows including or excluding a listener for a specific entity.- Parameters:
entity
- The entityeventType
- The event type- Returns:
- True if it is supported
-
prePersist
default boolean prePersist(@NonNull EntityEventContext<T> context)
A pre-persist hook. Implementors can return false to evict the operation.- Parameters:
context
- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
postPersist
default void postPersist(@NonNull EntityEventContext<T> context)
A post-persist hook. Executed once the object has been persisted.- Parameters:
context
- The context object
-
postLoad
default void postLoad(@NonNull EntityEventContext<T> context)
A post-load hook. Executed once the object has been persisted.- Parameters:
context
- The context object
-
preRemove
default boolean preRemove(@NonNull EntityEventContext<T> context)
A pre-remove hook. Implementors can return false to evict the operation.- Parameters:
context
- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
postRemove
default void postRemove(@NonNull EntityEventContext<T> context)
A post-remove hook. Executed once the object has been removed.- Parameters:
context
- The context object
-
preUpdate
default boolean preUpdate(@NonNull EntityEventContext<T> context)
A pre-update hook. Implementors can return false to evict the operation.- Parameters:
context
- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
preQuery
default boolean preQuery(@NonNull QueryEventContext<T> context)
A pre-update hook. Implementors can return false to evict the operation.- Parameters:
context
- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
postUpdate
default void postUpdate(@NonNull EntityEventContext<T> context)
A post-update hook. Executed once the object has been updated.- Parameters:
context
- The context object
-
-