Top Description Fields Constructors Methods
org.hibernate

public Class LockOptions

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, java.util.Collections, .HashMap, .Iterator, .LinkedHashMap, .Map

Contains locking details (LockMode, Timeout and Scope).
Author
Scott Marlow

Field Summary

Modifier and TypeField and Description
private Map<String, LockMode>
private Boolean
private LockMode
public static final int
NO_WAIT

Indicates that the database should not wait at all to acquire the pessimistic lock.

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).

private boolean
public static final int
SKIP_LOCKED

Indicates that rows that are already locked should be skipped.

private int
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
WAIT_FOREVER

Indicates that there is no timeout for the acquisition.

Constructor Summary

AccessConstructor and Description
public
LockOptions()

Constructs a LockOptions with all default options.

public
LockOptions(LockMode
The lock mode to use
lockMode
)

Constructs a LockOptions with the given lock mode.

Method Summary

Modifier and TypeMethod and Description
public static LockOptions

Returns:

destination
copy
(LockOptions
Source for the copy (copied from)
source
,
LockOptions
Destination for the copy (copied to)
destination
)

Perform a shallow copy.

public LockMode

Returns:

The greatest of all requested lock modes.
findGreatestLockMode
()

Currently needed for follow-on locking.

public int

Returns:

the number of explicitly defined alias lock modes.
getAliasLockCount
()

Get the number of aliases that have specific lock modes defined.

public Iterator<Map.Entry<String, LockMode>>

Returns:

Iterator for accessing the Map.Entry's
getAliasLockIterator
()

Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.

public LockMode

Returns:

The explicit lock mode for that alias.
getAliasSpecificLockMode
(String
The alias for which to locate the explicit lock mode.
alias
)

Get the LockMode explicitly specified for the given alias via setAliasSpecificLockMode

Differs from getEffectiveLockMode in that here we only return explicitly specified alias-specific lock modes.

public Iterable<Map.Entry<String, LockMode>>

Returns:

Iterable for accessing the Map.Entry's
getAliasSpecificLocks
()

Iterable access to alias (key) and LockMode (value) as Map.Entry.

public LockMode

Returns:

The effective lock mode.
getEffectiveLockMode
(String
The alias for which to locate the effective lock mode.
alias
)

Determine the LockMode to apply to the given alias.

public Boolean

Returns:

true if follow-on-locking is enabled
getFollowOnLocking
()

Retrieve the current follow-on-locking setting.

public LockMode

Returns:

The overall lock mode.
getLockMode
()

Retrieve the overall lock mode in effect for this set of options.

public boolean

Returns:

true if locking will be extended to owned associations
getScope
()

Retrieve the current lock scope setting.

public int

Returns:

timeout in milliseconds, NO_WAIT, WAIT_FOREVER or SKIP_LOCKED
getTimeOut
()

Retrieve the current timeout setting.

public boolean

Returns:

true if this LockOptions object define alias-specific lock modes; false otherwise.
hasAliasSpecificLockModes
()

Does this LockOptions object define alias-specific lock modes?

public static LockOptions
interpret(LockMode lockMode)

public LockOptions

Returns:

The copy
makeCopy
()

Make a copy.

public LockOptions

Returns:

this LockRequest instance for operation chaining.
setAliasSpecificLockMode
(String
used to reference the LockMode.
alias
,
LockMode
The lock mode to apply to the given alias
lockMode
)

Specify the LockMode to be used for a specific query alias.

public LockOptions

Returns:

this (for method chaining).
setFollowOnLocking
(Boolean
The new follow-on-locking setting
followOnLocking
)

Set the the follow-on-locking setting.

public LockOptions

Returns:

this (for method chaining).
setLockMode
(LockMode
The new overall lock mode to use.
lockMode
)

Set the overall LockMode to be used.

public LockOptions

Returns:

this (for method chaining).
setScope
(boolean
The new scope setting
scope
)

Set the scope.

public LockOptions

Returns:

this (for method chaining).
setTimeOut
(int
The new timeout setting, in milliseconds
timeout
)

Set the timeout setting.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aliasSpecificLockModesback to summary
private Map<String, LockMode> aliasSpecificLockModes
followOnLockingback to summary
private Boolean followOnLocking
lockModeback to summary
private LockMode lockMode
NO_WAITback to summary
public static final int NO_WAIT

Indicates that the database should not wait at all to acquire the pessimistic lock.

See Also
getTimeOut
NONEback to summary
public static final LockOptions NONE

Represents LockMode.NONE (timeout + scope do not apply).

READback to summary
public static final LockOptions READ

Represents LockMode.READ (timeout + scope do not apply).

scopeback to summary
private boolean scope
SKIP_LOCKEDback to summary
public static final int SKIP_LOCKED

Indicates that rows that are already locked should be skipped.

See Also
getTimeOut()
timeoutback to summary
private int timeout
UPGRADEback to summary
public static final LockOptions UPGRADE

