在 JPA 持久性单元中指定 TaskName
指定 Java™ Persistence API (JPA) 持久性单元中的 TaskName
关于此任务
TaskName 是使用持久性单元中的 wsjpa.AccessIntent 属性名称在 persistence.xml 文件中定义的。该属性值是由 TaskName、实体类型和访问意向定义组成的列表。以下示例显示持久性单元中 wsjpa.AccessIntent 属性名称的内容。
<property name = "wsjpa.AccessIntent"
value = "Tasks=' <taskName> { <entityName> ( <isolationLockValue> ) } ' "/>
A A A | | |
| | +--------- , --------+ | |
| +----------------- , -----------------+ |
+----------------------- , --------------------------+
Tasks ::= <task> [ ',' <task> ]*
<task> ::= <taskName> '{' <entity> [ ',' <entity> ]* '}'
<entity> ::= <entityName> '(' <isolationLockValues> ')'
<taskName> ::= <fully_qualified_identifier>
<entityName> ::= <fully_qualified_identifier>
<fully_qualified_identifier> ::= <identifier> [ '.' <identifier> ]*
<identifier> ::= <idStartCharacter> [ <idCharacter> ]*
<idStartCharacter> ::= Character.isJavaIdentifierStart | '?' | '*'
<idStartCharacter> ::= Character.isJavaIdentifierPart | '?' | '*'
<isolationLockValues> ::= <isolationLockValue> [ ',' <isolationLockValue> ]
<isolationLockValue> ::= <isolation> | <readLock>
<isolation> ::= "isolation" '=' <isolationValue>
<readLock> ::= "readlock" '=' <readlockValue>
<isolationValue> ::= "read-uncommitted"|"read-committed"|"repeatable-read"|"serializable"
<readlockValue> ::= "read" | "write"
在持久性单元中设置 TaskName 之前,请记住以下各项:- 标记之间的空格会被忽略。
- 仅 <isolation> 和 <readLock> 内容不区分大小写。
- <TaskName> 采用标准包方法名的格式(例如 com.acme.bean.MyBean.increment)或者用户定义的任意任务名称(例如 MyProfile)。
- <entityName> 采用标准包类名的格式(例如 com.acme.bean.Entity1)。
- 通配符“?”或“*”可用在 <TaskName> 和 <entityName> 中。"?" 匹配任何单一字符,而“*”匹配零个或更多序列字符。
- 仅 hintNames isolation 和 readLock 允许在任务定义中使用,并且顺序不重要。
- 如果 readLock 的值为 write,那么 isolation 必须为 repeatable-read 或 serializable。
- 如果 readLock 的值为 read,那么 isolation 为 read-uncommitted 时,它不起作用。
以下代码示例显示如何指定 JPA 持久性单元中的 TaskName。
package my.company;
@Remote
class Ejb1 {
// assumer no tx from the caller
@TransactionAttribute(Requires)
public void caller_Method1() {
// an implicit new transaction begins
// TaskName "my.company.Ejb1.caller_Method1" set on TSR
ejb1.callee_Method?();
}
@TransactionAttribute(RequiredNew)
public void callee_Method2() {
// an implicit new transaction begins i.e. TxRequiredNew.
// TaskName "my.company.Ejb1.callee_Method2" set on TSR
}
@TransactionAttribute(Requires)
public void callee_Method3() {
// In caller's transaction, hence TaskName remains
// "my.company.Ejb1.caller_Method1"
}
@TransactionAttribute(NotSupported)
public void callee_LocalTx () {
// Unspecified transaction, a new local transaction implicitly started.
// TaskName "my.company.Ejb1.callee_LocalTx" set on TSR
}
}
因为可以使用通配符来指定 TaskName 和实体类型,所以在运行时可能会出现多个规范匹配项。wsjpa.AccessIntent 属性中定义的顺序将用于搜索任务名称和实体类型。
<properties>
<property name="wsjpa.AccessIntent" value="Tasks="
*.Task1 { *.Employee1 ( isolation=read-uncommitted ),
*.Employee? ( isolation=repeatable-read, readlock=write ),
},
* { *.Employee3 ( isolation=serializable, readlock=write ) },
'" />
</properties>