Class JpaOptimisticLockingListener
- java.lang.Object
-
- org.keycloak.models.map.storage.jpa.hibernate.listeners.JpaOptimisticLockingListener
-
- All Implemented Interfaces:
Serializable
,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 preventsOptimisticLockException
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.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static JpaOptimisticLockingListener
INSTANCE
-
Constructor Summary
Constructors Constructor Description JpaOptimisticLockingListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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 Detail
-
INSTANCE
public static final JpaOptimisticLockingListener INSTANCE
-
-
Method Detail
-
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
-
-