Represents LockMode.UPGRADE (will wait forever for lock and scope of false meaning only entity is locked).

Annotations
@SuppressWarnings:deprecation
WAIT_FOREVERback to summary
public static final int WAIT_FOREVER

Indicates that there is no timeout for the acquisition.

See Also
getTimeOut

Constructor Detail

LockOptionsback to summary
public LockOptions()

Constructs a LockOptions with all default options.

LockOptionsback to summary
public LockOptions(LockMode lockMode)

Constructs a LockOptions with the given lock mode.

Parameters
lockMode:LockMode

The lock mode to use

Method Detail

copyback to summary
public static LockOptions copy(LockOptions source, LockOptions destination)

Perform a shallow copy.

Parameters
source:LockOptions

Source for the copy (copied from)

destination:LockOptions

Destination for the copy (copied to)

Returns:LockOptions

destination

findGreatestLockModeback to summary
public LockMode findGreatestLockMode()

Currently needed for follow-on locking.

Returns:LockMode

The greatest of all requested lock modes.

getAliasLockCountback to summary
public int getAliasLockCount()

Get the number of aliases that have specific lock modes defined.

Returns:int

the number of explicitly defined alias lock modes.

getAliasLockIteratorback to summary
public Iterator<Map.Entry<String, LockMode>> getAliasLockIterator()

Iterator for accessing Alias (key) and LockMode (value) as Map.Entry.

Returns:Iterator<Map.Entry<String, LockMode>>

Iterator for accessing the Map.Entry's

getAliasSpecificLockModeback to summary
public LockMode getAliasSpecificLockMode(String alias)

Get the LockMode explicitly specified for the given alias via setAliasSpecificLockMode

Differs from getEffectiveLockMode in that here we only return explicitly specified alias-specific lock modes.

Parameters
alias:String

The alias for which to locate the explicit lock mode.

Returns:LockMode

The explicit lock mode for that alias.

getAliasSpecificLocksback to summary
public Iterable<Map.Entry<String, LockMode>> getAliasSpecificLocks()

Iterable access to alias (key) and LockMode (value) as Map.Entry.

Returns:Iterable<Map.Entry<String, LockMode>>

Iterable for accessing the Map.Entry's

getEffectiveLockModeback to summary
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 null as well, LockMode#NONE is returned.

Differs from getAliasSpecificLockMode in that here we fallback to we only return the overall lock mode.

Parameters
alias:String

The alias for which to locate the effective lock mode.

Returns:LockMode

The effective lock mode.

getFollowOnLockingback to summary
public Boolean getFollowOnLocking()

Retrieve the current follow-on-locking setting.

Returns:Boolean

true if follow-on-locking is enabled

getLockModeback to summary
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 granular per-alias fashion

Returns:LockMode

The overall lock mode.

getScopeback to summary
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:boolean

true if locking will be extended to owned associations

getTimeOutback to summary
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 or SKIP_LOCKED represent 3 "magic" values.

Returns:int

timeout in milliseconds, NO_WAIT, WAIT_FOREVER or SKIP_LOCKED

hasAliasSpecificLockModesback to summary
public boolean hasAliasSpecificLockModes()

Does this LockOptions object define alias-specific lock modes?

Returns:boolean

true if this LockOptions object define alias-specific lock modes; false otherwise.

interpretback to summary
public static LockOptions interpret(LockMode lockMode)
makeCopyback to summary
public LockOptions makeCopy()

Make a copy.

Returns:LockOptions

The copy

setAliasSpecificLockModeback to summary
public LockOptions setAliasSpecificLockMode(String alias, LockMode lockMode)

Specify the LockMode to be used for a specific query alias.

Parameters
alias:String

used to reference the LockMode.

lockMode:LockMode

The lock mode to apply to the given alias

Returns:LockOptions

this LockRequest instance for operation chaining.

See Also
Query#setLockMode(String, LockMode), Criteria#setLockMode(LockMode), Criteria#setLockMode(String, LockMode)
setFollowOnLockingback to summary
public LockOptions setFollowOnLocking(Boolean followOnLocking)

Set the the follow-on-locking setting.

Parameters
followOnLocking:Boolean

The new follow-on-locking setting

Returns:LockOptions

this (for method chaining).

setLockModeback to summary
public LockOptions setLockMode(LockMode lockMode)

Set the overall LockMode to be used. The default is LockMode#NONE

Parameters
lockMode:LockMode

The new overall lock mode to use.

Returns:LockOptions

this (for method chaining).

setScopeback to summary
public LockOptions setScope(boolean scope)

Set the scope.

Parameters
scope:boolean

The new scope setting

Returns:LockOptions

this (for method chaining).

setTimeOutback to summary
public LockOptions setTimeOut(int timeout)

Set the timeout setting.

See getTimeOut for a discussion of meaning.

Parameters
timeout:int

The new timeout setting, in milliseconds

Returns:LockOptions

this (for method chaining).

See Also
getTimeOut