Class JpaOptimisticLockingListener
java.lang.Object
org.keycloak.models.map.storage.jpa.hibernate.listeners.JpaOptimisticLockingListener
- All Implemented Interfaces:
org.hibernate.event.spi.PreDeleteEventListener
,org.hibernate.event.spi.PreInsertEventListener
,org.hibernate.event.spi.PreUpdateEventListener
public class JpaOptimisticLockingListener
extends Object
implements org.hibernate.event.spi.PreInsertEventListener, org.hibernate.event.spi.PreDeleteEventListener, org.hibernate.event.spi.PreUpdateEventListener
Listen on changes on child entities and forces an optimistic locking increment on the closest parent aka root.
The assumption is that any parent of a child entity is root entity. Optimistic locking is enforced on child entity
which is not the child entity at the same time. This prevents
OptimisticLockException
s
when different children in the same parent are being manipulated at the same time by different threads.
This support a multiple level parent-child relationship, where only the closest parent is locked.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
lockRootEntity
(org.hibernate.Session session, Object entity) Check if the entity is a child with a parent and force optimistic locking increment on the parent aka root.boolean
onPreDelete
(org.hibernate.event.spi.PreDeleteEvent event) boolean
onPreInsert
(org.hibernate.event.spi.PreInsertEvent event) boolean
onPreUpdate
(org.hibernate.event.spi.PreUpdateEvent event)
-
Field Details
-
INSTANCE
-
-
Constructor Details
-
JpaOptimisticLockingListener
public JpaOptimisticLockingListener()
-
-
Method Details
-
lockRootEntity
public void lockRootEntity(org.hibernate.Session session, Object entity) throws org.hibernate.HibernateException Check if the entity is a child with a parent and force optimistic locking increment on the parent aka root.- 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
-