Enum Class LockModeType
- All Implemented Interfaces:
Serializable
,Comparable<LockModeType>
,Constable
LockModeType
argument to one of the EntityManager
methods that take locks
(lock
, find
, or refresh
) or
to the Query.setLockMode()
or
TypedQuery.setLockMode()
method.
Lock modes can be used to specify either optimistic or pessimistic locks.
Optimistic locks are specified using LockModeType.OPTIMISTIC
and LockModeType.OPTIMISTIC_FORCE_INCREMENT
. The lock mode type
values LockModeType.READ
and
LockModeType.WRITE
are
synonyms of OPTIMISTIC
and
OPTIMISTIC_FORCE_INCREMENT
respectively. The latter
are to be preferred for new applications.
The semantics of requesting locks of type
If transaction T1 calls for a lock of type
Lock modes must always prevent the phenomena P1 and P2.
In addition, calling a lock of type
The persistence implementation is not required to support
the use of optimistic lock modes on non-versioned objects. When it
cannot support a such lock call, it must throw the The lock modes The semantics of requesting locks of type
If transaction T1 calls for a lock of type
A lock with The persistence implementation must support use of locks of type
When the lock cannot be obtained, and the database locking
failure results in transaction-level rollback, the provider must
throw the When the lock cannot be obtained, and the database locking
failure results in only statement-level rollback, the provider must
throw the LockModeType.OPTIMISTIC
and
LockModeType.OPTIMISTIC_FORCE_INCREMENT
are the
following.
LockModeType.OPTIMISTIC
on a versioned object,
the entity manager must ensure that neither of the following
phenomena can occur:
LockModeType.OPTIMISTIC_FORCE_INCREMENT
on a versioned object,
will also force an update (increment) to the entity's version
column.
PersistenceException
.
LockModeType.PESSIMISTIC_READ
, LockModeType.PESSIMISTIC_WRITE
, and
LockModeType.PESSIMISTIC_FORCE_INCREMENT
are used to immediately
obtain long-term database locks.
LockModeType.PESSIMISTIC_READ
, LockModeType.PESSIMISTIC_WRITE
, and
LockModeType.PESSIMISTIC_FORCE_INCREMENT
are the following.
LockModeType.PESSIMISTIC_READ
or
LockModeType.PESSIMISTIC_WRITE
on an object, the entity
manager must ensure that neither of the following phenomena can
occur:
LockModeType.PESSIMISTIC_WRITE
can be obtained on
an entity instance to force serialization among transactions
attempting to update the entity data. A lock with
LockModeType.PESSIMISTIC_READ
can be used to query data using
repeatable-read semantics without the need to reread the data at
the end of the transaction to obtain a lock, and without blocking
other transactions reading the data. A lock with
LockModeType.PESSIMISTIC_WRITE
can be used when querying data and
there is a high likelihood of deadlock or update failure among
concurrent updating transactions.
LockModeType.PESSIMISTIC_READ
LockModeType.PESSIMISTIC_WRITE
on a non-versioned entity as well as
on a versioned entity.
PessimisticLockException
and ensure that the JTA
transaction or EntityTransaction
has been marked for rollback.
LockTimeoutException
(and must not mark the transaction
for rollback).
- Since:
- Java Persistence 1.0
-
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.Optimistic lock.Optimistic lock, with version update.Pessimistic write lock, with version update.Pessimistic read lock.Pessimistic write lock.Synonymous withOPTIMISTIC
.Synonymous withOPTIMISTIC_FORCE_INCREMENT
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic LockModeType
Returns the enum constant of this class with the specified name.static LockModeType[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
READ
Synonymous withOPTIMISTIC
.OPTIMISTIC
is to be preferred for new applications. -
WRITE
Synonymous withOPTIMISTIC_FORCE_INCREMENT
.OPTIMISTIC_FORCE_IMCREMENT
is to be preferred for new applications. -
OPTIMISTIC
Optimistic lock.- Since:
- Java Persistence 2.0
-
OPTIMISTIC_FORCE_INCREMENT
Optimistic lock, with version update.- Since:
- Java Persistence 2.0
-
PESSIMISTIC_READ
Pessimistic read lock.- Since:
- Java Persistence 2.0
-
PESSIMISTIC_WRITE
Pessimistic write lock.- Since:
- Java Persistence 2.0
-
PESSIMISTIC_FORCE_INCREMENT
Pessimistic write lock, with version update.- Since:
- Java Persistence 2.0
-
NONE
No lock.- Since:
- Java Persistence 2.0
-
-
Constructor Details
-
LockModeType
private LockModeType()
-
-
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
-