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 preventsOptimisticLockExceptions 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 JpaOptimisticLockingListenerINSTANCE
-
Constructor Summary
Constructors Constructor Description JpaOptimisticLockingListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidlockRootEntity(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.booleanonPreDelete(org.hibernate.event.spi.PreDeleteEvent event)booleanonPreInsert(org.hibernate.event.spi.PreInsertEvent event)booleanonPreUpdate(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.HibernateExceptionCheck 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:
onPreInsertin interfaceorg.hibernate.event.spi.PreInsertEventListener
-
onPreDelete
public boolean onPreDelete(org.hibernate.event.spi.PreDeleteEvent event)
- Specified by:
onPreDeletein interfaceorg.hibernate.event.spi.PreDeleteEventListener
-
onPreUpdate
public boolean onPreUpdate(org.hibernate.event.spi.PreUpdateEvent event)
- Specified by:
onPreUpdatein interfaceorg.hibernate.event.spi.PreUpdateEventListener
-
-