Class EntityHistoryRelationEntityListener
java.lang.Object
ch.tocco.nice2.persist.core.api.util.CollectingAfterFlushEntityListener
ch.tocco.nice2.optional.entityhistory.impl.EntityHistoryRelationEntityListener
- All Implemented Interfaces:
EntityFacadeListener
,CommitListener
,EventListener
@Component
public class EntityHistoryRelationEntityListener
extends CollectingAfterFlushEntityListener
Tracks field changes on existing entities and save them as Entity_history
A EntityHistoryConfig/ChildEntityHistoryConfig is required, as an example:
@Bean
public EntityHistoryConfig relationEntityHistoryConfig() {
EntityHistoryConfig config = new EntityHistoryConfig();
config.setHistoryRelatedEntityName("User");
config.setRelationsToTrack("relGender");
return bean;
}
Additionally this listener must be registered for the entity:
@Bean
public ListenerContribution<EntityFacadeListener> userEntityHistoryRelationEntityListener(EntityFacadeListener entityHistoryRelationEntityListener) {
ListenerContribution<EntityFacadeListener> contribution = new ListenerContribution<>();
contribution.setListener(entityHistoryRelationEntityListener);
contribution.setFilter("User");
return contribution;
}
-
Nested Class Summary
Nested classes/interfaces inherited from class ch.tocco.nice2.persist.core.api.util.CollectingAfterFlushEntityListener
CollectingAfterFlushEntityListener.EntityContext
-
Constructor Summary
ConstructorsConstructorDescriptionEntityHistoryRelationEntityListener
(L10N l10N, TextResources textResources, CommandExecutor commandExecutor, DefaultDisplayService defaultDisplayService, EntityHistoryService entityHistoryService) -
Method Summary
Modifier and TypeMethodDescriptionboolean
void
int
priority()
Defines execution order of allCollectingAfterFlushEntityListener
.Methods inherited from class ch.tocco.nice2.persist.core.api.util.CollectingAfterFlushEntityListener
afterCommit, afterFlush, beforeCommit, entityChanging, entityCreating, entityDeleting, entityRelationChanging, getEntityContext, onEntityChanging, onEntityCreating, onEntityDeleting
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface ch.tocco.nice2.persist.core.api.entity.events.EntityFacadeListener
entityReceivedValues, handleSessionOnlyEntity
-
Constructor Details
-
EntityHistoryRelationEntityListener
public EntityHistoryRelationEntityListener(L10N l10N, TextResources textResources, CommandExecutor commandExecutor, DefaultDisplayService defaultDisplayService, EntityHistoryService entityHistoryService)
-
-
Method Details
-
onEntityRelationChanging
- Overrides:
onEntityRelationChanging
in classCollectingAfterFlushEntityListener
-
onAfterFlush
- Specified by:
onAfterFlush
in classCollectingAfterFlushEntityListener
- Returns:
- true if this listeners has made any changes to the database
-
priority
public int priority()Description copied from class:CollectingAfterFlushEntityListener
Defines execution order of allCollectingAfterFlushEntityListener
. It is important to make sure that other listeners are not affected.- Specified by:
priority
in interfaceCommitListener
- Specified by:
priority
in classCollectingAfterFlushEntityListener
-
createEntityContext
- Overrides:
createEntityContext
in classCollectingAfterFlushEntityListener
-