Package org.hibernate

Class LockOptions

    • Constructor Detail

      • LockOptions

        public LockOptions​(LockMode lockMode)
        Construct an instance with the given mode and WAIT_FOREVER.
        Parameters:
        lockMode - The initial lock mode
      • LockOptions

        public LockOptions​(LockMode lockMode,
                           int timeout)
        Construct an instance with the given mode and timeout.
        Parameters:
        lockMode - The initial lock mode
        timeout - The initial timeout
      • LockOptions

        public LockOptions​(LockMode lockMode,
                           int timeout,
                           PessimisticLockScope scope)
        Construct an instance with the given mode, timeout, and scope.
        Parameters:
        lockMode - The initial lock mode
        timeout - The initial timeout
        scope - The initial lock scope
    • Method Detail

      • isEmpty

        public boolean isEmpty()
        Determine of the lock options are empty.
        Returns:
        true if the lock options are equivalent to NONE.
      • getLockMode

        public LockMode getLockMode()
        Retrieve the overall lock mode in effect for this set of options.
        Returns:
        the overall lock mode
      • setLockMode

        public LockOptions setLockMode​(LockMode lockMode)
        Set the overall lock mode. The default is LockMode.NONE, that is, no locking at all.
        Parameters:
        lockMode - the new overall lock mode
        Returns:
        this for method chaining
      • setAliasSpecificLockMode

        public LockOptions setAliasSpecificLockMode​(String alias,
                                                    LockMode lockMode)
        Specify the LockMode to be used for the given query alias.
        Parameters:
        alias - the query alias to which the lock mode applies
        lockMode - the lock mode to apply to the given alias
        Returns:
        this for method chaining
        See Also:
        Query.setLockMode(String, LockMode)
      • hasAliasSpecificLockModes

        public boolean hasAliasSpecificLockModes()
        Does this LockOptions instance define alias-specific lock modes?
        Returns:
        true if this object defines alias-specific lock modes; false otherwise.
      • getAliasLockCount

        public int getAliasLockCount()
        The number of aliases that have alias-specific lock modes specified.
        Returns:
        the number of explicitly defined alias lock modes.
      • findGreatestLockMode

        public LockMode findGreatestLockMode()
        Currently needed for follow-on locking.
        Returns:
        The greatest of all requested lock modes.
      • getTimeOut

        public int getTimeOut()
        The current timeout, a maximum amount of time in milliseconds that the database should wait to obtain a pessimistic lock before returning an error to the client.

        NO_WAIT, WAIT_FOREVER, or SKIP_LOCKED represent 3 "magic" values.

        Returns:
        a timeout in milliseconds, NO_WAIT, WAIT_FOREVER, or SKIP_LOCKED
      • setTimeOut

        public LockOptions setTimeOut​(int timeout)
        Set the timeout, that is, the maximum amount of time in milliseconds that the database should wait to obtain a pessimistic lock before returning an error to the client.

        NO_WAIT, WAIT_FOREVER, or SKIP_LOCKED represent 3 "magic" values.

        Parameters:
        timeout - the new timeout setting, in milliseconds
        Returns:
        this for method chaining
        See Also:
        getTimeOut()
      • getScope

        @Deprecated(since="6.2")
        public boolean getScope()
        Deprecated.
        The current lock scope setting:
        • true means the lock extends to rows of owned collections, but
        • false means only the entity table and secondary tables are locked.
        Returns:
        true if the lock extends to owned associations
      • setScope

        @Deprecated(since="6.2")
        public LockOptions setScope​(boolean scope)
        Set the lock scope setting:
        • true means the lock extends to rows of owned collections, but
        • false means only the entity table and secondary tables are locked.
        Parameters:
        scope - the new scope setting
        Returns:
        this for method chaining
      • getFollowOnLocking

        public Boolean getFollowOnLocking()
        Returns a value indicating if follow-on locking was force enabled or disabled, overriding the default behavior of the SQL dialect.
        Returns:
        true if follow-on locking was force enabled, false if follow-on locking was force disabled, or null if the default behavior of the dialect has not been overridden.
        See Also:
        HibernateHints.HINT_FOLLOW_ON_LOCKING, Dialect.useFollowOnLocking(String, QueryOptions)
      • makeCopy

        public LockOptions makeCopy()
        Make a copy.
        Returns:
        The copy
      • overlay

        public void overlay​(LockOptions lockOptions)
        Copy the given lock options into this instance, merging the alias-specific lock modes.
      • copy

        public static LockOptions copy​(LockOptions source,
                                       LockOptions destination)
        Copy the options in the first given instance of LockOptions to the second given instance.
        Parameters:
        source - Source for the copy (copied from)
        destination - Destination for the copy (copied to)
        Returns:
        destination
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object