public class LockOptions extends Object implements Serializable
Contains locking details (LockMode, Timeout and Scope).
| Modifier and Type | Field and 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 and Description |
|---|
LockOptions()
Constructs a LockOptions with all default options.
|
LockOptions(LockMode lockMode)
Constructs a LockOptions with the given lock mode.
|
| Modifier and Type | Method and 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.
|
Iterator<Map.Entry<String,LockMode>> |
getAliasLockIterator()
Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.
|
LockMode |
getAliasSpecificLockMode(String alias)
Get the
LockMode explicitly specified for the given alias via
setAliasSpecificLockMode(java.lang.String, org.hibernate.LockMode)
<p/>
Differs from getEffectiveLockMode(java.lang.String) in that here we only return
explicitly specified alias-specific lock modes. |
Iterable<Map.Entry<String,LockMode>> |
getAliasSpecificLocks()
Iterable access to alias (key) and LockMode (value) as Map.Entry.
|
LockMode |
getEffectiveLockMode(String alias)
Determine the
LockMode to apply to the given alias. |
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(String alias,
LockMode lockMode)
Specify the
LockMode to be used for a specific query alias. |
LockOptions |
setFollowOnLocking(Boolean followOnLocking)
Set the the follow-on-locking setting.
|
LockOptions |
setLockMode(LockMode lockMode)
Set the overall
LockMode to be used. |
LockOptions |
setScope(boolean scope)
Set the scope.
|
LockOptions |
setTimeOut(int timeout)
Set the timeout setting.
|
public static final LockOptions NONE
Represents LockMode.NONE (timeout + scope do not apply).
public static final LockOptions READ
Represents LockMode.READ (timeout + scope do not apply).
public static final LockOptions UPGRADE
Represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked).
public static final int NO_WAIT
Indicates that the database should not wait at all to acquire the pessimistic lock.
getTimeOut(),
Constant Field Valuespublic static final int WAIT_FOREVER
Indicates that there is no timeout for the acquisition.
getTimeOut(),
Constant Field Valuespublic static final int SKIP_LOCKED
Indicates that rows that are already locked should be skipped.
getTimeOut(),
Constant Field Valuespublic LockOptions()
Constructs a LockOptions with all default options.
public LockOptions(LockMode lockMode)
Constructs a LockOptions with the given lock mode.
lockMode - The lock mode to usepublic LockMode getLockMode()
Retrieve the overall lock mode in effect for this set of options.
<p/>
In certain contexts (hql and criteria), lock-modes can be defined in an
even more granular per-alias fashion
public LockOptions setLockMode(LockMode lockMode)
Set the overall LockMode to be used. The default is
LockMode.NONE
lockMode - The new overall lock mode to use.public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode)
Specify the LockMode to be used for a specific query alias.
alias - used to reference the LockMode.lockMode - The lock mode to apply to the given aliasQuery.setLockMode(String, LockMode),
Criteria.setLockMode(LockMode),
Criteria.setLockMode(String, LockMode)public LockMode getAliasSpecificLockMode(String alias)
Get the LockMode explicitly specified for the given alias via
setAliasSpecificLockMode(java.lang.String, org.hibernate.LockMode)
<p/>
Differs from getEffectiveLockMode(java.lang.String) in that here we only return
explicitly specified alias-specific lock modes.
alias - The alias for which to locate the explicit lock mode.public LockMode getEffectiveLockMode(String alias)
Determine the LockMode to apply to the given alias. If no
mode was explicitly set, the
overall mode is returned. If the overall lock mode is
<tt>null</tt> as well, LockMode.NONE is returned.
<p/>
Differs from getAliasSpecificLockMode(java.lang.String) in that here we fallback to we only return
the overall lock mode.
alias - The alias for which to locate the effective lock mode.public boolean hasAliasSpecificLockModes()
Does this LockOptions object define alias-specific lock modes?
true if this LockOptions object define alias-specific lock modes; false otherwise.public int getAliasLockCount()
Get the number of aliases that have specific lock modes defined.
public Iterator<Map.Entry<String,LockMode>> getAliasLockIterator()
Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.
public Iterable<Map.Entry<String,LockMode>> getAliasSpecificLocks()
Iterable access to alias (key) and LockMode (value) as Map.Entry.
public LockMode findGreatestLockMode()
Currently needed for follow-on locking.
public int getTimeOut()
Retrieve the current timeout setting.
<p/>
The timeout is the amount of time, in milliseconds, we should instruct the database
to wait for any requested pessimistic lock acquisition.
<p/>
NO_WAIT, WAIT_FOREVER or SKIP_LOCKED represent 3 "magic" values.
NO_WAIT, WAIT_FOREVER or SKIP_LOCKEDpublic LockOptions setTimeOut(int timeout)
Set the timeout setting.
<p/>
See getTimeOut() for a discussion of meaning.
timeout - The new timeout setting.getTimeOut()public boolean getScope()
Retrieve the current lock scope setting. <p/> "scope" is a JPA defined term. It is basically a cascading of the lock to associations.
public LockOptions setScope(boolean scope)
Set the scope.
scope - The new scope settingpublic Boolean getFollowOnLocking()
Retrieve the current follow-on-locking setting.
public LockOptions setFollowOnLocking(Boolean followOnLocking)
Set the the follow-on-locking setting.
followOnLocking - The new follow-on-locking settingpublic LockOptions makeCopy()
Make a copy.
public static LockOptions copy(LockOptions source, LockOptions destination)
Perform a shallow copy.
source - Source for the copy (copied from)destination - Destination for the copy (copied to)Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.