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 OptimisticLockExceptions 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 Details

  • 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 interface org.hibernate.event.spi.PreInsertEventListener
    • onPreDelete

      public boolean onPreDelete(org.hibernate.event.spi.PreDeleteEvent event)
      Specified by:
      onPreDelete in interface org.hibernate.event.spi.PreDeleteEventListener
    • onPreUpdate

      public boolean onPreUpdate(org.hibernate.event.spi.PreUpdateEvent event)
      Specified by:
      onPreUpdate in interface org.hibernate.event.spi.PreUpdateEventListener