From d1b2f70fb9d26288e5871655b5af2688371f9492 Mon Sep 17 00:00:00 2001 From: Gavin King Date: Sun, 12 May 2024 12:11:04 +0200 Subject: [PATCH] reorganize the javadoc for LockModeType there are no semantic changes here, but this is much more readable, I believe Signed-off-by: Gavin King --- .../jakarta/persistence/LockModeType.java | 241 +++++++++++------- 1 file changed, 146 insertions(+), 95 deletions(-) diff --git a/api/src/main/java/jakarta/persistence/LockModeType.java b/api/src/main/java/jakarta/persistence/LockModeType.java index bb58b6e8..f262408e 100644 --- a/api/src/main/java/jakarta/persistence/LockModeType.java +++ b/api/src/main/java/jakarta/persistence/LockModeType.java @@ -17,10 +17,10 @@ package jakarta.persistence; /** - * Enumerates the kinds of optimistic or pessimistic lock which - * may be obtained on an entity instance. + * Enumerates the kinds of optimistic or pessimistic lock which may + * be obtained on an entity instance. * - *

A specific lock mode may be requested by passing an explicit + *

A specific lock mode may be requested by passing an explicit * {@code LockModeType} as an argument to: *

+ *

Lock modes other than {@link #NONE} prevent dirty reads and + * non-repeatable reads of locked entity data within the current + * transaction. * - *

Optimistic locks are specified using - * {@link LockModeType#OPTIMISTIC LockModeType.OPTIMISTIC} and - * {@link LockModeType#OPTIMISTIC_FORCE_INCREMENT}. The lock mode - * types {@link LockModeType#READ} and {@link LockModeType#WRITE} are - * synonyms for {@code OPTIMISTIC} and {@code OPTIMISTIC_FORCE_INCREMENT} + *

An optimistic lock is requested by specifying the lock mode + * type {@link #OPTIMISTIC} or {@link #OPTIMISTIC_FORCE_INCREMENT}. + * The lock mode types {@link #READ} and {@link #WRITE} are synonyms + * for {@code OPTIMISTIC} and {@code OPTIMISTIC_FORCE_INCREMENT} * respectively. The latter are preferred for new applications. * - *

The semantics of requesting locks of type - * {@code LockModeType.OPTIMISTIC} and - * {@code LockModeType.OPTIMISTIC_FORCE_INCREMENT} are the - * following. + *

The persistence implementation is not required to accept + * requests for optimistic locks on non-versioned entities. When + * a provider does not support such a lock request, it must throw + * {@link PersistenceException}. * - *

If transaction T1 calls for a lock of type - * {@code LockModeType.OPTIMISTIC} on a versioned object, - * the entity manager must ensure that neither of the following - * phenomena can occur: + *

An immediate pessimistic database-level lock is requested by + * specifying one of the lock mode types {@link #PESSIMISTIC_READ}, + * {@link #PESSIMISTIC_WRITE}, or {@link #PESSIMISTIC_FORCE_INCREMENT}. *

- * - *

Lock modes must always prevent the phenomena P1 and P2. - * - *

In addition, obtaining a lock of type - * {@code LockModeType.OPTIMISTIC_FORCE_INCREMENT} on a versioned - * object, will also force an update (increment) to the entity's - * version column. - * - *

The persistence implementation is not required to support - * the use of optimistic lock modes on non-versioned objects. When - * it cannot support such a lock request, it must throw the {@link - * PersistenceException}. - * - *

The lock modes {@link LockModeType#PESSIMISTIC_READ}, - * {@link LockModeType#PESSIMISTIC_WRITE}, and - * {@link LockModeType#PESSIMISTIC_FORCE_INCREMENT} are used to - * immediately obtain long-term database locks. - * - *

The semantics of requesting locks of type - * {@code LockModeType.PESSIMISTIC_READ}, - * {@code LockModeType.PESSIMISTIC_WRITE}, and - * {@code LockModeType.PESSIMISTIC_FORCE_INCREMENT} are the - * following. - * - *

If transaction T1 calls for a lock of type - * {@code LockModeType.PESSIMISTIC_READ} or - * {@code LockModeType.PESSIMISTIC_WRITE} on an object, the entity - * manager must ensure that neither of the following phenomena can - * occur: - *

- * - *

A lock with {@code LockModeType.PESSIMISTIC_WRITE} can be - * obtained on an entity instance to force serialization among - * transactions attempting to update the entity data. A lock with - * {@code 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 - * {@code LockModeType.PESSIMISTIC_WRITE} can be used when querying - * data and there is a high likelihood of deadlock or update failure - * among concurrent updating transactions. * - *

The persistence implementation must support the use of locks - * of type {@code LockModeType.PESSIMISTIC_READ} and - * {@code LockModeType.PESSIMISTIC_WRITE} with non-versioned entities - * as well as with versioned entities. - * - *

When the lock cannot be obtained, and the database locking - * failure results in transaction-level rollback, the provider must - * throw the {@link PessimisticLockException} and ensure that the - * JTA transaction or {@code EntityTransaction} has been marked for - * rollback. - * - *

When the lock cannot be obtained, and the database locking - * failure results in only statement-level rollback, the provider - * must throw the {@link LockTimeoutException} (and must not mark - * the transaction for rollback). + *

The persistence implementation must accept requests for locks + * of type {@code PESSIMISTIC_READ} and {@code PESSIMISTIC_WRITE} on + * both versioned and non-versioned entities. + *

+ *

The persistence implementation is not required to accept + * requests for locks of type {@code PESSIMISTIC_FORCE_INCREMENT} on + * non-versioned entities. When a provider does not support such a + * lock request, it must throw {@link PersistenceException}. * * @since 1.0 * @@ -149,23 +102,85 @@ public enum LockModeType implements FindOption, RefreshOption { WRITE, /** - * Optimistic lock. + * An optimistic lock. + * + *

If transaction T1 calls for a lock of type + * {@code OPTIMISTIC} on a versioned object, the entity manager + * must ensure that neither of the following phenomena can occur: + *

+ * + *

The persistence implementation is not required to accept + * requests for {@code OPTIMISTIC} locks on non-versioned entities. * * @since 2.0 */ OPTIMISTIC, /** - * Optimistic lock, with version update. + * Optimistic lock, with version update, which prevents the + * following phenomena: + * + *

If transaction T1 calls for a lock of type + * {@code OPTIMISTIC_FORCE_INCREMENT} on a versioned object, + * the entity manager must ensure that neither of the following + * phenomena can occur: + *

+ * + *

In addition, obtaining a lock of type + * {@code OPTIMISTIC_FORCE_INCREMENT} on a versioned entity will + * also force an update (increment) to the {@linkplain Version + * version column}. + * + *

The persistence implementation is not required to accept + * requests for {@code OPTIMISTIC_FORCE_INCREMENT} locks on + * non-versioned entities. * * @since 2.0 */ OPTIMISTIC_FORCE_INCREMENT, /** - * * Pessimistic read lock. * + *

If transaction T1 calls for a lock of type + * {@code PESSIMISTIC_READ} on an object, the entity manager must + * ensure that neither of the following phenomena can occur: + *

+ * * @since 2.0 */ PESSIMISTIC_READ, @@ -173,6 +188,19 @@ public enum LockModeType implements FindOption, RefreshOption { /** * Pessimistic write lock. * + *

If transaction T1 calls for a lock of type + * {@code PESSIMISTIC_WRITE} on an object, the entity manager must + * ensure that neither of the following phenomena can occur: + *

+ * * @since 2.0 */ PESSIMISTIC_WRITE, @@ -180,6 +208,29 @@ public enum LockModeType implements FindOption, RefreshOption { /** * Pessimistic write lock, with version update. * + *

If transaction T1 calls for a lock of type + * {@code PESSIMISTIC_FORCE_INCREMENT} on an object, the entity + * manager must ensure that neither of the following phenomena + * can occur: + *

+ * + *

In addition, obtaining a lock of type + * {@code PESSIMISTIC_FORCE_INCREMENT} on a versioned entity will + * also force an update (increment) to the {@linkplain Version + * version column}. + * + *

The persistence implementation is not required to accept + * requests for {@code PESSIMISTIC_FORCE_INCREMENT} locks on + * non-versioned entities. + * * @since 2.0 */ PESSIMISTIC_FORCE_INCREMENT,