Package org.hibernate
Class LockOptions
- java.lang.Object
-
- org.hibernate.LockOptions
-
- All Implemented Interfaces:
java.io.Serializable
public class LockOptions extends java.lang.Object implements java.io.Serializable
Contains locking details (LockMode, Timeout and Scope).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
NO_WAIT
Indicates that the database should not wait at all to acquire the pessimistic lock.static LockOptions
NONE
Represents LockMode.NONE (timeout + scope do not apply).static LockOptions
READ
Represents LockMode.READ (timeout + scope do not apply).static int
SKIP_LOCKED
Indicates that rows that are already locked should be skipped.static LockOptions
UPGRADE
Represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked).static int
WAIT_FOREVER
Indicates that there is no timeout for the acquisition.
-
Constructor Summary
Constructors Constructor Description LockOptions()
Constructs a LockOptions with all default options.LockOptions(LockMode lockMode)
Constructs a LockOptions with the given lock mode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static LockOptions
copy(LockOptions source, LockOptions destination)
Perform a shallow copy.LockMode
findGreatestLockMode()
Currently needed for follow-on locking.int
getAliasLockCount()
Get the number of aliases that have specific lock modes defined.java.util.Iterator<java.util.Map.Entry<java.lang.String,LockMode>>
getAliasLockIterator()
Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.LockMode
getAliasSpecificLockMode(java.lang.String alias)
Get theLockMode
explicitly specified for the given alias viasetAliasSpecificLockMode(java.lang.String, org.hibernate.LockMode)
java.lang.Iterable<java.util.Map.Entry<java.lang.String,LockMode>>
getAliasSpecificLocks()
Iterable access to alias (key) and LockMode (value) as Map.Entry.LockMode
getEffectiveLockMode(java.lang.String alias)
Determine theLockMode
to apply to the given alias.java.lang.Boolean
getFollowOnLocking()
Retrieve the current follow-on-locking setting.LockMode
getLockMode()
Retrieve the overall lock mode in effect for this set of options.boolean
getScope()
Retrieve the current lock scope setting.int
getTimeOut()
Retrieve the current timeout setting.boolean
hasAliasSpecificLockModes()
Does this LockOptions object define alias-specific lock modes?LockOptions
makeCopy()
Make a copy.LockOptions
setAliasSpecificLockMode(java.lang.String alias, LockMode lockMode)
Specify theLockMode
to be used for a specific query alias.LockOptions
setFollowOnLocking(java.lang.Boolean followOnLocking)
Set the the follow-on-locking setting.LockOptions
setLockMode(LockMode lockMode)
Set the overallLockMode
to be used.LockOptions
setScope(boolean scope)
Set the scope.LockOptions
setTimeOut(int timeout)
Set the timeout setting.
-
-
-
Field Detail
-
NONE
public static final LockOptions NONE
Represents LockMode.NONE (timeout + scope do not apply).
-
READ
public static final LockOptions READ
Represents LockMode.READ (timeout + scope do not apply).
-
UPGRADE
public static final LockOptions UPGRADE
Represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked).
-
NO_WAIT
public static final int NO_WAIT
Indicates that the database should not wait at all to acquire the pessimistic lock.- See Also:
getTimeOut()
, Constant Field Values
-
WAIT_FOREVER
public static final int WAIT_FOREVER
Indicates that there is no timeout for the acquisition.- See Also:
getTimeOut()
, Constant Field Values
-
SKIP_LOCKED
public static final int SKIP_LOCKED
Indicates that rows that are already locked should be skipped.- See Also:
getTimeOut()
, Constant Field Values
-
-
Constructor Detail
-
LockOptions
public LockOptions()
Constructs a LockOptions with all default options.
-
LockOptions
public LockOptions(LockMode lockMode)
Constructs a LockOptions with the given lock mode.- Parameters:
lockMode
- The lock mode to use
-
-
Method Detail
-
getLockMode
public LockMode getLockMode()
Retrieve the overall lock mode in effect for this set of options. In certain contexts (hql and criteria), lock-modes can be defined in an even more granularper-alias
fashion- Returns:
- The overall lock mode.
-
setLockMode
public LockOptions setLockMode(LockMode lockMode)
Set the overallLockMode
to be used. The default isLockMode.NONE
- Parameters:
lockMode
- The new overall lock mode to use.- Returns:
- this (for method chaining).
-
setAliasSpecificLockMode
public LockOptions setAliasSpecificLockMode(java.lang.String alias, LockMode lockMode)
Specify theLockMode
to be used for a specific query alias.- Parameters:
alias
- used to reference the LockMode.lockMode
- The lock mode to apply to the given alias- Returns:
- this LockRequest instance for operation chaining.
- See Also:
Query.setLockMode(String, LockMode)
,Criteria.setLockMode(LockMode)
,Criteria.setLockMode(String, LockMode)
-
getAliasSpecificLockMode
public LockMode getAliasSpecificLockMode(java.lang.String alias)
Get theLockMode
explicitly specified for the given alias viasetAliasSpecificLockMode(java.lang.String, org.hibernate.LockMode)
Differs fromgetEffectiveLockMode(java.lang.String)
in that here we only return explicitly specified alias-specific lock modes.- Parameters:
alias
- The alias for which to locate the explicit lock mode.- Returns:
- The explicit lock mode for that alias.
-
getEffectiveLockMode
public LockMode getEffectiveLockMode(java.lang.String alias)
Determine theLockMode
to apply to the given alias. If no mode was explicitlyset
, theoverall mode
is returned. If the overall lock mode is null as well,LockMode.NONE
is returned. Differs fromgetAliasSpecificLockMode(java.lang.String)
in that here we fallback to we only return the overall lock mode.- Parameters:
alias
- The alias for which to locate the effective lock mode.- Returns:
- The effective lock mode.
-
hasAliasSpecificLockModes
public boolean hasAliasSpecificLockModes()
Does this LockOptions object define alias-specific lock modes?- Returns:
true
if this LockOptions object define alias-specific lock modes;false
otherwise.
-
getAliasLockCount
public int getAliasLockCount()
Get the number of aliases that have specific lock modes defined.- Returns:
- the number of explicitly defined alias lock modes.
-
getAliasLockIterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String,LockMode>> getAliasLockIterator()
Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.- Returns:
- Iterator for accessing the Map.Entry's
-
getAliasSpecificLocks
public java.lang.Iterable<java.util.Map.Entry<java.lang.String,LockMode>> getAliasSpecificLocks()
Iterable access to alias (key) and LockMode (value) as Map.Entry.- Returns:
- Iterable for accessing the Map.Entry's
-
findGreatestLockMode
public LockMode findGreatestLockMode()
Currently needed for follow-on locking.- Returns:
- The greatest of all requested lock modes.
-
getTimeOut
public int getTimeOut()
Retrieve the current timeout setting. The timeout is the amount of time, in milliseconds, we should instruct the database to wait for any requested pessimistic lock acquisition.NO_WAIT
,WAIT_FOREVER
orSKIP_LOCKED
represent 3 "magic" values.- Returns:
- timeout in milliseconds,
NO_WAIT
,WAIT_FOREVER
orSKIP_LOCKED
-
setTimeOut
public LockOptions setTimeOut(int timeout)
Set the timeout setting. SeegetTimeOut()
for a discussion of meaning.- Parameters:
timeout
- The new timeout setting.- Returns:
- this (for method chaining).
- See Also:
getTimeOut()
-
getScope
public boolean getScope()
Retrieve the current lock scope setting. "scope" is a JPA defined term. It is basically a cascading of the lock to associations.- Returns:
- true if locking will be extended to owned associations
-
setScope
public LockOptions setScope(boolean scope)
Set the scope.- Parameters:
scope
- The new scope setting- Returns:
- this (for method chaining).
-
getFollowOnLocking
public java.lang.Boolean getFollowOnLocking()
Retrieve the current follow-on-locking setting.- Returns:
- true if follow-on-locking is enabled
-
setFollowOnLocking
public LockOptions setFollowOnLocking(java.lang.Boolean followOnLocking)
Set the the follow-on-locking setting.- Parameters:
followOnLocking
- The new follow-on-locking setting- Returns:
- this (for method chaining).
-
makeCopy
public LockOptions makeCopy()
Make a copy.- Returns:
- The copy
-
copy
public static LockOptions copy(LockOptions source, LockOptions destination)
Perform a shallow copy.- Parameters:
source
- Source for the copy (copied from)destination
- Destination for the copy (copied to)- Returns:
- destination
-
-