Package org.hibernate
Class LockOptions
java.lang.Object
org.hibernate.LockOptions
- All Implemented Interfaces:
Serializable
Contains locking details (LockMode, Timeout and Scope).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intIndicates that the database should not wait at all to acquire the pessimistic lock.static final LockOptionsNONE represents LockMode.NONE (timeout + scope do not apply)static final LockOptionsREAD represents LockMode.READ (timeout + scope do not apply)static final LockOptionsUPGRADE represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked)static final intIndicates that there is no timeout for the acquisition. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LockOptionscopy(LockOptions from, LockOptions dest) Shallow copy From to DestintGet the number of aliases that have specific lock modes defined.Iterator for accessing Alias (key) and LockMode (value) as Map.EntrygetAliasSpecificLockMode(String alias) Get theLockModeexplicitly specified for the given alias viasetAliasSpecificLockMode(java.lang.String, org.hibernate.LockMode)getEffectiveLockMode(String alias) Determine theLockModeto apply to the given alias.Retrieve the overall lock mode in effect for this set of options.booleangetScope()Retrieve the current lock scope setting.intRetrieve the current timeout setting.setAliasSpecificLockMode(String alias, LockMode lockMode) Specify theLockModeto be used for a specific query alias.setLockMode(LockMode lockMode) Set the overallLockModeto be used.setScope(boolean scope) Set the cope.setTimeOut(int timeout) Set the timeout setting.
-
Field Details
-
NONE
NONE represents LockMode.NONE (timeout + scope do not apply) -
READ
READ represents LockMode.READ (timeout + scope do not apply) -
UPGRADE
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_WAITIndicates that the database should not wait at all to acquire the pessimistic lock.- See Also:
-
WAIT_FOREVER
public static final int WAIT_FOREVERIndicates that there is no timeout for the acquisition.- See Also:
-
-
Constructor Details
-
LockOptions
public LockOptions() -
LockOptions
-
-
Method Details
-
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-aliasfashion- Returns:
- The overall lock mode.
-
setLockMode
Set the overallLockModeto be used. The default isLockMode.NONE- Parameters:
lockMode- The new overall lock mode to use.- Returns:
- this (for method chaining).
-
setAliasSpecificLockMode
Specify theLockModeto 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:
-
getAliasSpecificLockMode
Get theLockModeexplicitly 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
Determine theLockModeto apply to the given alias. If no mode was explicitlyset, theoverall modeis returned. If the overall lock mode is null as well,LockMode.NONEis 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.
-
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
Iterator for accessing Alias (key) and LockMode (value) as Map.Entry- Returns:
- Iterator for accessing the Map.Entry's
-
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_WAITandWAIT_FOREVERrepresent 2 "magic" values.- Returns:
- timeout in milliseconds, or
NO_WAITorWAIT_FOREVER
-
setTimeOut
Set the timeout setting. SeegetTimeOut()for a discussion of meaning.- Parameters:
timeout- The new timeout setting.- Returns:
- this (for method chaining).
- See Also:
-
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
Set the cope.- Parameters:
scope- The new scope setting- Returns:
- this (for method chaining).
-
copy
Shallow copy From to Dest- Parameters:
from- is copied fromdest- is copied to- Returns:
- dest
-