LockModeType (Java EE 5)

Java EE API


javax.persistence Enum LockModeType

java.lang.Object
  extended by java.lang.Enum<LockModeType>
      extended by javax.persistence.LockModeType
All Implemented Interfaces:
Serializable, Comparable<LockModeType>

public enum LockModeType
extends Enum<LockModeType>

Extends: Enum<E>

可以通过 lock EntityManager.lock() 方法指定的锁定模式。

请求 LockModeType.READLockModeType.WRITE 类型的锁定的语义如下。

如果事务 T1 对版本化的对象调用 lock(entity, LockModeType.READ),则实体管理器必须确保不会发生以下任何一种情况:

  • P1(脏读):事务 T1 修改某行。然后另一个事务 T2 在 T1 提交或回滚之前阅读该行并获取已修改的值。事务 T2 最终成功提交;T1 是否提交或回滚,以及提交或回滚的时间是在 T2 提交之前或之后都无关紧要。
  • P2(不可重复读取):事务 T1 阅读某行。然后另一个事务 T2 在 T1 提交之前修改或删除了该行。两个事务最终都成功提交。

锁定模式必须总能防止出现情况 P1 和 P2。

此外,对版本化的对象调用 lock(entity, LockModeType.WRITE) 还将强制更新(增量)实体的版本列。

不要求持久性实现支持对非版本化的对象调用 lock EntityManager.lock()。当其不支持此类锁定调用时,必须抛出 PersistenceException

英文文档:

Lock modes that can be specified by means of the EntityManager.lock() method.

The semantics of requesting locks of type LockModeType.READ and LockModeType.WRITE are the following.

If transaction T1 calls lock(entity, LockModeType.READ) on a versioned object, the entity manager must ensure that neither of the following phenomena can occur:

  • P1 (Dirty read): Transaction T1 modifies a row. Another transaction T2 then reads that row and obtains the modified value, before T1 has committed or rolled back. Transaction T2 eventually commits successfully; it does not matter whether T1 commits or rolls back and whether it does so before or after T2 commits.
  • P2 (Non-repeatable read): Transaction T1 reads a row. Another transaction T2 then modifies or deletes that row, before T1 has committed. Both transactions eventually commit successfully.

Lock modes must always prevent the phenomena P1 and P2.

In addition, calling lock(entity, LockModeType.WRITE) on a versioned object, will also force an update (increment) to the entity's version column.

The persistence implementation is not required to support calling EntityManager.lock() on a non-versioned object. When it cannot support a such lock call, it must throw the PersistenceException.

Since:
Java Persistence 1.0

Enum Constant Summary
 
Method Summary
static LockModeType
static LockModeType[]
 
Methods inherited from class java.lang.Enum
 
Methods inherited from class java.lang.Object
 

Enum Constant Detail

英文文档:

READ

public static final LockModeType READ
Read lock


英文文档:

WRITE

public static final LockModeType WRITE
Write lock

Method Detail

final public static LockModeType[] values()
英文文档:

values

public static final LockModeType[] values()
Returns an array containing the constants of this enum type, in the order they're declared. This method may be used to iterate over the constants as follows:
for(LockModeType c : LockModeType.values())
        System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they're declared

public static LockModeType valueOf(String name)
英文文档:

valueOf

public static LockModeType valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified name


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!