Enum Class LockMode
- All Implemented Interfaces:
Serializable,Comparable<LockMode>,java.lang.constant.Constable
This enumeration of lock modes competes with the JPA-defined
LockModeType, but offers additional options, including
UPGRADE_NOWAIT and UPGRADE_SKIPLOCKED.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionNo lock required.A shared optimistic lock.A kind of exclusive optimistic lock.A pessimistic write lock which immediately increments the version of the locked object.A pessimistic shared lock, which prevents concurrent transactions from writing the locked object.A pessimistic upgrade lock, which prevents concurrent transactions from reading or writing the locked object.A shared lock.A pessimistic upgrade lock, obtained using an Oracle-styleselect for update nowait.A pessimistic upgrade lock, obtained using an Oracle-styleselect for update skip locked.An exclusive write lock. -
Method Summary
Modifier and TypeMethodDescriptionstatic LockModefromExternalForm(String externalForm) static LockModefromJpaLockMode(LockModeType lockMode) booleangreaterThan(LockMode mode) Check if this lock mode is more restrictive than the given lock mode.booleanCheck if this lock mode is less restrictive than the given lock mode.static LockModeTypetoJpaLockMode(LockMode lockMode) static LockModeReturns the enum constant of this class with the specified name.static LockMode[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
NONE
No lock required. If an object is requested with this lock mode, aREADlock will be obtained if it turns out to be necessary to actually read the state from the database, rather than pull it from a cache.This is the "default" lock mode, the mode requested by calling
Session.get(Class, Object)without passing an explicit mode. It permits the state of an object to be retrieved from the cache without the cost of database access.- See Also:
-
READ
A shared lock. Objects in this lock mode were read from the database in the current transaction, rather than being pulled from a cache.Note that this lock mode is the same as the JPA-defined modes
LockModeType.READandLockModeType.OPTIMISTIC.- See Also:
-
OPTIMISTIC
A shared optimistic lock. Assumes that the current transaction will not experience contention for the state of an entity. The version will be checked near the end of the transaction, to verify that this was indeed the case.Note that, despite the similar names this lock mode is not the same as the JPA-defined mode
LockModeType.OPTIMISTIC. -
OPTIMISTIC_FORCE_INCREMENT
A kind of exclusive optimistic lock. Assumes that the current transaction will not experience contention for the state of an entity. The version will be checked and incremented near the end of the transaction, to verify that this was indeed the case, and to signal to concurrent optimistic readers that their optimistic locks have failed.- See Also:
-
WRITE
An exclusive write lock. Objects in this lock mode were updated or inserted in the database in the current transaction.This lock mode is for internal use only and is not a legal argument to
Session.get(Class, Object, LockMode),Session.refresh(Object, LockMode), orSession.lock(Object, LockMode). These methods throw an exception ifWRITEis given as an argument.Note that, despite the similar names, this lock mode is not the same as the JPA-defined mode
LockModeType.WRITE. -
UPGRADE_NOWAIT
A pessimistic upgrade lock, obtained using an Oracle-styleselect for update nowait. The semantics of this lock mode, if the lock is successfully obtained, are the same asPESSIMISTIC_WRITE. If the lock is not immediately available, an exception occurs. -
UPGRADE_SKIPLOCKED
A pessimistic upgrade lock, obtained using an Oracle-styleselect for update skip locked. The semantics of this lock mode, if the lock is successfully obtained, are the same asPESSIMISTIC_WRITE. But if the lock is not immediately available, no exception occurs, but the locked row is not returned from the database. -
PESSIMISTIC_READ
A pessimistic shared lock, which prevents concurrent transactions from writing the locked object. Obtained via aselect for sharestatement in dialects where this syntax is supported, and viaselect for updatein other dialects.On databases which do not support
for share, this lock mode is equivalent toPESSIMISTIC_WRITE.- See Also:
-
PESSIMISTIC_WRITE
A pessimistic upgrade lock, which prevents concurrent transactions from reading or writing the locked object. Obtained via aselect for updatestatement.- See Also:
-
PESSIMISTIC_FORCE_INCREMENT
A pessimistic write lock which immediately increments the version of the locked object. Obtained by immediate execution of anupdatestatement.- See Also:
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
fromJpaLockMode
-
toJpaLockMode
-
toJpaLockMode
-
greaterThan
Check if this lock mode is more restrictive than the given lock mode.- Parameters:
mode- LockMode to check- Returns:
- true if this lock mode is more restrictive than given lock mode
-
lessThan
Check if this lock mode is less restrictive than the given lock mode.- Parameters:
mode- LockMode to check- Returns:
- true if this lock mode is less restrictive than given lock mode
-
toExternalForm
-
fromExternalForm
-
toLockOptions
- Returns:
- an instance of
LockOptionswith this lock mode, and all other settings defaulted.
-