Class JpaEntityVersionListener
java.lang.Object
org.keycloak.models.map.storage.jpa.hibernate.listeners.JpaEntityVersionListener
- All Implemented Interfaces:
org.hibernate.event.spi.PreDeleteEventListener
,org.hibernate.event.spi.PreInsertEventListener
,org.hibernate.event.spi.PreUpdateEventListener
public class JpaEntityVersionListener
extends Object
implements org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreDeleteEventListener, org.hibernate.event.spi.PreUpdateEventListener
Listen on changes on child- and root entities and updates the current entity version of the root.
This support a multiple level parent-child relationship, where all parents needs the entity version to be updated
in case it was effectively changed. The traversing is stopped at that point when it is detected that parent entity
version is the same one.
It is based on an assumption that it may happen that one parent entity could be extracted into "parent A -> parent B -> child"
format. Then the change (insertion, deletion or update) of the child should bump the entity version of both parent B and parent A.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
onPreDelete
(org.hibernate.event.spi.PreDeleteEvent event) boolean
onPreInsert
(org.hibernate.event.spi.PreInsertEvent event) boolean
onPreUpdate
(org.hibernate.event.spi.PreUpdateEvent event) void
updateEntityVersion
(Object entity) Traverse from current entity through its parent tree and update the entity version of it.
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
JpaEntityVersionListener
public JpaEntityVersionListener()
-
-
Method Details
-
updateEntityVersion
Traverse from current entity through its parent tree and update the entity version of it. Stop if non-changed parent is found.- Throws:
org.hibernate.HibernateException
-
onPreInsert
public boolean onPreInsert(org.hibernate.event.spi.PreInsertEvent event) - Specified by:
onPreInsert
in interfaceorg.hibernate.event.spi.PreInsertEventListener
-
onPreDelete
public boolean onPreDelete(org.hibernate.event.spi.PreDeleteEvent event) - Specified by:
onPreDelete
in interfaceorg.hibernate.event.spi.PreDeleteEventListener
-
onPreUpdate
public boolean onPreUpdate(org.hibernate.event.spi.PreUpdateEvent event) - Specified by:
onPreUpdate
in interfaceorg.hibernate.event.spi.PreUpdateEventListener
-