Class OptimisticLockingStrategy

  • All Implemented Interfaces:
    LockingStrategy

    public class OptimisticLockingStrategy
    extends java.lang.Object
    implements LockingStrategy
    An optimistic locking strategy that verifies that the version hasn't changed (prior to transaction commit).

    This strategy is valid for LockMode.OPTIMISTIC

    Since:
    3.5
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected LockMode getLockMode()  
      void lock​(java.io.Serializable id, java.lang.Object version, java.lang.Object object, int timeout, SharedSessionContractImplementor session)
      Acquire an appropriate type of lock on the underlying data that will endure until the end of the current transaction.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • OptimisticLockingStrategy

        public OptimisticLockingStrategy​(Lockable lockable,
                                         LockMode lockMode)
        Construct locking strategy.
        Parameters:
        lockable - The metadata for the entity to be locked.
        lockMode - Indicates the type of lock to be acquired.
    • Method Detail

      • lock

        public void lock​(java.io.Serializable id,
                         java.lang.Object version,
                         java.lang.Object object,
                         int timeout,
                         SharedSessionContractImplementor session)
        Description copied from interface: LockingStrategy
        Acquire an appropriate type of lock on the underlying data that will endure until the end of the current transaction.
        Specified by:
        lock in interface LockingStrategy
        Parameters:
        id - The id of the row to be locked
        version - The current version (or null if not versioned)
        object - The object logically being locked (currently not used)
        timeout - timeout in milliseconds, 0 = no wait, -1 = wait indefinitely
        session - The session from which the lock request originated
      • getLockMode

        protected LockMode getLockMode()