JPAWriterPattern
JPAWriterPattern 模式用于将数据写入使用 Java™ Persistence API (JPA) 连接的数据库。
支持类
JPAWriter 类实现获取 EntityManager 类以及连接、开始和落实事务的基本 JPA 操作。缺省情况下,JPAWriter 会连接现有全局事务。
将 transaction-type 属性设置为 JTA 并声明 jta-data-source 元素的 persistence.xml 文件打包。可以选择配置 JPAWriter 类以开始和落实与全局事务同步的事务。这些事务用于 non-jta-data-source 元素和连接 URL。在此示例中,persistence.xml 文件将 transaction-type 设置为 RESOURCE_LOCAL,且声明非 jta-data-source 元素或连接 URL。
必需属性
以下属性对于该模式是必需的。
属性名称 | 值 |
---|---|
PATTERN_IMPL_CLASS | 实现 JPAWriterPattern 接口的类 |
PERSISTENT_UNIT | 提供程序持久性单元名称 |
对 EntityManager 类设置的 JPA 属性 | 这些属性的值 |
可选属性
以下属性对于该模式是可选的。
属性名称 | 值 | 描述 |
---|---|---|
debug | true 或 false(缺省值为 false。) | 在此批处理数据流上启用详细跟踪。 |
use_JTA_transactions | true 或 false(缺省值为 true。) | 如果使用非 non-jta-data-source 元素或连接 URL,那么将该值设置为 false。 |
EnablePerformanceMeasurement | true 或 false(缺省值为 false。) | 如果正使用 GenericXDBatchStep,那么计算批处理数据流和 processRecord 方法中所花的总时间。 |
接口定义
public interface JPAWriterPattern {
/**
* This method is invoked during create job step to allow the JPAWriter stream to
* initialize.
* @param props Properties passed via xJCL
*/
public void initialize(Properties props);
/**
* This method is invoked to actually persist the passed object to the database
* using JPA EntityManager
* @param manager
* @param record
*/
public void writeRecord(EntityManager manager, Object record);
}
xJCL 示例
<batch-data-streams>
<bds>
<logical-name>outputStream</logical-name>
<props>
<prop name="PATTERN_IMPL_CLASS" value="com.ibm.websphere.batch.samples.tests.bds.EchoWriter"/>
<prop name="PERSISTENT_UNIT" value="mypersistentU"/>
<prop name="debug" value="true"/>
</props>
<impl-class>com.ibm.websphere.batch.devframework.datastreams.patterns.JPAWriter</impl-class>
</bds>
</batch-data-streams>