Class VersionGeneratingEntityEventListener
java.lang.Object
io.micronaut.data.runtime.event.listeners.VersionGeneratingEntityEventListener
- All Implemented Interfaces:
io.micronaut.core.order.Ordered,EntityEventListener<Object>,PropertyAutoPopulator<Version>,EventListener
@Singleton
public class VersionGeneratingEntityEventListener
extends Object
implements EntityEventListener<Object>, PropertyAutoPopulator<Version>
Supports optimistic locking by using a version.
- Since:
- 2.4.0
- Author:
- Denis Stepanov
-
Field Summary
Fields inherited from interface io.micronaut.data.event.EntityEventListener
NOOPFields inherited from interface io.micronaut.core.order.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionVersionGeneratingEntityEventListener(DateTimeProvider dateTimeProvider, DataConversionService conversionService) -
Method Summary
Modifier and TypeMethodDescription@NonNull Objectpopulate(RuntimePersistentProperty<?> property, @Nullable Object previousValue) Auto-populating the property.booleanprePersist(@NonNull EntityEventContext<Object> context) A pre-persist hook.booleanpreRemove(@NonNull EntityEventContext<Object> context) A pre-remove hook.booleanpreUpdate(@NonNull EntityEventContext<Object> context) A pre-update hook.booleansupports(RuntimePersistentEntity<Object> entity, Class<? extends Annotation> eventType) Allows including or excluding a listener for a specific entity.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.data.event.EntityEventListener
postLoad, postPersist, postRemove, postUpdate, preQueryMethods inherited from interface io.micronaut.core.order.Ordered
getOrder
-
Constructor Details
-
VersionGeneratingEntityEventListener
public VersionGeneratingEntityEventListener(DateTimeProvider dateTimeProvider, DataConversionService conversionService)
-
-
Method Details
-
supports
public boolean supports(RuntimePersistentEntity<Object> entity, Class<? extends Annotation> eventType) Description copied from interface:EntityEventListenerAllows including or excluding a listener for a specific entity.- Specified by:
supportsin interfaceEntityEventListener<Object>- Parameters:
entity- The entityeventType- The event type- Returns:
- True if it is supported
-
prePersist
Description copied from interface:EntityEventListenerA pre-persist hook. Implementors can return false to evict the operation.- Specified by:
prePersistin interfaceEntityEventListener<Object>- Parameters:
context- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
preUpdate
Description copied from interface:EntityEventListenerA pre-update hook. Implementors can return false to evict the operation.- Specified by:
preUpdatein interfaceEntityEventListener<Object>- Parameters:
context- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
preRemove
Description copied from interface:EntityEventListenerA pre-remove hook. Implementors can return false to evict the operation.- Specified by:
preRemovein interfaceEntityEventListener<Object>- Parameters:
context- The context object- Returns:
- A boolean value indicating whether to proceed with the operation.
-
populate
@NonNull public @NonNull Object populate(RuntimePersistentProperty<?> property, @Nullable @Nullable Object previousValue) Description copied from interface:PropertyAutoPopulatorAuto-populating the property.- Specified by:
populatein interfacePropertyAutoPopulator<Version>- Parameters:
property- the property to auto-populatepreviousValue- the previous value, if any- Returns:
- new value
-